SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
C Perl, C Perl Inline, C Perl XS, C Perl Guts                            Abram Hindle




                         C Perl, C Perl Inline, C Perl XS, C Perl Guts

                                            Abram Hindle

                              Victoria Perl Mongers (victoria.pm.org)

                                         abez@abez.ca

                                           March 16, 2004




Victoria.pm                                                                        1
C Perl, C Perl Inline, C Perl XS, C Perl Guts   Abram Hindle




        This Presentation
          • What am I going to Cover?
              – Inline::C

              – Perl Data Structures / Guts

              – XS




Victoria.pm                                               2
C Perl, C Perl Inline, C Perl XS, C Perl Guts                                  Abram Hindle




        This Presentation
          • What am I not going to Cover?
              – How to program in C

              – C++

              – Anything in depth

              – Magic Perl Guts

              – OO and Perl Guts

              – References and Perl Guts

              – SWIG (maybe you should take a look if you’re wrapping a lib)




Victoria.pm                                                                              3
C Perl, C Perl Inline, C Perl XS, C Perl Guts                       Abram Hindle




        Inline::C
          • What is it?
              – Write Perl Subroutines in C [1]

              – Compile and Link C into Perl

              – Embed subroutines into perl scripts and modules

              – Automatically Wrap functions based on prototypes.




Victoria.pm                                                                   4
C Perl, C Perl Inline, C Perl XS, C Perl Guts       Abram Hindle




        Inline::C
          • How do you use Inline::C?
              – use Inline C => CODE;

              – bind Inline C => CODE;
                  ∗ Dynamic generation of C code.
              –   use Inline C;
                  __END__
                  __C__
                  void cCode() {
                  }




Victoria.pm                                                   5
C Perl, C Perl Inline, C Perl XS, C Perl Guts                                        Abram Hindle




        Inline::C
          • How do you use Inline::C?
              – Inline::C parses the function prototypes and wraps them into perl.

              – Function prototypes should be in ANSI style
                ∗ return-type function-name ( type-name-pairs ) ...




Victoria.pm                                                                                    6
C Perl, C Perl Inline, C Perl XS, C Perl Guts                  Abram Hindle




        Inline::C
          • Which types are supported?
              – void → nothing

              – double → scalar

              – char * → string

              – SV* → Scalar

              – long → Scalar

              – float is not supported but you can support it




Victoria.pm                                                              7
C Perl, C Perl Inline, C Perl XS, C Perl Guts   Abram Hindle




        Inline::C
          • Example
              use Inline C;
              helloWorld();
              __END__
              __C__
              void helloWorld() {
                printf("Hello worldn");
              }




Victoria.pm                                               8
C Perl, C Perl Inline, C Perl XS, C Perl Guts   Abram Hindle




        Inline::C
          • Example
              use Inline C;
              hello(’World’);
              hello(42);
              hello(42,42);
              hello(undef);
              __END__
              __C__
              void hello(char * string) {
                printf("Hello %sn",string);
              }




Victoria.pm                                               9
C Perl, C Perl Inline, C Perl XS, C Perl Guts                                      Abram Hindle




        Inline::C
          • Example (perl guts)
              use Inline C;
              $a = "HEY";
              hello(’World’,1,42,undef,’Universe’,$a);
              __END__
              __C__
              void hello(SV* name1, ...) {
                      Inline_Stack_Vars;
                      int i = 0;
                      STRLEN count;
                      for (i = 0; i < Inline_Stack_Items; i++) {
                              char * string = SvPV(Inline_Stack_Item(i), count);
                              printf("Hello %sn",string);
                      }
              }




Victoria.pm                                                                                 10
C Perl, C Perl Inline, C Perl XS, C Perl Guts                                                  Abram Hindle




        Inline::C
          • Inline Stack Access macros
              – Inline Stack Vars       - put this macros at the top of the subroutine as it
                defines new various for Inline Stack macros to work on

              – Inline Stack Items       - how many items are on the stack

              – Inline Stack Item(i)       - get the item at index i in the stack

              – see perldoc Inline::C




Victoria.pm                                                                                             11
C Perl, C Perl Inline, C Perl XS, C Perl Guts   Abram Hindle




        Perl Guts
          • Types in C [5]
              – SV - Scalar Value

              – AV - Array Value

              – HV - Hash Value

              – IV - Integer Value *

              – UV - Unsigned Value *

              – NV - Double Value *

              – PV - String Value *

              – * return values




Victoria.pm                                              12
C Perl, C Perl Inline, C Perl XS, C Perl Guts                 Abram Hindle




        Perl Guts
          • Convert Scalars [5] ( these are macros )
              – int SvIV(SV*)

              – unsigned int SvUV(SV*)

              – double SvNV(SV*)

              – char * SvPV(SV*, STRLEN len)
               ∗ puts length in len, i is the buffer in SV*
              – char * SvPV nolen(SV*)




Victoria.pm                                                            13
C Perl, C Perl Inline, C Perl XS, C Perl Guts           Abram Hindle




        Perl Guts
          • Set scalars [5] ( these are macros )
              – void sv setiv(SV*, IV);

              – void sv setuv(SV*, UV);

              – void sv setnv(SV*, double);

              – void sv setpv(SV*, const char*);

              – void sv setpvn(SV*, const char*, int)




Victoria.pm                                                      14
C Perl, C Perl Inline, C Perl XS, C Perl Guts         Abram Hindle




        Perl Guts
          • Create scalars [5] ( these are macros )
              – SV* newSViv(IV);

              – SV* newSVuv(UV);

              – SV* newSVnv(double);

              – SV* newSVpv(const char*, int);

              – SV* newSVpvn(const char*, int);

              – SV* newSVpvf(const char*, ...);

              – SV* newSVsv(SV*);




Victoria.pm                                                    15
C Perl, C Perl Inline, C Perl XS, C Perl Guts                  Abram Hindle




        Perl Guts
          • Arrays [5]
              – Make an array
               ∗ create -    AV* newAV();

               ∗ create -    AV* av make(I32 num, SV **ptr);

              – Operations
               ∗   push - void av push(AV*, SV*);
               ∗   pop - SV* av pop(AV*);
               ∗   shift - SV* av shift(AV*);
               ∗   unshift - void av unshift(AV*, I32 num);




Victoria.pm                                                             16
C Perl, C Perl Inline, C Perl XS, C Perl Guts                    Abram Hindle




        Perl Guts
          • Arrays [5]
              – length - I32 av len(AV*);

              – fetch - SV** av fetch(AV*, I32 key, I32 lval);

              – store - SV** av store(AV*, I32 key, SV* val);

              – clear - void av clear(AV*);

              – destroy - void av undef(AV*);

              – expand - void av extend(AV*, I32 key);




Victoria.pm                                                               17
C Perl, C Perl Inline, C Perl XS, C Perl Guts                                   Abram Hindle




        Perl Guts
          • Hashes
              – HV* newHV();

              – SV** hv store(HV*, const char* key, U32 klen, SV* val, U32 hash);

              – SV** hv fetch(HV*, const char* key, U32 klen, I32 lval);

              – bool hv exists(HV*, const char* key, U32 klen);

              – SV* hv delete(HV*, const char* key, U32 klen, I32 flags);

              – void hv clear(HV*);

              – void hv undef(HV*);




Victoria.pm                                                                              18
C Perl, C Perl Inline, C Perl XS, C Perl Guts                      Abram Hindle




        Perl Guts
          • Hash iteration
              – I32 hv iterinit(HV*);

              – HE* hv iternext(HV*);

              – char* hv iterkey(HE* entry, I32* retlen);

              – SV* hv iterval(HV*, HE* entry);

              – SV* hv iternextsv(HV*, char** key, I32* retlen);




Victoria.pm                                                                 19
C Perl, C Perl Inline, C Perl XS, C Perl Guts           Abram Hindle




        Perl Guts
          • Package Vars [5]
              – SV* get sv("package::varname", TRUE);

              – AV* get av("package::varname", TRUE);

              – HV* get hv("package::varname", TRUE);




Victoria.pm                                                      20
C Perl, C Perl Inline, C Perl XS, C Perl Guts                                          Abram Hindle




        Perl Guts
          • Mortality
              – If you have temporary values such as those that are returned or used
                temporarily you want the garbage collection to handle it properley.

              – SV* sv newmortal()

              – SV* sv 2mortal(SV* sv)




Victoria.pm                                                                                     21
C Perl, C Perl Inline, C Perl XS, C Perl Guts                    Abram Hindle




        XS
          • What is XS?
              – interface description format

              – Integrate Perl and C code / libs

              – A language that is used to integrate C w/ Perl

              – Wraps C calls




Victoria.pm                                                               22
C Perl, C Perl Inline, C Perl XS, C Perl Guts                                         Abram Hindle




        XS
          • Into the fire: [4] - Some of this is ripped from the perlxstut
              – h2xs -A -n PackageName

              – Edit PackageName.xs

              – perl Makefile.PL

              – make

              – Make a test script in the PackageName directory

              – make install – only do this if your test script has problems finding
                PackageName




Victoria.pm                                                                                    23
C Perl, C Perl Inline, C Perl XS, C Perl Guts                                       Abram Hindle




        XS
          • The .xs file
              – Prototypes are done differently, see perldoc perlxs and perlxstut

              – First line, return type

              – Second line, prototype in K&R

              – Following lines, type the parameters (newline is the delimiter)

              –   int
                  strcmp(str1,str2)
                          char *str1
                          char *str2




Victoria.pm                                                                                  24
C Perl, C Perl Inline, C Perl XS, C Perl Guts                              Abram Hindle




        XS
          • Lets wrap a already existing function (add this to your .xs)
              – strcmp

              –   #include <string.h>
                  int
                  strcmp(str1,str2)
                          char *str1
                          char *str2
              – That’s it




Victoria.pm                                                                         25
C Perl, C Perl Inline, C Perl XS, C Perl Guts                  Abram Hindle




        XS
          • Lets write a new function (add this to your .xs)
              – hello

              –   void
                  hello()
                  CODE:
                  printf("Hello Worldn");
              – That’s it




Victoria.pm                                                             26
C Perl, C Perl Inline, C Perl XS, C Perl Guts                      Abram Hindle




        XS
          • Lets see our test driver (after make install)
                  #!/usr/bin/perl
                  use Hello;

                  Hello::hello();

                  print join(" ",
                                    Hello::strcmp("a","b"),
                                    Hello::strcmp("a","a"),
                                    Hello::strcmp("bbbb","aaaa")
                          ),$/;

              –




Victoria.pm                                                                 27
C Perl, C Perl Inline, C Perl XS, C Perl Guts   Abram Hindle




        Get Help
          • Where to get Help?
              – perldoc Inline

              – perldoc Inline::C

              – perldoc Inline::C-Cookbook

              – perldoc perlguts

              – perldoc perlapi

              – perldoc perlxs

              – perldoc perlxstut

              – perldoc perlembed




Victoria.pm                                              28
C Perl, C Perl Inline, C Perl XS, C Perl Guts                                             Abram Hindle



        References

        [1] I NGERSON , B. Inline::c - write perl subroutines in c.

        [2] I NGERSON , B., AND WATKISS , N. Inline - write perl subroutines in other
              programming languages.

        [3] M AC E ACHERN , D., AND O RWANT, J. perlembed - how to embed perl in your c
              program.

        [4] O KAMOTO, J. perlxstut - tutorial for writing xsubs.

        [5] P ORTERS , P. . perlguts - introduction to the perl api.

        [6] R OEHRICH , D., O KAMOTO, J., AND S TUHL , B. perlapi - autogenerated
              documentation for the perl public api.

        [7] R OEHRICH , D., AND P ORTERS , T. P. perlxs - xs language reference manual.



Victoria.pm                                                                                        29

Mais conteúdo relacionado

Mais procurados

Understanding Javascript Engines
Understanding Javascript Engines Understanding Javascript Engines
Understanding Javascript Engines Parashuram N
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web DevsRami Sayar
 
IronSmalltalk
IronSmalltalkIronSmalltalk
IronSmalltalkESUG
 
Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14CHOOSE
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMCharles Nutter
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeAlexander Shopov
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談hackstuff
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript EngineKris Mok
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Charles Nutter
 
05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR mattersAlexandre Moneger
 
Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaWei-Bo Chen
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]RootedCON
 
(5) cpp dynamic memory_arrays_and_c-strings
(5) cpp dynamic memory_arrays_and_c-strings(5) cpp dynamic memory_arrays_and_c-strings
(5) cpp dynamic memory_arrays_and_c-stringsNico Ludwig
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015Charles Nutter
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 

Mais procurados (18)

How to write Ruby extensions with Crystal
How to write Ruby extensions with CrystalHow to write Ruby extensions with Crystal
How to write Ruby extensions with Crystal
 
Understanding Javascript Engines
Understanding Javascript Engines Understanding Javascript Engines
Understanding Javascript Engines
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
IronSmalltalk
IronSmalltalkIronSmalltalk
IronSmalltalk
 
Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVM
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java Bytecode
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters
 
Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON China
 
Opal compiler
Opal compilerOpal compiler
Opal compiler
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
 
(5) cpp dynamic memory_arrays_and_c-strings
(5) cpp dynamic memory_arrays_and_c-strings(5) cpp dynamic memory_arrays_and_c-strings
(5) cpp dynamic memory_arrays_and_c-strings
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 

Semelhante a March2004-CPerlRun

Getting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::CGetting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::Cdaoswald
 
Dr archana dhawan bajaj - csharp fundamentals slides
Dr archana dhawan bajaj - csharp fundamentals slidesDr archana dhawan bajaj - csharp fundamentals slides
Dr archana dhawan bajaj - csharp fundamentals slidesDr-archana-dhawan-bajaj
 
The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)Mike Friedman
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaPatrick Allaert
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of JavascriptUniverse41
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.Brian Hsu
 
An OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parserAn OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parserKiwamu Okabe
 
Debugging with pry
Debugging with pryDebugging with pry
Debugging with pryCreditas
 
(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-strings(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-stringsNico Ludwig
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersKirk Kimmel
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformEastBanc Tachnologies
 
Perl 5.10
Perl 5.10Perl 5.10
Perl 5.10acme
 
Make Your Own Perl with Moops
Make Your Own Perl with MoopsMake Your Own Perl with Moops
Make Your Own Perl with MoopsMike Friedman
 
C101 – Intro to Programming with C
C101 – Intro to Programming with CC101 – Intro to Programming with C
C101 – Intro to Programming with Cgpsoft_sk
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 developmentFisnik Doko
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java ProgrammersEric Pederson
 

Semelhante a March2004-CPerlRun (20)

Getting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::CGetting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::C
 
Dr archana dhawan bajaj - csharp fundamentals slides
Dr archana dhawan bajaj - csharp fundamentals slidesDr archana dhawan bajaj - csharp fundamentals slides
Dr archana dhawan bajaj - csharp fundamentals slides
 
The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)
 
Chtp408
Chtp408Chtp408
Chtp408
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 Verona
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of Javascript
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.
 
An OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parserAn OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parser
 
Debugging with pry
Debugging with pryDebugging with pry
Debugging with pry
 
(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-strings(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-strings
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
Perl 5.10
Perl 5.10Perl 5.10
Perl 5.10
 
Karakter dan String
Karakter dan StringKarakter dan String
Karakter dan String
 
Make Your Own Perl with Moops
Make Your Own Perl with MoopsMake Your Own Perl with Moops
Make Your Own Perl with Moops
 
C101 – Intro to Programming with C
C101 – Intro to Programming with CC101 – Intro to Programming with C
C101 – Intro to Programming with C
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 development
 
Perl-C/C++ Integration with Swig
Perl-C/C++ Integration with SwigPerl-C/C++ Integration with Swig
Perl-C/C++ Integration with Swig
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 

Mais de tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

Mais de tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Último

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Último (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

March2004-CPerlRun

  • 1. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Victoria Perl Mongers (victoria.pm.org) abez@abez.ca March 16, 2004 Victoria.pm 1
  • 2. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle This Presentation • What am I going to Cover? – Inline::C – Perl Data Structures / Guts – XS Victoria.pm 2
  • 3. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle This Presentation • What am I not going to Cover? – How to program in C – C++ – Anything in depth – Magic Perl Guts – OO and Perl Guts – References and Perl Guts – SWIG (maybe you should take a look if you’re wrapping a lib) Victoria.pm 3
  • 4. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Inline::C • What is it? – Write Perl Subroutines in C [1] – Compile and Link C into Perl – Embed subroutines into perl scripts and modules – Automatically Wrap functions based on prototypes. Victoria.pm 4
  • 5. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Inline::C • How do you use Inline::C? – use Inline C => CODE; – bind Inline C => CODE; ∗ Dynamic generation of C code. – use Inline C; __END__ __C__ void cCode() { } Victoria.pm 5
  • 6. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Inline::C • How do you use Inline::C? – Inline::C parses the function prototypes and wraps them into perl. – Function prototypes should be in ANSI style ∗ return-type function-name ( type-name-pairs ) ... Victoria.pm 6
  • 7. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Inline::C • Which types are supported? – void → nothing – double → scalar – char * → string – SV* → Scalar – long → Scalar – float is not supported but you can support it Victoria.pm 7
  • 8. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Inline::C • Example use Inline C; helloWorld(); __END__ __C__ void helloWorld() { printf("Hello worldn"); } Victoria.pm 8
  • 9. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Inline::C • Example use Inline C; hello(’World’); hello(42); hello(42,42); hello(undef); __END__ __C__ void hello(char * string) { printf("Hello %sn",string); } Victoria.pm 9
  • 10. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Inline::C • Example (perl guts) use Inline C; $a = "HEY"; hello(’World’,1,42,undef,’Universe’,$a); __END__ __C__ void hello(SV* name1, ...) { Inline_Stack_Vars; int i = 0; STRLEN count; for (i = 0; i < Inline_Stack_Items; i++) { char * string = SvPV(Inline_Stack_Item(i), count); printf("Hello %sn",string); } } Victoria.pm 10
  • 11. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Inline::C • Inline Stack Access macros – Inline Stack Vars - put this macros at the top of the subroutine as it defines new various for Inline Stack macros to work on – Inline Stack Items - how many items are on the stack – Inline Stack Item(i) - get the item at index i in the stack – see perldoc Inline::C Victoria.pm 11
  • 12. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Types in C [5] – SV - Scalar Value – AV - Array Value – HV - Hash Value – IV - Integer Value * – UV - Unsigned Value * – NV - Double Value * – PV - String Value * – * return values Victoria.pm 12
  • 13. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Convert Scalars [5] ( these are macros ) – int SvIV(SV*) – unsigned int SvUV(SV*) – double SvNV(SV*) – char * SvPV(SV*, STRLEN len) ∗ puts length in len, i is the buffer in SV* – char * SvPV nolen(SV*) Victoria.pm 13
  • 14. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Set scalars [5] ( these are macros ) – void sv setiv(SV*, IV); – void sv setuv(SV*, UV); – void sv setnv(SV*, double); – void sv setpv(SV*, const char*); – void sv setpvn(SV*, const char*, int) Victoria.pm 14
  • 15. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Create scalars [5] ( these are macros ) – SV* newSViv(IV); – SV* newSVuv(UV); – SV* newSVnv(double); – SV* newSVpv(const char*, int); – SV* newSVpvn(const char*, int); – SV* newSVpvf(const char*, ...); – SV* newSVsv(SV*); Victoria.pm 15
  • 16. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Arrays [5] – Make an array ∗ create - AV* newAV(); ∗ create - AV* av make(I32 num, SV **ptr); – Operations ∗ push - void av push(AV*, SV*); ∗ pop - SV* av pop(AV*); ∗ shift - SV* av shift(AV*); ∗ unshift - void av unshift(AV*, I32 num); Victoria.pm 16
  • 17. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Arrays [5] – length - I32 av len(AV*); – fetch - SV** av fetch(AV*, I32 key, I32 lval); – store - SV** av store(AV*, I32 key, SV* val); – clear - void av clear(AV*); – destroy - void av undef(AV*); – expand - void av extend(AV*, I32 key); Victoria.pm 17
  • 18. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Hashes – HV* newHV(); – SV** hv store(HV*, const char* key, U32 klen, SV* val, U32 hash); – SV** hv fetch(HV*, const char* key, U32 klen, I32 lval); – bool hv exists(HV*, const char* key, U32 klen); – SV* hv delete(HV*, const char* key, U32 klen, I32 flags); – void hv clear(HV*); – void hv undef(HV*); Victoria.pm 18
  • 19. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Hash iteration – I32 hv iterinit(HV*); – HE* hv iternext(HV*); – char* hv iterkey(HE* entry, I32* retlen); – SV* hv iterval(HV*, HE* entry); – SV* hv iternextsv(HV*, char** key, I32* retlen); Victoria.pm 19
  • 20. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Package Vars [5] – SV* get sv("package::varname", TRUE); – AV* get av("package::varname", TRUE); – HV* get hv("package::varname", TRUE); Victoria.pm 20
  • 21. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Perl Guts • Mortality – If you have temporary values such as those that are returned or used temporarily you want the garbage collection to handle it properley. – SV* sv newmortal() – SV* sv 2mortal(SV* sv) Victoria.pm 21
  • 22. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle XS • What is XS? – interface description format – Integrate Perl and C code / libs – A language that is used to integrate C w/ Perl – Wraps C calls Victoria.pm 22
  • 23. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle XS • Into the fire: [4] - Some of this is ripped from the perlxstut – h2xs -A -n PackageName – Edit PackageName.xs – perl Makefile.PL – make – Make a test script in the PackageName directory – make install – only do this if your test script has problems finding PackageName Victoria.pm 23
  • 24. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle XS • The .xs file – Prototypes are done differently, see perldoc perlxs and perlxstut – First line, return type – Second line, prototype in K&R – Following lines, type the parameters (newline is the delimiter) – int strcmp(str1,str2) char *str1 char *str2 Victoria.pm 24
  • 25. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle XS • Lets wrap a already existing function (add this to your .xs) – strcmp – #include <string.h> int strcmp(str1,str2) char *str1 char *str2 – That’s it Victoria.pm 25
  • 26. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle XS • Lets write a new function (add this to your .xs) – hello – void hello() CODE: printf("Hello Worldn"); – That’s it Victoria.pm 26
  • 27. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle XS • Lets see our test driver (after make install) #!/usr/bin/perl use Hello; Hello::hello(); print join(" ", Hello::strcmp("a","b"), Hello::strcmp("a","a"), Hello::strcmp("bbbb","aaaa") ),$/; – Victoria.pm 27
  • 28. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle Get Help • Where to get Help? – perldoc Inline – perldoc Inline::C – perldoc Inline::C-Cookbook – perldoc perlguts – perldoc perlapi – perldoc perlxs – perldoc perlxstut – perldoc perlembed Victoria.pm 28
  • 29. C Perl, C Perl Inline, C Perl XS, C Perl Guts Abram Hindle References [1] I NGERSON , B. Inline::c - write perl subroutines in c. [2] I NGERSON , B., AND WATKISS , N. Inline - write perl subroutines in other programming languages. [3] M AC E ACHERN , D., AND O RWANT, J. perlembed - how to embed perl in your c program. [4] O KAMOTO, J. perlxstut - tutorial for writing xsubs. [5] P ORTERS , P. . perlguts - introduction to the perl api. [6] R OEHRICH , D., O KAMOTO, J., AND S TUHL , B. perlapi - autogenerated documentation for the perl public api. [7] R OEHRICH , D., AND P ORTERS , T. P. perlxs - xs language reference manual. Victoria.pm 29