Re: Some weird crashes

2011-03-08 Thread Bekenn

On 3/8/2011 12:57 PM, simendsjo wrote:


One more thing..
Function pointers in structs.. Should they use extern(Windows) too?


Yes.


Re: Some weird crashes

2011-03-08 Thread simendsjo

On 08.03.2011 01:32, Andrej Mitrovic wrote:

Sorry for not seeing this sooner. I think you might have set the wrong
calling convention in the translated header file. See my answer on SO.
I hope it works for you now.


Thanks. Just to get the solution here too:

* Use the vs2005 library (to get COFF?)
* coffimplib
* wrap __stdcall in extern(Windows)

One more thing..
Function pointers in structs.. Should they use extern(Windows) too?


Re: Some weird crashes

2011-03-07 Thread Andrej Mitrovic
Sorry for not seeing this sooner. I think you might have set the wrong
calling convention in the translated header file. See my answer on SO.
I hope it works for you now.


Re: Some weird crashes

2011-03-05 Thread simendsjo

On 28.02.2011 18:52, simendsjo wrote:

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.



Asked on SO too: 
http://stackoverflow.com/questions/5204460/problems-convering-a-c-header-to-d


Re: Some weird crashes

2011-03-03 Thread simendsjo

On 02.03.2011 18:24, Denis Koroskin wrote:

On Tue, 01 Mar 2011 23:01:21 +0300, simendsjo
 wrote:


On 28.02.2011 20:24, Denis Koroskin wrote:

On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo
 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 

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?


I've gone through the entire file and fixed ever wrong definition I 
found. I added the C declarations as a comment before each type.

The same error exists, and I cannot understand why...

The code is pasted here: http://pastebin.com/KwacZ0MY

Does anyone have a clue where to start looking?



Re: Some weird crashes

2011-03-03 Thread simendsjo
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)?


Re: Some weird crashes

2011-03-02 Thread Bekenn

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


Re: Some weird crashes

2011-03-02 Thread simendsjo

On 02.03.2011 18:24, Denis Koroskin wrote:

On Tue, 01 Mar 2011 23:01:21 +0300, simendsjo
 wrote:


On 28.02.2011 20:24, Denis Koroskin wrote:

On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo
 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 

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.


Re: Some weird crashes

2011-03-02 Thread Denis Koroskin
On Tue, 01 Mar 2011 23:01:21 +0300, simendsjo   
wrote:



On 28.02.2011 20:24, Denis Koroskin wrote:

On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo
 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 

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?


Re: Some weird crashes

2011-03-01 Thread simendsjo

On 28.02.2011 20:24, Denis Koroskin wrote:

On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo
 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


Re: Some weird crashes

2011-02-28 Thread bearophile
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


Re: Some weird crashes

2011-02-28 Thread simendsjo

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.


Re: Some weird crashes

2011-02-28 Thread Denis Koroskin
On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo   
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.


Re: Some weird crashes

2011-02-28 Thread 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..


Some weird crashes

2011-02-28 Thread simendsjo
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 F5B30300CALL 
0040201F  |. 6A 00  PUSH 0
00402021  |. E8 E8B30300CALL 
00402026  |. 8945 F8MOV DWORD PTR SS:[EBP-8],EAX
00402029  |. 8945 FCMOV DWORD PTR SS:[EBP-4],EAX
0040202C  |. FF75 F8PUSH DWORD PTR SS:[EBP-8]
0040202F  |. E8 D4B30300CALL 
00402034  |. 83C4 04ADD ESP,4
00402037  |. E8 4C00CALL mytest_w.00402088
0040203C  |. 8B45 F8MOV EAX,DWORD PTR SS:[EBP-8]
0040203F  |. 3B45 FCCMP EAX,DWORD PTR SS:[EBP-4]
00402042  |. B9 0100MOV ECX,1
00402047  |. 74 02  JE SHORT mytest_w.0040204B
00402049  |. 8ACD   MOV CL,CH
0040204B  |> 894D F4MOV DWORD PTR SS:[EBP-C],ECX
0040204E  |. 74 0A  JE SHORT mytest_w.0040205A
00402050  |. B8 1A00MOV EAX,1A
00402055  |. E8 662ACALL mytest_w.00404AC0
0040205A  |> FF75 F8PUSH DWORD PTR SS:[EBP-8]
0040205D  |. E8 A6B30300CALL 
00402062  |. 807D F4 00 CMP BYTE PTR SS:[EBP-C],0
00402066  |. 75 0A  JNZ SHORT mytest_w.00402072
00402068  |. B8 1D00MOV EAX,1D
0040206D  |. E8 4E2ACALL mytest_w.00404AC0
00402072  |> FF75 F8PUSH DWORD PTR SS:[EBP-8]
00402075  |. E8 88B30300CALL 
0040207A  |. E8 7DB30300CALL 
0040207F  |. 31C0   XOR EAX,EAX
00402081  |. 83C4 18ADD 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 D5B30300CALL 
0040201F  |. 6A 00  PUSH 0
00402021  |. E8 C8B30300CALL 
00402026  |. 8945 F8MOV DWORD PTR SS:[EBP-8],EAX
00402029  |. 8945 FCMOV DWORD PTR SS:[EBP-4],EAX
0040202C  |. FF75 F8PUSH DWORD PTR SS:[EBP-8]
0040202F  |. E8 B4B30300CALL 
00402034  |. 83C4 04ADD ESP,4
00402037  |. E8 3000CALL mytest_f.0040206C
0040203C  |. 8B45 F8MOV EAX,DWORD PTR SS:[EBP-8]
0040203F  |. 3B45 FCCMP EAX,DWORD PTR SS:[EBP-4]
00402042  |. 74 0A  JE SHORT mytest_f.0040204E
00402044  |. B8 1A00MOV EAX,1A
00402049  |. E8 562ACALL mytest_f.00404AA4
0040204E  |> FF75 F8PUSH DWORD PTR SS:[EBP-8]
00402051  |. E8 92B30300CALL 
00402056  |. FF75 F8PUSH DWORD PTR SS:[EBP-8]
00402059  |. E8 84B30300CALL 
0040205E  |. E8 79B30300CALL 
00402063  |. 31C0   XOR EAX,EAX
00402065  |. 83C4 18ADD ESP,18
00402068  |. C9 LEAVE
00402069  \. C3 RETN