SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
5                          XS
                    Tsukuba.xs Beer Talks #1
                            xaicron




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


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

2010   7   24
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
                .
                |-- Bar.xs
                |-- Changes
                |-- MANIFEST
                |-- Makefile.PL
                |-- README
                |-- lib
                | `-- Foo
                |       `-- Bar.pm
                |-- ppport.h
                `-- t
                    `-- Foo-Bar.t




2010   7   24
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 '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
$ 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
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
$ perl Makefile.PL
                $ make
                $ perl -Mblib -MFoo::Bar -le “print Foo::Bar::sum(1 ,2)”
                3




2010   7   24
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

2010   7   24
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
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
foo.h




2010   7   24
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
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
$ 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
2010   7   24
•             C
                    XS

                • SV     typemap




2010   7   24

Mais conteúdo relacionado

Destaque

Receiving Meetings 1 & 2 with Dr Joe Ozawa
Receiving Meetings 1 & 2 with Dr Joe OzawaReceiving Meetings 1 & 2 with Dr Joe Ozawa
Receiving Meetings 1 & 2 with Dr Joe OzawaSSMC
 
Graphic Design Work 2012
Graphic Design Work 2012Graphic Design Work 2012
Graphic Design Work 2012catwomack
 
07 10 kingdom eternal
07 10 kingdom eternal 07 10 kingdom eternal
07 10 kingdom eternal SSMC
 
Webcare sho oxfamnovib
Webcare sho oxfamnovibWebcare sho oxfamnovib
Webcare sho oxfamnovibSMC070
 
7 orthographic
7 orthographic7 orthographic
7 orthographicdan1172
 
From Ingenuity to Innovation: Africa Leapfrogging the 20th Century
From Ingenuity to Innovation: Africa Leapfrogging the 20th CenturyFrom Ingenuity to Innovation: Africa Leapfrogging the 20th Century
From Ingenuity to Innovation: Africa Leapfrogging the 20th CenturyJV Africa
 
What about-those-who-have-never-heard (1)
What about-those-who-have-never-heard (1)What about-those-who-have-never-heard (1)
What about-those-who-have-never-heard (1)SSMC
 
Presentazione La Roche
Presentazione La RochePresentazione La Roche
Presentazione La RocheDavide
 
Láminas tema 6 ECP
Láminas tema 6 ECPLáminas tema 6 ECP
Láminas tema 6 ECPgobernar
 
القضاء على الفساد الاداري والمالي لتحقيق أهداف الثورة الشعبية
القضاء على الفساد الاداري والمالي لتحقيق أهداف الثورة الشعبيةالقضاء على الفساد الاداري والمالي لتحقيق أهداف الثورة الشعبية
القضاء على الفساد الاداري والمالي لتحقيق أهداف الثورة الشعبيةezzeddine
 
Crowdsourcing for Journalism: KipCamp 2014
Crowdsourcing for Journalism: KipCamp 2014Crowdsourcing for Journalism: KipCamp 2014
Crowdsourcing for Journalism: KipCamp 2014Mandy Jenkins
 
Social Media for NGOs and Non-profits
Social Media for NGOs and Non-profitsSocial Media for NGOs and Non-profits
Social Media for NGOs and Non-profitsMandy Jenkins
 
Crowdsourcing, Searching Social Media and Curation Resource List
Crowdsourcing, Searching Social Media and Curation Resource ListCrowdsourcing, Searching Social Media and Curation Resource List
Crowdsourcing, Searching Social Media and Curation Resource ListMandy Jenkins
 
Dollars to Doughnuts: Predicting Prescription Drug Costs of Beneficiaries and...
Dollars to Doughnuts: Predicting Prescription Drug Costs of Beneficiaries and...Dollars to Doughnuts: Predicting Prescription Drug Costs of Beneficiaries and...
Dollars to Doughnuts: Predicting Prescription Drug Costs of Beneficiaries and...M. Christopher Roebuck
 
Mosaic Catalogue for architects
Mosaic Catalogue for architectsMosaic Catalogue for architects
Mosaic Catalogue for architectsguestd10af4
 
Láminas tema 1 ADP
Láminas tema 1 ADPLáminas tema 1 ADP
Láminas tema 1 ADPgobernar
 
Intercession 17 Nov 2013 for the Philipines
Intercession 17 Nov 2013  for the PhilipinesIntercession 17 Nov 2013  for the Philipines
Intercession 17 Nov 2013 for the PhilipinesSSMC
 
Copyright and Terms ofService in Social Media
Copyright and Terms ofService in Social MediaCopyright and Terms ofService in Social Media
Copyright and Terms ofService in Social MediaMandy Jenkins
 

Destaque (20)

Receiving Meetings 1 & 2 with Dr Joe Ozawa
Receiving Meetings 1 & 2 with Dr Joe OzawaReceiving Meetings 1 & 2 with Dr Joe Ozawa
Receiving Meetings 1 & 2 with Dr Joe Ozawa
 
Graphic Design Work 2012
Graphic Design Work 2012Graphic Design Work 2012
Graphic Design Work 2012
 
07 10 kingdom eternal
07 10 kingdom eternal 07 10 kingdom eternal
07 10 kingdom eternal
 
Webcare sho oxfamnovib
Webcare sho oxfamnovibWebcare sho oxfamnovib
Webcare sho oxfamnovib
 
7 orthographic
7 orthographic7 orthographic
7 orthographic
 
From Ingenuity to Innovation: Africa Leapfrogging the 20th Century
From Ingenuity to Innovation: Africa Leapfrogging the 20th CenturyFrom Ingenuity to Innovation: Africa Leapfrogging the 20th Century
From Ingenuity to Innovation: Africa Leapfrogging the 20th Century
 
What about-those-who-have-never-heard (1)
What about-those-who-have-never-heard (1)What about-those-who-have-never-heard (1)
What about-those-who-have-never-heard (1)
 
Presentazione La Roche
Presentazione La RochePresentazione La Roche
Presentazione La Roche
 
Láminas tema 6 ECP
Láminas tema 6 ECPLáminas tema 6 ECP
Láminas tema 6 ECP
 
القضاء على الفساد الاداري والمالي لتحقيق أهداف الثورة الشعبية
القضاء على الفساد الاداري والمالي لتحقيق أهداف الثورة الشعبيةالقضاء على الفساد الاداري والمالي لتحقيق أهداف الثورة الشعبية
القضاء على الفساد الاداري والمالي لتحقيق أهداف الثورة الشعبية
 
Crowdsourcing for Journalism: KipCamp 2014
Crowdsourcing for Journalism: KipCamp 2014Crowdsourcing for Journalism: KipCamp 2014
Crowdsourcing for Journalism: KipCamp 2014
 
Social Media for NGOs and Non-profits
Social Media for NGOs and Non-profitsSocial Media for NGOs and Non-profits
Social Media for NGOs and Non-profits
 
Crowdsourcing, Searching Social Media and Curation Resource List
Crowdsourcing, Searching Social Media and Curation Resource ListCrowdsourcing, Searching Social Media and Curation Resource List
Crowdsourcing, Searching Social Media and Curation Resource List
 
Dollars to Doughnuts: Predicting Prescription Drug Costs of Beneficiaries and...
Dollars to Doughnuts: Predicting Prescription Drug Costs of Beneficiaries and...Dollars to Doughnuts: Predicting Prescription Drug Costs of Beneficiaries and...
Dollars to Doughnuts: Predicting Prescription Drug Costs of Beneficiaries and...
 
schattig.....
schattig.....schattig.....
schattig.....
 
Mosaic Catalogue for architects
Mosaic Catalogue for architectsMosaic Catalogue for architects
Mosaic Catalogue for architects
 
Full report
Full reportFull report
Full report
 
Láminas tema 1 ADP
Láminas tema 1 ADPLáminas tema 1 ADP
Láminas tema 1 ADP
 
Intercession 17 Nov 2013 for the Philipines
Intercession 17 Nov 2013  for the PhilipinesIntercession 17 Nov 2013  for the Philipines
Intercession 17 Nov 2013 for the Philipines
 
Copyright and Terms ofService in Social Media
Copyright and Terms ofService in Social MediaCopyright and Terms ofService in Social Media
Copyright and Terms ofService in Social Media
 

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

Python Programming in Entertainment Industry: Coding Style
Python Programming in Entertainment Industry: Coding StylePython Programming in Entertainment Industry: Coding Style
Python Programming in Entertainment Industry: Coding StyleShuen-Huei Guan
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?Lloyd Huang
 
Overloading Perl OPs using XS
Overloading Perl OPs using XSOverloading Perl OPs using XS
Overloading Perl OPs using XSℕicolas ℝ.
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with itFlavien Raynaud
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges✅ William Pinaud
 

Semelhante a 5分で始める XS - tsukuba.xs#1 (8)

Python Programming in Entertainment Industry: Coding Style
Python Programming in Entertainment Industry: Coding StylePython Programming in Entertainment Industry: Coding Style
Python Programming in Entertainment Industry: Coding Style
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?
 
Having Fun Programming!
Having Fun Programming!Having Fun Programming!
Having Fun Programming!
 
Overloading Perl OPs using XS
Overloading Perl OPs using XSOverloading Perl OPs using XS
Overloading Perl OPs using XS
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with it
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
Sp ch05
Sp ch05Sp ch05
Sp ch05
 

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

  • 1. 5 XS Tsukuba.xs Beer Talks #1 xaicron 2010 7 24
  • 2. • @xaicron • http://blog.livedoor.jp/xaicron/ • XS 2010 7 24
  • 3. 2010 7 24
  • 4. 2010 7 24
  • 5. • PL_Cehck Hack • Perl • /* Polyglot */ • VM 2010 7 24
  • 6. 2010 7 24
  • 7. XS 2010 7 24
  • 8. C 2010 7 24
  • 9. • make, gcc C • Module::Install::XSUtil 2010 7 24
  • 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. make && make test $ perl Makefile.PL $ make && make test 2010 7 24
  • 12. 2010 7 24
  • 13. 2010 7 24
  • 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. $ 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. 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. $ perl Makefile.PL $ make $ perl -Mblib -MFoo::Bar -le “print Foo::Bar::sum(1 ,2)” 3 2010 7 24
  • 18. 2010 7 24
  • 19. XS 2010 7 24
  • 20. Foo::Bar / Foo::Baz xs 2010 7 24
  • 21. $ h2xs -A -b 5.8.1 -n Foo::XS 2010 7 24
  • 22. • xs/Bar.xs, xs/Baz.xs • foo.h • xs/XS.xs • lib/Foo/Bar.pm, lib/Foo/Baz/pm 2010 7 24
  • 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. 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. foo.h 2010 7 24
  • 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. 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. $ 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. 2010 7 24
  • 30. C XS • SV typemap 2010 7 24