From: Soren A. <so...@wo...> - 2001-01-07 19:04:04
|
On 7 Jan 2001, an entity purporting to be Richard Pennington [Richard Pennington <ri...@in...>] wrote [regarding Re: [Mingw-users] asm in MSC and in GCC] > On Sun, 07 Jan 2001, Dan Egnor wrote: > [snip - lots of good info] > > But... > > WARNING -- that sample really is bizarre -- it just pops something off the > > stack. They're making assumptions about the calling conventions in use. > > Do you really know what's going on here? (I know I don't.) Absolutely NOT! {chuckles} .. I REALLY appreciate all the great feedback. You are all confirming to me that my half-guesses are not far off. What we are dealing with here is the muckiest of the mucky. Perl XS interface code is *known* to be deeply inscrutible. I will, just for edification, paste below the actual C code generated (but it's exactly the same). But the main point raised -- can't I do this without using assembler -- is basically "no". Not without understanding much more about xs and the API that's being [ab]used here. This is a Perl module source file for interfacing to C subroutines and was written by someone else (Aldo "dada" Calpini) and *I* don't know what he's doing, only that it must've only ever compiled under MSVC++ and (maybe) Borland. As a side note, for laughs, my "C" reference book is so old it says that MSC doesn't even support inline assembler! {G}. I knew it was wrong though, I understood that this is inline assembler. Dan: >> If you try to just substitute the GCC asm() directive for the MSC asm{} >> directive, youwill probably not have much luck. I guess so. And that is just the kind of hacking I am predisposed to try, but based on this good advice I'd like to suppress the urge and find another way. > I'll second this. What kind of add-on is this? Your example seems almost > guaranteed to crash right after printing out self, since it has mucked up > the stack. > > Is this function really called in normal operation? Here's the C: ---- code, watch for wrapping ---- void AbstractCallback() { LPBYTE self; _asm { pop eax mov dword ptr self, eax } printf("AbstractCallback: got eax=%ld\n", self); } ---- end code ---------------------------------------- LOL!!! ... This is my first really deep foray into xs (the Perl glue macros or black magic that lets extensions to perl be written in C). I will economize on my efforts to explain by pasting the posting I have been plastering all over USENET ng's, asking for help with this: --- ng posting ------- Hello Mages, I am trying to compile the Perl 5 module Win32::API (http://dada.perl.it/) on WinNT4 sp6 using MinGW - gcc-2.95.2 and having a rough go of it with the xs code. The compilation fails because this code has an undeclared identifier: --- console output, watch for wrapping -- Reading L:/develperl/site/lib/Make.pm Reading L:\develperl\usr\manual_build\Win32-API-0.20\makefile gcc -c -g -O2 -DWIN32 -fno-strict-aliasing -DPERL_MSVCRT_READFIX - DPERL_POLLUTE -g -O2 -DVERSION=\"0.20\" -DXS_VERSION=\"0.20\" - I..\..\..\lib\CORE API.c API.xs: In function `AbstractCallback': API.xs:52: `_asm' undeclared (first use in this function) API.xs:52: (Each undeclared identifier is reported only once API.xs:52: for each function it appears in.) API.xs:52: parse error before `{' API.xs: At top level: API.xs:56: parse error before string constant API.xs:56: warning: data definition has no type or storage class API.xs: In function `XS_Win32__API_Call': API.xs:282: `_asm' undeclared (first use in this function) API.xs:282: parse error before `{' API.xs:290: parse error before `{' API.xs:298: parse error before `{' API.xs:306: parse error before `{' API.xs:316: parse error before `{' API.xs:326: parse error before `{' API.xs:342: parse error before `{' API.xs:351: parse error before `{' Code 256 from gcc -c -g -O2 -DWIN32 -fno-strict-aliasing - DPERL_MSVCRT_READFIX -DPERL_POLLUTE -DVERSION=\"0.20\" -DXS_VERSION=\"0.20\" - I..\..\..\lib\CORE API.c at L:/develperl/site/l ib/Make.pm line 265. --- code snippet quote w/ line nos., watch for wrapping -- # from Win32-API-0.20/API.xs 48 49 void AbstractCallback() { 50 51 LPBYTE self; 52 _asm { 53 pop eax 54 mov dword ptr self, eax 55 } 56 printf("AbstractCallback: got eax=%ld\n", self); 57 } 58 --- end code snippet quote ------------------------------ So, this _asm critter seems to be the first problem to tackle. I think the possibility exists that some #define isn't happening, that needs to, and maybe it's one that the MSVC would do by default (but not MinGW). The author of this module, Aldo 'dada' Calpini, uses MSVC++ to build his binaries. Nobody that I know of has built this mod using something else. Anybody (perhaps familiar with xs and Win32/MSVC++) got any insights? Thanks Much, soren andersen --- end ng posting --- It would be great to get this mod to compile under MinGW. It's an important Win32 Perl extension that many other modules have a dependency on. Thanks! soren |