It's a right royal pain isn't it!
Perhaps the simplest thing to do is compile your C code to a DLL & lib without any mention of Perl or XS. Ie. No perl or XS headers or makefile stuff. Then use h2xs to generate the XS interface wrappers.
This means that your C functions would have to make no references at all to Perl internal APIs or data structures. So, no SV* parameters. It also means that you need to take full responsibility for freeing any dynamically allocated memory. That means providing destructors and ensuring that the get called in a timely fashion.
It is possible to #undef malloc etc. in order to gain access back to the CRT versions; but you have to be very careful about restricting the scope of those undefs.
It is all together a mess, and the primary reason many of my projects have never come to friution. So much of the library code I've written works perfectly when called from simple or threaded C-only test programs, but as soon as I try to call it from Perl, it just fails in random and mysterious ways and is neigh impossible to debug.
It obviously is possible to do this stuff properly--there are plenty of Win32-only and ported XS modules that work fine--but the secrets of making it work seem to be mostly lost.
All together intensely frustrating. Sorry I don't have better advice.
In reply to Re: XS replacing my c library, not compatible with OS threads
by BrowserUk
in thread XS replacing my c library, not compatible with OS threads
by patcat88
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |