Hi Folks,
I attached some test code to this mail that reproduces a bug in GPC that just occurred in one of my projects. In short: When I link a Pascal unit to a C project, and a function in the Pascal unit calls RuntimeError, this results in a segfault when called from within the C code. (I'm using gpc-20050331 together with gcc-3.4.3.)
Pure Pascal projects are not affected, there the RuntimeError just works fine.
Yours,
Markus
Markus Gerwinski wrote:
I attached some test code to this mail that reproduces a bug in GPC that just occurred in one of my projects. In short: When I link a Pascal unit to a C project, and a function in the Pascal unit calls RuntimeError, this results in a segfault when called from within the C code. (I'm using gpc-20050331 together with gcc-3.4.3.)
I think the problem is that the Pascal runtime is not initialized (see the thread "Default linker names").
Pure Pascal projects are not affected, there the RuntimeError just works fine.
Regards,
Adriaan van Os
Adriaan van Os wrote:
Markus Gerwinski wrote:
I attached some test code to this mail that reproduces a bug in GPC that just occurred in one of my projects. In short: When I link a Pascal unit to a C project, and a function in the Pascal unit calls RuntimeError, this results in a segfault when called from within the C code. (I'm using gpc-20050331 together with gcc-3.4.3.)
I think the problem is that the Pascal runtime is not initialized (see the thread "Default linker names").
Yes, seems so.
Please look at gpc-in-c.h, as there may be more things you'll have to do. (You can ignore the part about `--gpc-main' if you only have units on the Pascal side.)
Pure Pascal projects are not affected, there the RuntimeError just works fine.
More precisely, if the main program is in Pascal, things are initialized/finalized automatically. So unless the C part insists on providing main(), you might consider this alternative. (You can then, of course, call a big C function which does most of the work from the Pascal main program, and the C functions can then call back to Pascal anytime.)
Frank
Frank Heckenbach wrote:
Please look at gpc-in-c.h, as there may be more things you'll have to do. (You can ignore the part about `--gpc-main' if you only have units on the Pascal side.)
Okay, thanks. Calling _p_initialize solves the problem, of course. However, since it wasn't necessary in an earlier version, I wonder what has changed since?
Pure Pascal projects are not affected, there the RuntimeError just works fine.
More precisely, if the main program is in Pascal, things are initialized/finalized automatically. So unless the C part insists on providing main(), you might consider this alternative. (You can then, of course, call a big C function which does most of the work from the Pascal main program, and the C functions can then call back to Pascal anytime.)
Problem is, what I'm writing here is a library, so most probably there will be some users who insist on running it from a C main(). However, I could just provide all of my C demo programs with init()- and fini()-calls at the beginning and the end; that should be clear enough.
Markus Gerwinski wrote:
Frank Heckenbach wrote:
Please look at gpc-in-c.h, as there may be more things you'll have to do. (You can ignore the part about `--gpc-main' if you only have units on the Pascal side.)
Okay, thanks. Calling _p_initialize solves the problem, of course. However, since it wasn't necessary in an earlier version, I wonder what has changed since?
When was it not necessary? gpc-in-c.h has existed for quite some time. If this particular case didn't crash before didn't mean that initialization wasn't necessary.
Pure Pascal projects are not affected, there the RuntimeError just works fine.
More precisely, if the main program is in Pascal, things are initialized/finalized automatically. So unless the C part insists on providing main(), you might consider this alternative. (You can then, of course, call a big C function which does most of the work from the Pascal main program, and the C functions can then call back to Pascal anytime.)
Problem is, what I'm writing here is a library, so most probably there will be some users who insist on running it from a C main(). However, I could just provide all of my C demo programs with init()- and fini()-calls at the beginning and the end; that should be clear enough.
Yes, you might want to wrap them in library-init/fini routines, particularly if you need to do other initialization/finalization yourself.
If several such libraries are used together (or one such library with a Pascal main program), RTS initialization/finalization is done several times, but at a guick glance (you might want to check for yourself), I think they are idempotent, so no problem.
Frank