Repeated calls to DLL function causes stack overflow using Borland Builder6

Anton Vrba anton at a-l-v.net
Sun Nov 13 08:00:04 CET 2005


Hi,
 
I have succesfully compiled gmp-4.1.4 on Windows 2000 MinGw MSYS system.
 
./configure --enable-shared --disable-static
 
I then imported the DLL library to Borland C Builder6 by following following steps
 
1. renamed libgmp-3.dll to gmp.dll  (Borland hates "-" in file names) and copied to my project directory.
2. under Command Prompt
2.a  > impdef gmp.def gmp.dll
2.b  > implib gmp.lib gmp.def
3. needless to say gmp.h also needs to be copied to a place that Cbuilder6 can find it.
 
In Borland C Builder6 added gmp.lib to Project .
 
Using C Builder6 I set following options  Menu [project][options]
Compiler Tab 
  - Code optimization  - speed
Advanced Compiler Tab 
  - Instruction Set - Pentium
  - Calling conventions - Standard
 
The program compiles and links properly but  if gmp calls are in a loop then a stack overflow is reported after 83000 loops of below code.
 
while (1)
 {
     mpz_mul_ui(n,n,1227750359) ;
      mpz_div_ui(n,n,1227750359) ;
 
      count++ ;
      if ((count % 1000) ==1)   {
         cout << "count = "<<count  <<"\n"  ;
         }
      }
 
Adding following code resets the stack and program can loop indefinately, a non elageant brute force method to work around the problem.
 
 test = 1   ;
 while (test)
 {
    test = setjmp( envbuf );
 }
 while (1)
 {
     mpz_mul_ui(n,n,1227750359L);
      mpz_div_ui(n,n,1227750359L);
 
      count++ ;
      if ((count % 1000) ==1)   {
         cout << "count = "<<count  <<"\n"  ;
         longjmp( envbuf, -1 );
         }
      }

The same program compiled under MinGW MSYS and using gcc and the static libraries (a seperate gmp build) does not have the same problems.
 
My question:
 
Is there a Borland calling incompatibility to the DLL libary or a DLL bug that the stack grows.
 
best regards
Anton
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gmplib.org/list-archives/gmp-discuss/attachments/20051113/fdba4223/attachment.html


More information about the gmp-discuss mailing list