SlideShare a Scribd company logo
1 of 29
Download to read 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

More Related Content

What's hot

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
 

What's hot (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?
 

Similar to 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
 

Similar to 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
 

More from 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
 

More from 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
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

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