Your SlideShare is downloading. ×
0
5                          XS
                    Tsukuba.xs Beer Talks #1
                            xaicron




2010   ...
• @xaicron
                • http://blog.livedoor.jp/xaicron/
                • XS


2010   7   24
2010   7   24
2010   7   24
•
                • PL_Cehck Hack
                • Perl
                • /* Polyglot */
                • VM

2010   7  ...
2010   7   24
XS




2010   7   24
C




2010   7   24
• make, gcc         C

                • Module::Install::XSUtil


2010   7   24
$ h2xs -A -b 5.8.1 -n Foo::Bar
                $ cd Foo-Bar
                $ tree
                .
                |-- B...
make && make test
                $ perl Makefile.PL
                $ make && make test




2010   7   24
2010   7   24
2010   7   24
Makefile.PL
                use inc::Module::Install;
                use Module::Install::XSUtil;

                name 'F...
$ rm ppport.h
                $ mkdir xs
                $ mv Bar.xs xs
                $ tree
                .
         ...
xs/Bar.xs
                #define PERL_NO_GET_CONTEXT
                #include "EXTERN.h"
                #include "perl.h"...
$ perl Makefile.PL
                $ make
                $ perl -Mblib -MFoo::Bar -le “print Foo::Bar::sum(1 ,2)”
        ...
2010   7   24
XS


2010   7   24
Foo::Bar / Foo::Baz
                     xs


2010   7   24
$ h2xs -A -b 5.8.1 -n Foo::XS




2010   7   24
• xs/Bar.xs, xs/Baz.xs
                • foo.h
                • xs/XS.xs
                • lib/Foo/Bar.pm, lib/Foo/Baz/pm...
xs/Bar.xs
                #define PERL_NO_GET_CONTEXT
                #include "EXTERN.h"
                #include "perl.h"...
xs/Baz.xs
                #define PERL_NO_GET_CONTEXT
                #include "EXTERN.h"
                #include "perl.h"...
foo.h




2010   7   24
xs/XS.xs
            #define PERL_NO_GET_CONTEXT
            #include "EXTERN.h"
            #include "perl.h"
            ...
Foo/Bar.pm Foo/Baz.pm
            package Foo::Bar; # or Baz
            use strict;
            use warnings;
           ...
$ perl Makefile.pl
                $ make test
                $ perl -Mblib -MFoo::Bar -le “print Foo::Bar::sum(1,2)”
    ...
2010   7   24
•             C
                    XS

                • SV     typemap




2010   7   24
Upcoming SlideShare
Loading in...5
×

5分で始める XS - tsukuba.xs#1

731

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
731
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "5分で始める XS - tsukuba.xs#1"

  1. 1. 5 XS Tsukuba.xs Beer Talks #1 xaicron 2010 7 24
  2. 2. • @xaicron • http://blog.livedoor.jp/xaicron/ • XS 2010 7 24
  3. 3. 2010 7 24
  4. 4. 2010 7 24
  5. 5. • • PL_Cehck Hack • Perl • /* Polyglot */ • VM 2010 7 24
  6. 6. 2010 7 24
  7. 7. XS 2010 7 24
  8. 8. C 2010 7 24
  9. 9. • make, gcc C • Module::Install::XSUtil 2010 7 24
  10. 10. $ h2xs -A -b 5.8.1 -n Foo::Bar $ cd Foo-Bar $ tree . |-- Bar.xs |-- Changes |-- MANIFEST |-- Makefile.PL |-- README |-- lib | `-- Foo | `-- Bar.pm |-- ppport.h `-- t `-- Foo-Bar.t 2010 7 24
  11. 11. make && make test $ perl Makefile.PL $ make && make test 2010 7 24
  12. 12. 2010 7 24
  13. 13. 2010 7 24
  14. 14. Makefile.PL use inc::Module::Install; use Module::Install::XSUtil; name 'Foo-Bar'; all_from 'lib/Foo/Bar.pm'; use_ppport 3.19; cc_warnings; cc_src_paths qw(xs); tests 't/*.t'; test_requires 'Test::More'; auto_include; WriteAll; 2010 7 24
  15. 15. $ rm ppport.h $ mkdir xs $ mv Bar.xs xs $ tree . |-- Changes |-- MANIFEST |-- Makefile.PL |-- README |-- lib | `-- Foo | `-- Bar.pm |-- t | `-- Foo-Bar.t `-- xs `-- Bar.xs 2010 7 24
  16. 16. xs/Bar.xs #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" MODULE = Foo::Bar PACKAGE = Foo::Bar PROTOTYPES: DISABLE int sum(int x, int y) CODE: RETVAL = x + y; OUTPUT: RETVAL 2010 7 24
  17. 17. $ perl Makefile.PL $ make $ perl -Mblib -MFoo::Bar -le “print Foo::Bar::sum(1 ,2)” 3 2010 7 24
  18. 18. 2010 7 24
  19. 19. XS 2010 7 24
  20. 20. Foo::Bar / Foo::Baz xs 2010 7 24
  21. 21. $ h2xs -A -b 5.8.1 -n Foo::XS 2010 7 24
  22. 22. • xs/Bar.xs, xs/Baz.xs • foo.h • xs/XS.xs • lib/Foo/Bar.pm, lib/Foo/Baz/pm 2010 7 24
  23. 23. xs/Bar.xs #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" MODULE = Foo::Bar PACKAGE = Foo::Bar PROTOTYPES: DISABLE int sum(int x, int y) CODE: RETVAL = x + y; OUTPUT: RETVAL 2010 7 24
  24. 24. xs/Baz.xs #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" MODULE = Foo::Baz PACKAGE = Foo::Baz PROTOTYPES: DISABLE int double(int x) CODE: RETVAL = x * 2; OUTPUT: RETVAL 2010 7 24
  25. 25. foo.h 2010 7 24
  26. 26. xs/XS.xs #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "foo.h" MODULE = Foo::XS BOOT: FOO_CALL_BOOT(Foo__Bar); FOO_CALL_BOOT(Foo__Baz); 2010 7 24
  27. 27. Foo/Bar.pm Foo/Baz.pm package Foo::Bar; # or Baz use strict; use warnings; use Foo::XS; our $VERSION = ‘0.01’; 1; 2010 7 24
  28. 28. $ perl Makefile.pl $ make test $ perl -Mblib -MFoo::Bar -le “print Foo::Bar::sum(1,2)” 3 $ perl -Mblib -MFoo::Baz -le “print Foo::Baz::double(1)” 2 2010 7 24
  29. 29. 2010 7 24
  30. 30. • C XS • SV typemap 2010 7 24
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×