develooper Front page | perl.perl5.porters | Postings from December 2013

Re: An article on writing Perl extensions without XS

Thread Previous | Thread Next
From:
bulk88
Date:
December 16, 2013 18:46
Subject:
Re: An article on writing Perl extensions without XS
Message ID:
BLU0-SMTP97E1CF7CB95046341F57ADFD80@phx.gbl
bulk88 wrote:
> Steffen Mueller wrote:
>> I wrote the following article with the intention of helping people 
>> understand a tad better what XS does for them under the hood. I could 
>> imagine some on this list might find it interesting.
>>
>> http://blog.booking.com/native-extensions-for-perl-without-smoke-and-mirrors.html 
>>
>>
>> Best regards,
>> Steffen
> 
> Not C89 compliant and not compatible with OSes that dont export all 
> symbols by default (Windows). I will see what I can figure out in my 
> github fork of the code.

After fixing C89 and export table list issues I run into more problems.

first issue is
----------------------------------------------
C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>perl makefile.pl
Warning: NAME must be a package name
WARNING: Setting ABSTRACT via file 'lib/XS/WithoutXS.pm' failed
  at C:/perl519/lib/ExtUtils/MakeMaker.pm line 629.
Generating a nmake-style Makefile
Writing Makefile for XS-WithoutXS
Writing MYMETA.yml and MYMETA.json

C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>
----------------------------------------------
NAME is 'XS-WithoutXS' in Makefile.PL. The problem with name having a - 
in it is, it raises other bugs in the build process.

example build failure
----------------------------------------------
C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>nmake test

Microsoft (R) Program Maintenance Utility Version 7.10.3077
Copyright (C) Microsoft Corporation.  All rights reserved.

Skip blib\lib\XS\WithoutXS.pm (unchanged)
         cl -c  -I.  -nologo -GF -W3 -O1 -MD -Zi -DNDEBUG -G7 -GL 
-DWIN32 -D_CONS
OLE -DNO_STRICT -DPERL_TEXTMODE_SCRIPTS -DPERL_HASH_FUNC_ONE_AT_A_TIME 
-DPERL_IM
PLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T -O1 
-MD -Zi
-DNDEBUG -G7 -GL    -DVERSION=\"0.001\"  -DXS_VERSION=\"0.001\" 
"-IC:\perl519\l
ib\CORE"   this_is_not_xs.c
this_is_not_xs.c
Running Mkbootstrap for XS-WithoutXS ()
         C:\perl519\bin\perl.exe -MExtUtils::Command -e chmod -- 644 
WithoutXS.bs

         C:\perl519\bin\perl.exe -MExtUtils::Mksymlists  -e 
"Mksymlists('NAME'=>\
"XS-WithoutXS\", 'DLBASE' => 'WithoutXS', 'DL_FUNCS' => {  }, 'FUNCLIST' 
=> [q[m
y_sum_xs_macros_are_evil], q[my_sum]], 'IMPORTS' => {  }, 'DL_VARS' => []);"
         link -out:blib\arch\auto\XS-WithoutXS\WithoutXS.dll -dll 
-nologo -nodefa
ultlib -debug -opt:ref,icf -ltcg  -libpath:"c:\perl519\lib\CORE" 
-machine:x86 t
his_is_not_xs.obj   C:\perl519\lib\CORE\perl519.lib oldnames.lib 
kernel32.lib us
er32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib 
ole32.lib
  oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib 
version.lib o
dbc32.lib odbccp32.lib comctl32.lib msvcrt.lib -def:WithoutXS.def
LINK : fatal error LNK1104: cannot open file 'WithoutXS.def'
LINK : fatal error LNK1141: failure during build of exports file
NMAKE : fatal error U1077: 'link' : return code '0x475'
Stop.

C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>
------------------------------------------------------
WithoutXS.def doesn't exist in the build dir, but a "XS-WithoutXS.def" 
(contents of it are correct) does exist. The section that makes the .def is
------------------------------------------------------
# --- MakeMaker dlsyms section:

WithoutXS.def: Makefile.PL
	$(PERLRUN) -MExtUtils::Mksymlists \
      -e "Mksymlists('NAME'=>\"XS-WithoutXS\", 'DLBASE' => '$(BASEEXT)', 
'DL_FUNCS' => {  }, 'FUNCLIST' => [q[my_sum_xs_macros_are_evil], 
q[my_sum]], 'IMPORTS' => {  }, 'DL_VARS' => []);"

------------------------------------------------------
Notice the -'ed NAME being passed.

WithoutXS.bs is built correct (NOECHO is supresed to get console output)
------------------------------------------------------
C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>nmake 
WithoutXS.bs

Microsoft (R) Program Maintenance Utility Version 7.10.3077
Copyright (C) Microsoft Corporation.  All rights reserved.

Running Mkbootstrap for XS-WithoutXS ()
         C:\perl519\bin\perl.exe  "-MExtUtils::Mkbootstrap"  -e 
"Mkbootstrap('Wit
houtXS','');"
         C:\perl519\bin\perl.exe -MExtUtils::Command -e chmod -- 644 
WithoutXS.bs


C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>
-----------------------------------------------------

Even "nmake clean" won't delete the misnamed as XS-WithoutXS.def 
WithoutXS.def
--------------------------------------------------
	C:\perl519\bin\perl.exe -MExtUtils::Command -e rm_f --  WithoutXS.bso 
WithoutXS.def  WithoutXS.exp WithoutXS.x  WithoutXS.bs 
blib\arch\auto\XS-WithoutXS\extralibs.all 
blib\arch\auto\XS-WithoutXS\extralibs.ld Makefile.aperl  *.lib *.obj 
*perl.core MYMETA.json  MYMETA.yml blibdirs.ts  core core.*perl.*.? 
core.[0-9] core.[0-9][0-9]  core.[0-9][0-9][0-9] 
core.[0-9][0-9][0-9][0-9]  core.[0-9][0-9][0-9][0-9][0-9] 
libWithoutXS.def  mon.out perl  perl.exe perl.exe  perlmain.c pm_to_blib 
  pm_to_blib.ts so_locations  tmon.out
--------------------------------------------------

So why does NAME have a - instead of ::?

If I change NAME to "XS::WithoutXS", your test kit fails to find the so/dll.
--------------------------------------------------
C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>nmake test

Microsoft (R) Program Maintenance Utility Version 7.10.3077
Copyright (C) Microsoft Corporation.  All rights reserved.

cp lib/XS/WithoutXS.pm blib\lib\XS\WithoutXS.pm
         cl -c  -I.  -nologo -GF -W3 -O1 -MD -Zi -DNDEBUG -G7 -GL 
-DWIN32 -D_CONS
OLE -DNO_STRICT -DPERL_TEXTMODE_SCRIPTS -DPERL_HASH_FUNC_ONE_AT_A_TIME 
-DPERL_IM
PLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T -O1 
-MD -Zi
-DNDEBUG -G7 -GL    -DVERSION=\"0.001\"  -DXS_VERSION=\"0.001\" 
"-IC:\perl519\l
ib\CORE"   this_is_not_xs.c
this_is_not_xs.c
Running Mkbootstrap for XS::WithoutXS ()
         C:\perl519\bin\perl.exe -MExtUtils::Command -e chmod -- 644 
WithoutXS.bs

         C:\perl519\bin\perl.exe -MExtUtils::Mksymlists  -e 
"Mksymlists('NAME'=>\
"XS::WithoutXS\", 'DLBASE' => 'WithoutXS', 'DL_FUNCS' => {  }, 
'FUNCLIST' => [q[
my_sum_xs_macros_are_evil], q[my_sum]], 'IMPORTS' => {  }, 'DL_VARS' => 
[]);"
         link -out:blib\arch\auto\XS\WithoutXS\WithoutXS.dll -dll 
-nologo -nodefa
ultlib -debug -opt:ref,icf -ltcg  -libpath:"c:\perl519\lib\CORE" 
-machine:x86 t
his_is_not_xs.obj   C:\perl519\lib\CORE\perl519.lib oldnames.lib 
kernel32.lib us
er32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib 
ole32.lib
  oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib 
version.lib o
dbc32.lib odbccp32.lib comctl32.lib msvcrt.lib -def:WithoutXS.def
    Creating library blib\arch\auto\XS\WithoutXS\WithoutXS.lib and 
object blib\ar
ch\auto\XS\WithoutXS\WithoutXS.exp
Generating code
Finished generating code
         if exist blib\arch\auto\XS\WithoutXS\WithoutXS.dll.manifest mt 
-nologo -
manifest blib\arch\auto\XS\WithoutXS\WithoutXS.dll.manifest 
-outputresource:blib
\arch\auto\XS\WithoutXS\WithoutXS.dll;2
         if exist blib\arch\auto\XS\WithoutXS\WithoutXS.dll.manifest del 
blib\arc
h\auto\XS\WithoutXS\WithoutXS.dll.manifest
         C:\perl519\bin\perl.exe -MExtUtils::Command -e chmod -- 755 
blib\arch\au
to\XS\WithoutXS\WithoutXS.dll
         C:\perl519\bin\perl.exe "-MExtUtils::Command::MM" 
"-MTest::Harness" "-e"
  "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 
'blib\arch')" t/*.
t
t/noxs.t .. Failed to locate shared library for 'XS::WithoutXS' at 
C:\Documents
and Settings\Owner\Desktop\cpan libs\muellerxs\blib\lib/XS/WithoutXS.pm 
line 39.

Compilation failed in require at t/noxs.t line 6.
BEGIN failed--compilation aborted at t/noxs.t line 6.
t/noxs.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/2 subtests

Test Summary Report
-------------------
t/noxs.t (Wstat: 512 Tests: 0 Failed: 0)
   Non-zero exit status: 2
   Parse errors: Bad plan.  You planned 2 tests but ran 0.
Files=1, Tests=0,  1 wallclock secs ( 0.08 usr +  0.00 sys =  0.08 CPU)
Result: FAIL
Failed 1/1 test programs. 0/0 subtests failed.
NMAKE : fatal error U1077: 'C:\perl519\bin\perl.exe' : return code '0x2'
Stop.

C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>set 
PERL_DL_DEBUG=1

C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>nmake test

Microsoft (R) Program Maintenance Utility Version 7.10.3077
Copyright (C) Microsoft Corporation.  All rights reserved.

         C:\perl519\bin\perl.exe "-MExtUtils::Command::MM" 
"-MTest::Harness" "-e"
  "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 
'blib\arch')" t/*.
t
DynaLoader.pm loaded (C:/perl519/site/lib C:/perl519/lib ., "C:\Program 
Files\Mi
crosoft Visual Studio .NET 2003\VC7\lib")
DynaLoader::bootstrap for Time::HiRes (auto/Time/HiRes/HiRes.dll)
DynaLoader::bootstrap for Cwd (auto/Cwd/Cwd.dll)
t/noxs.t .. DynaLoader.pm loaded (C:\Documents and 
Settings\Owner\Desktop\cpan l
ibs\muellerxs\blib\lib C:\Documents and Settings\Owner\Desktop\cpan 
libs\mueller
xs\blib\arch C:/perl519/site/lib C:/perl519/lib ., "C:\Program 
Files\Microsoft V
isual Studio .NET 2003\VC7\lib")
dl_findfile(-LC:\Documents and Settings\Owner\Desktop\cpan 
libs\muellerxs\blib\l
ib/auto/XS-WithoutXS -LC:\Documents and Settings\Owner\Desktop\cpan 
libs\mueller
xs\blib\arch/auto/XS-WithoutXS -LC:/perl519/site/lib/auto/XS-WithoutXS 
-LC:/perl
519/lib/auto/XS-WithoutXS -L./auto/XS-WithoutXS WithoutXS)
  dl_findfile ignored non-existent directory: C:\Documents and 
Settings\Owner\Des
ktop\cpan libs\muellerxs\blib\lib/auto/XS-WithoutXS
  dl_findfile ignored non-existent directory: C:\Documents and 
Settings\Owner\Des
ktop\cpan libs\muellerxs\blib\arch/auto/XS-WithoutXS
  dl_findfile ignored non-existent directory: 
C:/perl519/site/lib/auto/XS-Without
XS
  dl_findfile ignored non-existent directory: 
C:/perl519/lib/auto/XS-WithoutXS
  dl_findfile ignored non-existent directory: ./auto/XS-WithoutXS
dl_findfile found:
Failed to locate shared library for 'XS::WithoutXS' at C:\Documents and 
Settings
\Owner\Desktop\cpan libs\muellerxs\blib\lib/XS/WithoutXS.pm line 39.
Compilation failed in require at t/noxs.t line 6.
BEGIN failed--compilation aborted at t/noxs.t line 6.
t/noxs.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/2 subtests

Test Summary Report
-------------------
t/noxs.t (Wstat: 512 Tests: 0 Failed: 0)
   Non-zero exit status: 2
   Parse errors: Bad plan.  You planned 2 tests but ran 0.
Files=1, Tests=0,  0 wallclock secs ( 0.06 usr +  0.01 sys =  0.08 CPU)
Result: FAIL
Failed 1/1 test programs. 0/0 subtests failed.
NMAKE : fatal error U1077: 'C:\perl519\bin\perl.exe' : return code '0x2'
Stop.

C:\Documents and Settings\Owner\Desktop\cpan libs\muellerxs>
------------------------------------------------------

The dll is at "C:\Documents and Settings\Owner\Desktop\cpan 
libs\muellerxs\blib\arch\auto\XS\WithoutXS\WithoutXS.dll" on my disk.

On a side note, with FUNCLIST change the export list looks health 
without a boot_* function winding up in there.
----------------------------------------------
C:\Documents and Settings\Owner\Desktop\cpan 
libs\muellerxs\blib\arch\auto\XS\Wi
thoutXS>dumpbin /exports withoutxs.dll
Microsoft (R) COFF/PE Dumper Version 7.10.6030
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file withoutxs.dll

File Type: DLL

   Section contains the following exports for WithoutXS.dll

     00000000 characteristics
     52AF4907 time date stamp Mon Dec 16 13:40:07 2013
         0.00 version
            1 ordinal base
            4 number of functions
            4 number of names

     ordinal hint RVA      name

           1    0 00001000 _my_sum
           2    1 000010F5 _my_sum_xs_macros_are_evil
           3    2 00001000 my_sum
           4    3 000010F5 my_sum_xs_macros_are_evil

   Summary

         1000 .data
         1000 .rdata
         1000 .reloc
         1000 .text

C:\Documents and Settings\Owner\Desktop\cpan 
libs\muellerxs\blib\arch\auto\XS\Wi
thoutXS>
----------------------------------------------

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About