Thread overview | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 28, 2011 Some weird crashes | ||||
---|---|---|---|---|
| ||||
I'm trying to wrap the newest mysql c connector, but I get some weird bugs. I don't know any assembly, so I don't even know if I've included enough info.. I hope this is a small enough test case so someone can understand the issue. I've used implib on the included dll and rdmd and dmd 2.051 to compile. // CORRECT auto res = mysql_library_init(0, null, null); auto cn = mysql_init(null); auto oldcn = cn; writeln(mysql_errno(cn)); assert(cn == oldcn); auto err = mysql_errno(cn); //assert(cn == oldcn); // notice this is commented out mysql_close(cn); mysql_library_end(); 0040201A |. E8 F5B30300 CALL <JMP.&libmysql.mysql_server_init> 0040201F |. 6A 00 PUSH 0 00402021 |. E8 E8B30300 CALL <JMP.&libmysql.mysql_init> 00402026 |. 8945 F8 MOV DWORD PTR SS:[EBP-8],EAX 00402029 |. 8945 FC MOV DWORD PTR SS:[EBP-4],EAX 0040202C |. FF75 F8 PUSH DWORD PTR SS:[EBP-8] 0040202F |. E8 D4B30300 CALL <JMP.&libmysql.mysql_errno> 00402034 |. 83C4 04 ADD ESP,4 00402037 |. E8 4C000000 CALL mytest_w.00402088 0040203C |. 8B45 F8 MOV EAX,DWORD PTR SS:[EBP-8] 0040203F |. 3B45 FC CMP EAX,DWORD PTR SS:[EBP-4] 00402042 |. B9 01000000 MOV ECX,1 00402047 |. 74 02 JE SHORT mytest_w.0040204B 00402049 |. 8ACD MOV CL,CH 0040204B |> 894D F4 MOV DWORD PTR SS:[EBP-C],ECX 0040204E |. 74 0A JE SHORT mytest_w.0040205A 00402050 |. B8 1A000000 MOV EAX,1A 00402055 |. E8 662A0000 CALL mytest_w.00404AC0 0040205A |> FF75 F8 PUSH DWORD PTR SS:[EBP-8] 0040205D |. E8 A6B30300 CALL <JMP.&libmysql.mysql_errno> 00402062 |. 807D F4 00 CMP BYTE PTR SS:[EBP-C],0 00402066 |. 75 0A JNZ SHORT mytest_w.00402072 00402068 |. B8 1D000000 MOV EAX,1D 0040206D |. E8 4E2A0000 CALL mytest_w.00404AC0 00402072 |> FF75 F8 PUSH DWORD PTR SS:[EBP-8] 00402075 |. E8 88B30300 CALL <JMP.&libmysql.mysql_close> 0040207A |. E8 7DB30300 CALL <JMP.&libmysql.mysql_server_end> 0040207F |. 31C0 XOR EAX,EAX 00402081 |. 83C4 18 ADD ESP,18 00402084 |. C9 LEAVE 00402085 \. C3 RETN // ERROR auto res = mysql_library_init(0, null, null); auto cn = mysql_init(null); auto oldcn = cn; writeln(mysql_errno(cn)); assert(cn == oldcn); // when the last assert is active, the above line changes cn and thus fails. auto err = mysql_errno(cn); assert(cn == oldcn); mysql_close(cn); mysql_library_end(); 0040201A |. E8 D5B30300 CALL <JMP.&libmysql.mysql_server_init> 0040201F |. 6A 00 PUSH 0 00402021 |. E8 C8B30300 CALL <JMP.&libmysql.mysql_init> 00402026 |. 8945 F8 MOV DWORD PTR SS:[EBP-8],EAX 00402029 |. 8945 FC MOV DWORD PTR SS:[EBP-4],EAX 0040202C |. FF75 F8 PUSH DWORD PTR SS:[EBP-8] 0040202F |. E8 B4B30300 CALL <JMP.&libmysql.mysql_errno> 00402034 |. 83C4 04 ADD ESP,4 00402037 |. E8 30000000 CALL mytest_f.0040206C 0040203C |. 8B45 F8 MOV EAX,DWORD PTR SS:[EBP-8] 0040203F |. 3B45 FC CMP EAX,DWORD PTR SS:[EBP-4] 00402042 |. 74 0A JE SHORT mytest_f.0040204E 00402044 |. B8 1A000000 MOV EAX,1A 00402049 |. E8 562A0000 CALL mytest_f.00404AA4 0040204E |> FF75 F8 PUSH DWORD PTR SS:[EBP-8] 00402051 |. E8 92B30300 CALL <JMP.&libmysql.mysql_errno> 00402056 |. FF75 F8 PUSH DWORD PTR SS:[EBP-8] 00402059 |. E8 84B30300 CALL <JMP.&libmysql.mysql_close> 0040205E |. E8 79B30300 CALL <JMP.&libmysql.mysql_server_end> 00402063 |. 31C0 XOR EAX,EAX 00402065 |. 83C4 18 ADD ESP,18 00402068 |. C9 LEAVE 00402069 \. C3 RETN |
February 28, 2011 Re: Some weird crashes | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | On 28.02.2011 18:52, simendsjo wrote:
>
> // ERROR
> auto res = mysql_library_init(0, null, null);
>
> auto cn = mysql_init(null);
> auto oldcn = cn;
>
> writeln(mysql_errno(cn));
> assert(cn == oldcn); // when the last assert is active, the above line
> changes cn and thus fails.
>
> auto err = mysql_errno(cn);
> assert(cn == oldcn);
Btw, if I don't use writeln it doesn't fail..
|
February 28, 2011 Re: Some weird crashes | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo <simen.endsjo@pandavre.com> wrote:
> On 28.02.2011 18:52, simendsjo wrote:
>>
>> // ERROR
>> auto res = mysql_library_init(0, null, null);
>>
>> auto cn = mysql_init(null);
>> auto oldcn = cn;
>>
>> writeln(mysql_errno(cn));
>> assert(cn == oldcn); // when the last assert is active, the above line
>> changes cn and thus fails.
>>
>> auto err = mysql_errno(cn);
>> assert(cn == oldcn);
>
> Btw, if I don't use writeln it doesn't fail..
I think you have a bug at line 42.
On a serious note, it might have helped if you'd attached source code, or at least binaries.
|
February 28, 2011 Re: Some weird crashes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | On 28.02.2011 20:24, Denis Koroskin wrote: > I think you have a bug at line 42. > > On a serious note, it might have helped if you'd attached source code, > or at least binaries. The file was too large to be attached. Here's a link to a public hosting service: http://share1t.com/4xgt2l. Everything (including mysql libraries) is included. Not sure what line you are referring to though. |
February 28, 2011 Re: Some weird crashes | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | simendsjo: > Not sure what line you are referring to though. http://en.wikipedia.org/wiki/Answer_to_Life,_the_Universe,_and_Everything#The_number_42 Bye, bearophile |
March 01, 2011 Re: Some weird crashes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | On 28.02.2011 20:24, Denis Koroskin wrote: > On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo > <simen.endsjo@pandavre.com> wrote: > >> On 28.02.2011 18:52, simendsjo wrote: >>> >>> // ERROR >>> auto res = mysql_library_init(0, null, null); >>> >>> auto cn = mysql_init(null); >>> auto oldcn = cn; >>> >>> writeln(mysql_errno(cn)); >>> assert(cn == oldcn); // when the last assert is active, the above line >>> changes cn and thus fails. >>> >>> auto err = mysql_errno(cn); >>> assert(cn == oldcn); >> >> Btw, if I don't use writeln it doesn't fail.. > > I think you have a bug at line 42. > > On a serious note, it might have helped if you'd attached source code, > or at least binaries. Hmmm.. Seems my post last night didn't get through.. Here's the code and necessary libraries: http://share1t.com/4xgt2l |
March 02, 2011 Re: Some weird crashes | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | On Tue, 01 Mar 2011 23:01:21 +0300, simendsjo <simen.endsjo@pandavre.com> wrote: > On 28.02.2011 20:24, Denis Koroskin wrote: >> On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo >> <simen.endsjo@pandavre.com> wrote: >> >>> On 28.02.2011 18:52, simendsjo wrote: >>>> >>>> // ERROR >>>> auto res = mysql_library_init(0, null, null); >>>> >>>> auto cn = mysql_init(null); >>>> auto oldcn = cn; >>>> >>>> writeln(mysql_errno(cn)); >>>> assert(cn == oldcn); // when the last assert is active, the above line >>>> changes cn and thus fails. >>>> >>>> auto err = mysql_errno(cn); >>>> assert(cn == oldcn); >>> >>> Btw, if I don't use writeln it doesn't fail.. >> >> I think you have a bug at line 42. >> >> On a serious note, it might have helped if you'd attached source code, >> or at least binaries. > > Hmmm.. Seems my post last night didn't get through.. > Here's the code and necessary libraries: http://share1t.com/4xgt2l What appears to be an error here is in fact an Access Violation at mysql_close. Here is a reduced test-case: import mysql; void main() { auto res = mysql_library_init(0, null, null); auto cn = mysql_init(null); mysql_close(cn); } Then I decided to check whether it is D's fault or not by porting this short program to C. Here is what I got: // mysql.c int mysql_server_init(int argc, char **argv, char **groups); struct MYSQL* mysql_init(struct MYSQL*); void mysql_close(struct MYSQL*); #define mysql_library_init mysql_server_init #define NULL 0 #include <stdio.h> int main() { int res = mysql_library_init(0, NULL, NULL); struct MYSQL* cn = mysql_init(NULL); printf("here"); mysql_close(cn); return 0; } This program works fine, BUT try commenting out the "printf" call and it crashes, too. That said, it is unlikely to be DMD fault here. Are you sure those prototypes and/or .lib/.dll files are fine? |
March 02, 2011 Re: Some weird crashes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | On 02.03.2011 18:24, Denis Koroskin wrote:
> On Tue, 01 Mar 2011 23:01:21 +0300, simendsjo
> <simen.endsjo@pandavre.com> wrote:
>
>> On 28.02.2011 20:24, Denis Koroskin wrote:
>>> On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo
>>> <simen.endsjo@pandavre.com> wrote:
>>>
>>>> On 28.02.2011 18:52, simendsjo wrote:
>>>>>
>>>>> // ERROR
>>>>> auto res = mysql_library_init(0, null, null);
>>>>>
>>>>> auto cn = mysql_init(null);
>>>>> auto oldcn = cn;
>>>>>
>>>>> writeln(mysql_errno(cn));
>>>>> assert(cn == oldcn); // when the last assert is active, the above line
>>>>> changes cn and thus fails.
>>>>>
>>>>> auto err = mysql_errno(cn);
>>>>> assert(cn == oldcn);
>>>>
>>>> Btw, if I don't use writeln it doesn't fail..
>>>
>>> I think you have a bug at line 42.
>>>
>>> On a serious note, it might have helped if you'd attached source code,
>>> or at least binaries.
>>
>> Hmmm.. Seems my post last night didn't get through..
>> Here's the code and necessary libraries: http://share1t.com/4xgt2l
>
> What appears to be an error here is in fact an Access Violation at
> mysql_close.
>
> Here is a reduced test-case:
>
> import mysql;
>
> void main()
> {
> auto res = mysql_library_init(0, null, null);
> auto cn = mysql_init(null);
> mysql_close(cn);
> }
>
>
> Then I decided to check whether it is D's fault or not by porting this
> short program to C. Here is what I got:
>
> // mysql.c
> int mysql_server_init(int argc, char **argv, char **groups);
> struct MYSQL* mysql_init(struct MYSQL*);
> void mysql_close(struct MYSQL*);
>
> #define mysql_library_init mysql_server_init
>
> #define NULL 0
>
> #include <stdio.h>
>
> int main()
> {
> int res = mysql_library_init(0, NULL, NULL);
> struct MYSQL* cn = mysql_init(NULL);
> printf("here");
> mysql_close(cn);
> return 0;
> }
>
> This program works fine, BUT try commenting out the "printf" call and it
> crashes, too. That said, it is unlikely to be DMD fault here. Are you
> sure those prototypes and/or .lib/.dll files are fine?
The prototypes might be wrong. I'm in the process of checking everything.
The dll is the one included in the download. The lib is made with implib /system
But your c program fails..? Could the problem be with the implib library..?
I couldn't find a free download for coff2omf, that's why I don't use the supplied .lib.
|
March 02, 2011 Re: Some weird crashes | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | On 3/2/11 10:52 AM, simendsjo wrote: > I couldn't find a free download for coff2omf, that's why I don't use the > supplied .lib. You can use coffimplib: ftp://ftp.digitalmars.com/coffimplib.zip |
March 03, 2011 Re: Some weird crashes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bekenn | Thanks! I couldn't find it on the web page. coffimplib is missing to option to prepend _ to the types as implib does with /system. Any way around this (without changing all my code)? |
Copyright © 1999-2021 by the D Language Foundation