1. Program crash with regex wrapper after translation
Hello,
I've been using Karl Bochert's wrappers (regex.zip in the archive) for
the PCRE regular expression library, which work great under the
interpreter, but when translated to C causes a crash whenever the
regex_free function is called (which frees up memory when you are done
with a compiled pattern).
Any way to fix this, or is this function maybe not neccessary when
translating to C? (I don't want to cause a memory leak)
Andy Serpa
renegade at earthling.net
2. Re: Program crash with regex wrapper after translation
Andy Serpa writes:
> I've been using Karl Bochert's wrappers (regex.zip in the archive) for
> the PCRE regular expression library, which work great under the
> interpreter, but when translated to C causes a crash whenever the
> regex_free function is called (which frees up memory when you are done
> with a compiled pattern).
Check the argument that's passed to regex_free().
It's possible that it's wrong when you use the interpreter,
but it just doesn't cause a crash. If it looks ok,
then please send me a small program that works
with the 2.3 alpha interpreter, but not with the 2.3 alpha translator.
If you are still using the 2.2 translator, please install 2.3 alpha,
interpreter and translator.
Regards,
Rob Craig
Rapid Deployment Software
http://www.RapidEuphoria.com
3. Re: Program crash with regex wrapper after translation
Andy Serpa writes:
> So ANY call in ANY program to regex_find without regex_compile in your
> own code (or with it, but then you have to call regex_free yourself)
> will cause the crash. I should have mentioned I'm using all the latest
> versions of the interpreter & translator (unregistered) and am on a
> WinME system. I tried compiling with both Borland & lccWin, same
> result.
I duplicated the problem on my system using the
Translator with Borland or Lcc, but with Watcom it
runs fine. It also runs fine with exw (built by Watcom) as you noted.
I believe what's happening is that pcre.dll
contains C functions that were compiled using the
_cdecl calling convention, rather than the _stdcall
convention that Euphoria expects.
In most cases, when using Watcom (Translator or interpreter),
you can call _cdecl C routines and it will work. With Borland
and Lcc the call stack gets screwed up and
a crash is likely to occur.
Maybe in a future release (2.4?) I will experiment with
either detecting automatically, or having the user
tell me when a C routine is compiled as _cdecl.
Summary:
_stdcall:
all WIN32 API routines
fixed number of arguments only
callee resets the stack pointer
_ cdecl:
more common these days
allows for variable number of arguments
caller must reset the stack pointer
values are passed/returned the same way,
except for structures and doubles
Regards,
Rob Craig
Rapid Deployment Software
http://www.RapidEuphoria.com
4. Re: Program crash with regex wrapper after translation
-------Phoenix-Boundary-07081998-
Hi Robert Craig, you wrote on 1/4/02 7:47:11 PM:
>>Andy Serpa writes:
>> So ANY call in ANY program to regex_find without regex_compile in your
>> own code (or with it, but then you have to call regex_free yourself)
>> will cause the crash. I should have mentioned I'm using all the latest
>> versions of the interpreter & translator (unregistered) and am on a
>> WinME system. I tried compiling with both Borland & lccWin, same
>> result.
>I duplicated the problem on my system using the
>Translator with Borland or Lcc, but with Watcom it
>runs fine. It also runs fine with exw (built by Watcom) as you noted.
>
>I believe what's happening is that pcre.dll
>contains C functions that were compiled using the
>_cdecl calling convention, rather than the _stdcall
>convention that Euphoria expects.
>
>In most cases, when using Watcom (Translator or interpreter),
>you can call _cdecl C routines and it will work. With Borland
>and Lcc the call stack gets screwed up and
>a crash is likely to occur.
>
>Maybe in a future release (2.4?) I will experiment with
>either detecting automatically, or having the user
>tell me when a C routine is compiled as _cdecl.
>
>Summary:
>
>_stdcall:
> all WIN32 API routines
> fixed number of arguments only
> callee resets the stack pointer
>
>_ cdecl:
> more common these days
> allows for variable number of arguments
> caller must reset the stack pointer
>
>values are passed/returned the same way,
>except for structures and doubles
>
>Regards,
> Rob Craig
I compiled the pcre.dll from the publicly available C sources using
the LCC compiler. The sources do not have 'cdecl" in them. I have
attached the makefile I used which also doesn't mention cdecl. (and
is nearly as unintelligible as the makefile distributed with PCRE).
Perhaps the dll should be compiled with Watcom? That would at least
speed it up considerably.
-------Phoenix-Boundary-07081998-
Content-type: application/octet-stream; Name=makefile
5. Re: Program crash with regex wrapper after translation
Karl Bochert writes:
> I compiled the pcre.dll from the publicly available C sources using
> the LCC compiler. The sources do not have 'cdecl" in them.
I believe _cdecl is the default with Lcc and most other compilers.
> Perhaps the dll should be compiled with Watcom? That would at least
> speed it up considerably.
The important thing is to declare all the C routines as __stdcall.
Be aware that the exported names might change as a result.
Regards,
Rob Craig
Rapid Deployment Software
http://www.RapidEuphoria.com