SlideShare uma empresa Scribd logo
1 de 38
Hello Embed Perl!
       Hideaki Ohno

   YAPC::Asia Tokyo 2011
About me
Hideaki Ohno
  Github: hideo55
  Twitter: @hide_o_55
  PAUSE: HIDEAKIO
  Blog: http://d.hatena.ne.jp/hide_o_55/
  Perl/C/C++/JavaScript
Agenda

What’s embed perl?
Why use embed perl
Common sense of embed perl
Hello embed perl!
embed perl?
What’s embed perl?
What’s embed perl?
Using Perl From C
  Adding a Perl interpreter to C program
  Calling a Perl subroutine from C program
  Evaluting a Perl statement from C program
  Performing Perl pattern matches and
  substitutions from C program
  Fidding with the Perl stack from C
  program
Adding a Perl
interpreter to C program
Example of embed perl
 mod_perl (Apache)

 http_perl_module (Nginx)

 PL/Perl (PostgreSQL)

 MyPerl (MySQL)
Example of embed perl
 mod_perl (Apache)

 http_perl_module (Nginx)

 PL/Perl (PostgreSQL)

 MyPerl (MySQL)
 node-perl (Node.js)
Why use embed perl?
(What are merits of embed perl)
Why use embed perl?



 Regexp!!!
Why use embed perl?



     Regexp!!!
Don’t needs PCRE because perl’s regexp engine
is 100% perl compatible!
Why use embed perl?



   CPAN!!!
Common sense of
  embed perl
Perl data type
SV       SCALAr value

AV       ARRAY value

HV        HASH value

GV        Glob value

RV      Reference value
Basic usage
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
   PERL_SYS_INIT3(&argc,&argv,&env);
   my_perl = perl_alloc();
   perl_construct(my_perl);
   PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
   perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
   perl_run(my_perl);
   perl_destruct(my_perl);
   perl_free(my_perl);
   PERL_SYS_TERM();
}
Include
#include<EXTERN.h>
Define symbols for specific OSs
such as Windows.

#include<perl.h>
Define symbols and include header
files in accordance with compile
options
Include
From C++
extern “C” {
#include<EXTERN.h>
#include<perl.h>
}
Create interpreter
PerlInterpreter *perl = perl_alloc();
perl_construct(perl);


If you want use multiple interpreter,
use PERL_SET_CONTEXT().

It initialize global state for trace
“current” interpreter.
Parse
perl_perse()
This function parse and compile perl code.
Parse
perl_parse(
  register PerlInterpreter *my_perl,
  XSINIT_t xsinit,
  int argc,
  char** argv,
  char** env
);
xsinit is function pointer of initialize
XS module.

perl -MExtUtils::Embed -e xsinit -- -o perlxsi.c
Run
perl_run()
 Execute “INIT” Block

 Execute perl code

 mod_perl execute this function once at
 initialize time.

 nginx perl module don’t execute this
 function.
Why nginx don’t execute
     perl_run()?
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;

If set PL_exit_flags
PERL_EXIT_DESTRUCT_END, “END” Block is
executed in perl_destruct().
Destructor
perl_destruct()

   Execute “END” block.

   Objects destruction
perl_free()
   Free allocated memory
Q. How to get result
  from C program?
A. TIMTOWDI
Call subroutine and get
        return value
dSP;
ENTER;
SAVETMPS;
PUSHMARK(sp);
XPUSHs(...); //push some variables to stack
PUTBACK;
count = call_sv(sub, G_EVAL);
SPAGAIN;
if (count != 1) croak(“”);
x = SvPVx(POPs, n_a);
Override PerlIO layers


Changing the destination for STDOUT/STDERR
to scalar variables.
Override PerlIO layers

   extern "C" {
   #define PERLIO_NOT_STDIO 0
   #define USE_PERLIO
   #include <EXTERN.h>
   #include <perl.h>
   }

   See also perlio.h
Override PerlIO layers
void override_stdhandle (pTHX_ SV *sv,const char *name ) {
   int status;
   GV *handle = gv_fetchpv(name,TRUE,SVt_PVIO);
   SV *svref = newRV_inc(sv);
   save_gp(handle, 1);
   status = Perl_do_open9(aTHX_ handle, ">:scalar", 8 , FALSE, O_WRONLY,
      0, Nullfp, svref, 1);
   if(status == 0) {
        Perl_croak(aTHX_ "Failed to open %s: %" SVf,name, get_sv("!",TRUE));
   }
}
Override PerlIO layers
void restore_stdhandle (pTHX_ const char *name) {
   int status;
   GV *handle = gv_fetchpv(name,FALSE,SVt_PVIO);

  if( GvIOn(handle) && IoOFP(GvIOn(handle)) &&
(PerlIO_flush(IoOFP(GvIOn(handle))) == -1 ) ) {
    Perl_croak(aTHX_ "Failed to flush %s: "
       SVf,name,get_sv("!",TRUE) );
  }
}
Override PerlIO layers

{
    local *STDOUT;
    my $stdout;
    open STDOUT, ‘>’, ¥$stdout or die $!;
    ...
}
Compile
use ExtUtils::Embed

% cc -o myperl myperl.c `perl -MExtUtils::Embed
-e ccopts -e ldopts`

See ‘perldoc perlembed’ if you want to know
other way of to compile embed perl.
Others


eval

  eval_pv()

  eval_sv()
Reference
perldoc perlembed
perldoc perlcall
perldoc perlapi
perldoc perlxs
perldoc perlguts
perldoc perlapio
Book - Extending and Embedding Perl
Summary

Embed perl is not difficult

If you need the power of Perl in your C
program, then hesitate to jump into the
world of embedded Perl

By challenging the embedded Perl, even
deeper understanding of Perl
Thanks for your
   attention.

Mais conteúdo relacionado

Mais procurados

Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for Dummies
Elizabeth Smith
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
Unit 5
Unit 5Unit 5
Unit 5
siddr
 

Mais procurados (20)

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
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for Dummies
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013Nigel hamilton-megameet-2013
Nigel hamilton-megameet-2013
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7
 
Unit 5
Unit 5Unit 5
Unit 5
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 

Destaque

La ruta de la sal 2013
La ruta de la sal 2013La ruta de la sal 2013
La ruta de la sal 2013
Anam
 
Llsita web n
Llsita web nLlsita web n
Llsita web n
Anam
 
Web norte
Web norteWeb norte
Web norte
Anam
 
Spotkanie z krzysztofem śliwińskim w ramach wiosennej szkoły
Spotkanie z krzysztofem śliwińskim w ramach wiosennej szkołySpotkanie z krzysztofem śliwińskim w ramach wiosennej szkoły
Spotkanie z krzysztofem śliwińskim w ramach wiosennej szkoły
sknsz
 
Power point 3 media
Power point 3 mediaPower point 3 media
Power point 3 media
jackthompson
 
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
Paul G. Huppertz
 
Arabskie przebudzenie
Arabskie przebudzenieArabskie przebudzenie
Arabskie przebudzenie
sknsz
 
Afp toronto 2010 11 f ire up your board for fundraising- easy jobs for every ...
Afp toronto 2010 11 f ire up your board for fundraising- easy jobs for every ...Afp toronto 2010 11 f ire up your board for fundraising- easy jobs for every ...
Afp toronto 2010 11 f ire up your board for fundraising- easy jobs for every ...
gailperry
 
Blacklists amb Squidguard a Debian Squeeze
Blacklists amb Squidguard a Debian SqueezeBlacklists amb Squidguard a Debian Squeeze
Blacklists amb Squidguard a Debian Squeeze
Jordi Clopés Esteban
 
Inwestycje zagraniczne w chinach
Inwestycje zagraniczne w chinachInwestycje zagraniczne w chinach
Inwestycje zagraniczne w chinach
sknsz
 
Power point 5 media
Power point 5 mediaPower point 5 media
Power point 5 media
jackthompson
 

Destaque (20)

Suburbarian - presentation
Suburbarian - presentationSuburbarian - presentation
Suburbarian - presentation
 
Mupe5 120312
Mupe5 120312Mupe5 120312
Mupe5 120312
 
How to Have a Winning Team
How to Have a Winning TeamHow to Have a Winning Team
How to Have a Winning Team
 
Optiprint 3D Print Eyeglasses Patricia Durán Ospina
Optiprint 3D Print Eyeglasses Patricia Durán OspinaOptiprint 3D Print Eyeglasses Patricia Durán Ospina
Optiprint 3D Print Eyeglasses Patricia Durán Ospina
 
La ruta de la sal 2013
La ruta de la sal 2013La ruta de la sal 2013
La ruta de la sal 2013
 
Llsita web n
Llsita web nLlsita web n
Llsita web n
 
Presentation to create awareness in the top management of sport organization ...
Presentation to create awareness in the top management of sport organization ...Presentation to create awareness in the top management of sport organization ...
Presentation to create awareness in the top management of sport organization ...
 
2012 ii^ 18.30 dopo dedicazione
2012 ii^ 18.30 dopo dedicazione2012 ii^ 18.30 dopo dedicazione
2012 ii^ 18.30 dopo dedicazione
 
Web norte
Web norteWeb norte
Web norte
 
Spotkanie z krzysztofem śliwińskim w ramach wiosennej szkoły
Spotkanie z krzysztofem śliwińskim w ramach wiosennej szkołySpotkanie z krzysztofem śliwińskim w ramach wiosennej szkoły
Spotkanie z krzysztofem śliwińskim w ramach wiosennej szkoły
 
Power point 3 media
Power point 3 mediaPower point 3 media
Power point 3 media
 
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
Lecture 'Servicialisation - Service Consumers Center Stage' 2012-05-24 V01.02.00
 
Ldap a debian 2: nss i pam
Ldap a debian 2: nss i pamLdap a debian 2: nss i pam
Ldap a debian 2: nss i pam
 
Arabskie przebudzenie
Arabskie przebudzenieArabskie przebudzenie
Arabskie przebudzenie
 
Afp toronto 2010 11 f ire up your board for fundraising- easy jobs for every ...
Afp toronto 2010 11 f ire up your board for fundraising- easy jobs for every ...Afp toronto 2010 11 f ire up your board for fundraising- easy jobs for every ...
Afp toronto 2010 11 f ire up your board for fundraising- easy jobs for every ...
 
Srinivas, Nirmalaya - Testing a massively multi-player online game
Srinivas, Nirmalaya - Testing a massively multi-player online gameSrinivas, Nirmalaya - Testing a massively multi-player online game
Srinivas, Nirmalaya - Testing a massively multi-player online game
 
Blacklists amb Squidguard a Debian Squeeze
Blacklists amb Squidguard a Debian SqueezeBlacklists amb Squidguard a Debian Squeeze
Blacklists amb Squidguard a Debian Squeeze
 
Evaluation – question 3
Evaluation – question 3Evaluation – question 3
Evaluation – question 3
 
Inwestycje zagraniczne w chinach
Inwestycje zagraniczne w chinachInwestycje zagraniczne w chinach
Inwestycje zagraniczne w chinach
 
Power point 5 media
Power point 5 mediaPower point 5 media
Power point 5 media
 

Semelhante a Yapcasia2011 - Hello Embed Perl

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Unit 4
Unit 4Unit 4
Unit 4
siddr
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
IO redirection in C shellPlease implement input output redirect.pdf
IO redirection in C shellPlease implement input  output redirect.pdfIO redirection in C shellPlease implement input  output redirect.pdf
IO redirection in C shellPlease implement input output redirect.pdf
forecastfashions
 
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
AdrianEBJKingr
 

Semelhante a Yapcasia2011 - Hello Embed Perl (20)

PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Plpgsql internals
Plpgsql internalsPlpgsql internals
Plpgsql internals
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Embedding perl
Embedding perlEmbedding perl
Embedding perl
 
Unit 4
Unit 4Unit 4
Unit 4
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
05 pig user defined functions (udfs)
05 pig user defined functions (udfs)05 pig user defined functions (udfs)
05 pig user defined functions (udfs)
 
IO redirection in C shellPlease implement input output redirect.pdf
IO redirection in C shellPlease implement input  output redirect.pdfIO redirection in C shellPlease implement input  output redirect.pdf
IO redirection in C shellPlease implement input output redirect.pdf
 
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
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
 
C++ boot camp part 1/2
C++ boot camp part 1/2C++ boot camp part 1/2
C++ boot camp part 1/2
 
C++ Boot Camp Part 1
C++ Boot Camp Part 1C++ Boot Camp Part 1
C++ Boot Camp Part 1
 
Bluespec @waseda
Bluespec @wasedaBluespec @waseda
Bluespec @waseda
 
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
 

Último

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
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...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

Yapcasia2011 - Hello Embed Perl

  • 1. Hello Embed Perl! Hideaki Ohno YAPC::Asia Tokyo 2011
  • 2. About me Hideaki Ohno Github: hideo55 Twitter: @hide_o_55 PAUSE: HIDEAKIO Blog: http://d.hatena.ne.jp/hide_o_55/ Perl/C/C++/JavaScript
  • 3. Agenda What’s embed perl? Why use embed perl Common sense of embed perl
  • 7. What’s embed perl? Using Perl From C Adding a Perl interpreter to C program Calling a Perl subroutine from C program Evaluting a Perl statement from C program Performing Perl pattern matches and substitutions from C program Fidding with the Perl stack from C program
  • 9. Example of embed perl mod_perl (Apache) http_perl_module (Nginx) PL/Perl (PostgreSQL) MyPerl (MySQL)
  • 10. Example of embed perl mod_perl (Apache) http_perl_module (Nginx) PL/Perl (PostgreSQL) MyPerl (MySQL) node-perl (Node.js)
  • 11. Why use embed perl? (What are merits of embed perl)
  • 12. Why use embed perl? Regexp!!!
  • 13. Why use embed perl? Regexp!!! Don’t needs PCRE because perl’s regexp engine is 100% perl compatible!
  • 14. Why use embed perl? CPAN!!!
  • 15. Common sense of embed perl
  • 16. Perl data type SV SCALAr value AV ARRAY value HV HASH value GV Glob value RV Reference value
  • 17. Basic usage #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, NULL, argc, argv, (char **)NULL); perl_run(my_perl); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 18. Include #include<EXTERN.h> Define symbols for specific OSs such as Windows. #include<perl.h> Define symbols and include header files in accordance with compile options
  • 19. Include From C++ extern “C” { #include<EXTERN.h> #include<perl.h> }
  • 20. Create interpreter PerlInterpreter *perl = perl_alloc(); perl_construct(perl); If you want use multiple interpreter, use PERL_SET_CONTEXT(). It initialize global state for trace “current” interpreter.
  • 21. Parse perl_perse() This function parse and compile perl code.
  • 22. Parse perl_parse( register PerlInterpreter *my_perl, XSINIT_t xsinit, int argc, char** argv, char** env ); xsinit is function pointer of initialize XS module. perl -MExtUtils::Embed -e xsinit -- -o perlxsi.c
  • 23. Run perl_run() Execute “INIT” Block Execute perl code mod_perl execute this function once at initialize time. nginx perl module don’t execute this function.
  • 24. Why nginx don’t execute perl_run()? PL_exit_flags |= PERL_EXIT_DESTRUCT_END; If set PL_exit_flags PERL_EXIT_DESTRUCT_END, “END” Block is executed in perl_destruct().
  • 25. Destructor perl_destruct() Execute “END” block. Objects destruction perl_free() Free allocated memory
  • 26. Q. How to get result from C program?
  • 28. Call subroutine and get return value dSP; ENTER; SAVETMPS; PUSHMARK(sp); XPUSHs(...); //push some variables to stack PUTBACK; count = call_sv(sub, G_EVAL); SPAGAIN; if (count != 1) croak(“”); x = SvPVx(POPs, n_a);
  • 29. Override PerlIO layers Changing the destination for STDOUT/STDERR to scalar variables.
  • 30. Override PerlIO layers extern "C" { #define PERLIO_NOT_STDIO 0 #define USE_PERLIO #include <EXTERN.h> #include <perl.h> } See also perlio.h
  • 31. Override PerlIO layers void override_stdhandle (pTHX_ SV *sv,const char *name ) { int status; GV *handle = gv_fetchpv(name,TRUE,SVt_PVIO); SV *svref = newRV_inc(sv); save_gp(handle, 1); status = Perl_do_open9(aTHX_ handle, ">:scalar", 8 , FALSE, O_WRONLY, 0, Nullfp, svref, 1); if(status == 0) { Perl_croak(aTHX_ "Failed to open %s: %" SVf,name, get_sv("!",TRUE)); } }
  • 32. Override PerlIO layers void restore_stdhandle (pTHX_ const char *name) { int status; GV *handle = gv_fetchpv(name,FALSE,SVt_PVIO); if( GvIOn(handle) && IoOFP(GvIOn(handle)) && (PerlIO_flush(IoOFP(GvIOn(handle))) == -1 ) ) { Perl_croak(aTHX_ "Failed to flush %s: " SVf,name,get_sv("!",TRUE) ); } }
  • 33. Override PerlIO layers { local *STDOUT; my $stdout; open STDOUT, ‘>’, ¥$stdout or die $!; ... }
  • 34. Compile use ExtUtils::Embed % cc -o myperl myperl.c `perl -MExtUtils::Embed -e ccopts -e ldopts` See ‘perldoc perlembed’ if you want to know other way of to compile embed perl.
  • 36. Reference perldoc perlembed perldoc perlcall perldoc perlapi perldoc perlxs perldoc perlguts perldoc perlapio Book - Extending and Embedding Perl
  • 37. Summary Embed perl is not difficult If you need the power of Perl in your C program, then hesitate to jump into the world of embedded Perl By challenging the embedded Perl, even deeper understanding of Perl
  • 38. Thanks for your attention.

Notas do Editor

  1. \n
  2. &amp;#x307E;&amp;#x305A;&amp;#x3001;&amp;#x81EA;&amp;#x5DF1;&amp;#x7D39;&amp;#x4ECB;&amp;#x304B;&amp;#x3089;&amp;#x3055;&amp;#x305B;&amp;#x3066;&amp;#x304F;&amp;#x3060;&amp;#x3055;&amp;#x3044;&amp;#x3002;\n&amp;#x306F;&amp;#x3058;&amp;#x3081;&amp;#x307E;&amp;#x3057;&amp;#x3066;&amp;#x5927;&amp;#x91CE;&amp;#x79C0;&amp;#x660E;&amp;#x3068;&amp;#x8A00;&amp;#x3044;&amp;#x307E;&amp;#x3059;&amp;#x3002;\nYAPC::Asia&amp;#x306B;&amp;#x53C2;&amp;#x52A0;&amp;#x3059;&amp;#x308B;&amp;#x306E;&amp;#x306F;&amp;#x4ECA;&amp;#x56DE;&amp;#x304C;2&amp;#x56DE;&amp;#x76EE;&amp;#x3067;&amp;#x3059;&amp;#x3002;\n&amp;#x305D;&amp;#x3082;&amp;#x305D;&amp;#x3082;Perl&amp;#x306E;&amp;#x30B3;&amp;#x30DF;&amp;#x30E5;&amp;#x30CB;&amp;#x30C6;&amp;#x30A3;&amp;#x306B;&amp;#x95A2;&amp;#x308F;&amp;#x3063;&amp;#x305F;&amp;#x306E;&amp;#x304C;&amp;#x53BB;&amp;#x5E74;&amp;#x306E;YAPC::Asia&amp;#x304C;&amp;#x521D;&amp;#x3081;&amp;#x3066;&amp;#x3067;&amp;#x3001;&amp;#x305D;&amp;#x306E;&amp;#x5F8C;&amp;#x3053;&amp;#x306E;&amp;#x4E00;&amp;#x5E74;Hachioji.pm&amp;#x3001;Perl Advent Calendar&amp;#x306B;&amp;#x53C2;&amp;#x52A0;&amp;#x3059;&amp;#x308B;&amp;#x306A;&amp;#x3069;&amp;#x95A2;&amp;#x308F;&amp;#x3063;&amp;#x3066;&amp;#x304D;&amp;#x307E;&amp;#x3057;&amp;#x305F;&amp;#x3002;\n&amp;#x666E;&amp;#x6BB5;&amp;#x306E;&amp;#x4ED5;&amp;#x4E8B;&amp;#x306F;&amp;#x6240;&amp;#x8B02;SIer&amp;#x3067;&amp;#x30B9;&amp;#x30FC;&amp;#x30C4;&amp;#x7740;&amp;#x3066;&amp;#x4ED5;&amp;#x4E8B;&amp;#x3092;&amp;#x3057;&amp;#x3066;&amp;#x3044;&amp;#x307E;&amp;#x3059;&amp;#x3002;\n\n
  3. \n
  4. \n
  5. \n
  6. \n
  7. &amp;#x30FB;C&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30E0;&amp;#x306B;Perl&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x30D7;&amp;#x30EA;&amp;#x30BF;&amp;#x3092;&amp;#x8FFD;&amp;#x52A0;&amp;#x3059;&amp;#x308B;\n&amp;#x30FB;Perl&amp;#x30B5;&amp;#x30D6;&amp;#x30EB;&amp;#x30FC;&amp;#x30C1;&amp;#x30F3;&amp;#x3092;C&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30E0;&amp;#x304B;&amp;#x3089;&amp;#x547C;&amp;#x3073;&amp;#x51FA;&amp;#x3059;\n&amp;#x30FB;C&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30E0;&amp;#x304B;&amp;#x3089;Perl&amp;#x306E;&amp;#x6587;&amp;#x3092;&amp;#x8A55;&amp;#x4FA1;&amp;#x3059;&amp;#x308B;\n&amp;#x30FB;C&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30E0;&amp;#x304B;&amp;#x3089;Perl&amp;#x306E;&amp;#x30D1;&amp;#x30BF;&amp;#x30FC;&amp;#x30F3;&amp;#x30DE;&amp;#x30C3;&amp;#x30C1;&amp;#x3001;&amp;#x7F6E;&amp;#x63DB;&amp;#x3092;&amp;#x5B9F;&amp;#x884C;&amp;#x3059;&amp;#x308B;\n&amp;#x30FB;C&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30E0;&amp;#x304B;&amp;#x3089;Perl&amp;#x306E;&amp;#x30B9;&amp;#x30BF;&amp;#x30C3;&amp;#x30AF;&amp;#x3092;&amp;#x64CD;&amp;#x4F5C;&amp;#x3059;&amp;#x308B;\n
  8. &amp;#x3053;&amp;#x306E;&amp;#x3088;&amp;#x3046;&amp;#x306B;C&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30E0;&amp;#x304B;&amp;#x3089;Perl&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x30D7;&amp;#x30EA;&amp;#x30BF;&amp;#x306B;Perl&amp;#x30B3;&amp;#x30FC;&amp;#x30C9;&amp;#x3092;&amp;#x9001;&amp;#x308A;&amp;#x8FBC;&amp;#x307F;&amp;#x305D;&amp;#x306E;&amp;#x51FA;&amp;#x529B;&amp;#x3092;&amp;#x5F97;&amp;#x308B;&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x5F62;&amp;#x5F0F;&amp;#x306B;&amp;#x306A;&amp;#x308A;&amp;#x307E;&amp;#x3059;\n
  9. &amp;#x57CB;&amp;#x3081;&amp;#x8FBC;&amp;#x307F;Perl&amp;#x3092;&amp;#x5229;&amp;#x7528;&amp;#x3057;&amp;#x305F;&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30E0;&amp;#x3067;&amp;#x6709;&amp;#x540D;&amp;#x306A;&amp;#x3082;&amp;#x306E;&amp;#x3092;&amp;#x3042;&amp;#x3052;&amp;#x3066;&amp;#x3044;&amp;#x307E;&amp;#x3059;&amp;#x3002;\nmod_perl&amp;#x306F;Apache HTTP Server&amp;#x306B;Perl&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x30D7;&amp;#x30EA;&amp;#x30BF;&amp;#x3092;&amp;#x57CB;&amp;#x3081;&amp;#x8FBC;&amp;#x3080;&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x3082;&amp;#x306E;\nnode-perl&amp;#x3092;&amp;#x4F5C;&amp;#x3063;&amp;#x305F;&amp;#x52D5;&amp;#x6A5F;&amp;#x306F;&amp;#x305F;&amp;#x3060;&amp;#x4F5C;&amp;#x308A;&amp;#x305F;&amp;#x304B;&amp;#x3063;&amp;#x305F;&amp;#x304B;&amp;#x3089;\nNode.js&amp;#x3067;&amp;#x4F55;&amp;#x304B;&amp;#x4F5C;&amp;#x308A;&amp;#x305F;&amp;#x3044;&amp;#x3001;Node.js &amp;#x306E;&amp;#x30A2;&amp;#x30C9;&amp;#x30AA;&amp;#x30F3;&amp;#x306F;C++&amp;#x3067;&amp;#x66F8;&amp;#x3051;&amp;#x308B;&amp;#x3001;C++&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x3053;&amp;#x3068;&amp;#x306F;C&amp;#x306E;&amp;#x30E9;&amp;#x30A4;&amp;#x30D6;&amp;#x30E9;&amp;#x30EA;&amp;#x3082;&amp;#x4F7F;&amp;#x3048;&amp;#x308B;&amp;#x3001;Perl&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x30D7;&amp;#x30EA;&amp;#x30BF;&amp;#x306F;C&amp;#x3060;&amp;#x304B;&amp;#x3089;&amp;#x7D44;&amp;#x307F;&amp;#x8FBC;&amp;#x3081;&amp;#x308B;&amp;#xFF01;&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x6975;&amp;#x3081;&amp;#x3066;&amp;#x81EA;&amp;#x7136;&amp;#x306A;&amp;#x6D41;&amp;#x308C;&amp;#x3067;&amp;#x3059;&amp;#x3002;\n
  10. \n
  11. &amp;#x30FB;Perl&amp;#x3068;&amp;#x3044;&amp;#x3048;&amp;#x3070;&amp;#x6B63;&amp;#x898F;&amp;#x8868;&amp;#x73FE;&amp;#x3001;&amp;#x6B63;&amp;#x898F;&amp;#x8868;&amp;#x73FE;&amp;#x3068;&amp;#x3044;&amp;#x3048;&amp;#x3070;Perl&amp;#x3068;&amp;#x8A00;&amp;#x3063;&amp;#x3066;&amp;#x3082;&amp;#x3044;&amp;#x3044;&amp;#x304F;&amp;#x3089;&amp;#x3044;&amp;#x5207;&amp;#x3063;&amp;#x3066;&amp;#x3082;&amp;#x5207;&amp;#x308C;&amp;#x306A;&amp;#x3044;&amp;#x95A2;&amp;#x4FC2;\n&amp;#x30FB;&amp;#x590F;&amp;#x306E;Shibuya.pm&amp;#x3082;&amp;#x30C6;&amp;#x30FC;&amp;#x30DE;&amp;#x306F;&amp;#x6B63;&amp;#x898F;&amp;#x8868;&amp;#x73FE;&amp;#x3001;&amp;#x6B63;&amp;#x898F;&amp;#x2191;&amp;#x8868;&amp;#x73FE;&amp;#x2193;&amp;#xFF1F;\n&amp;#x30FB;Perl&amp;#x3092;&amp;#x6B63;&amp;#x898F;&amp;#x8868;&amp;#x73FE;&amp;#x30A8;&amp;#x30F3;&amp;#x30B8;&amp;#x30F3;&amp;#x3068;&amp;#x3057;&amp;#x3066;&amp;#x4F7F;&amp;#x3048;&amp;#x3070;&amp;#x3001;&amp;#xFF30;&amp;#xFF23;&amp;#xFF32;&amp;#xFF25;&amp;#x3068;&amp;#x304B;&amp;#x4F7F;&amp;#x308F;&amp;#x306A;&amp;#x304F;&amp;#x3066;&amp;#x3082;100%Perl&amp;#x30B3;&amp;#x30F3;&amp;#x30D1;&amp;#x30C1;&amp;#x30D6;&amp;#x30EB;&amp;#x306A;&amp;#x6B63;&amp;#x898F;&amp;#x8868;&amp;#x73FE;&amp;#x304C;&amp;#x4F7F;&amp;#x3048;&amp;#x308B;\n
  12. &amp;#x30FB;&amp;#x67D4;&amp;#x8EDF;&amp;#x304B;&amp;#x3064;&amp;#x5F37;&amp;#x529B;&amp;#x306A;&amp;#x6587;&amp;#x5B57;&amp;#x5217;&amp;#x64CD;&amp;#x4F5C;\n&amp;#x30FB;CPAN&amp;#x306E;&amp;#x529B;&amp;#x306E;&amp;#x6069;&amp;#x6075;&amp;#x3092;&amp;#x53D7;&amp;#x3051;&amp;#x308B;&amp;#x3053;&amp;#x3068;&amp;#x304C;&amp;#x3067;&amp;#x304D;&amp;#x308B;\n
  13. &amp;#x7D44;&amp;#x307F;&amp;#x8FBC;&amp;#x307F;Perl&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x30D7;&amp;#x30EA;&amp;#x30BF;&amp;#x306E;&amp;#x57FA;&amp;#x790E;\n
  14. \n
  15. &amp;#x3053;&amp;#x308C;&amp;#x304C;&amp;#x6700;&amp;#x3082;&amp;#x5358;&amp;#x7D14;&amp;#x306A;&amp;#x57CB;&amp;#x3081;&amp;#x8FBC;&amp;#x307F;Perl&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x30D7;&amp;#x30EA;&amp;#x30BF;&amp;#x306E;&amp;#x4F8B;&amp;#x3067;&amp;#x3059;&amp;#x3002;\n&amp;#x3053;&amp;#x308C;&amp;#x306F;&amp;#x901A;&amp;#x5E38;&amp;#x306E;perl&amp;#x3068;&amp;#x540C;&amp;#x69D8;&amp;#x306B;&amp;#x5F15;&amp;#x6570;&amp;#x3068;&amp;#x3057;&amp;#x3066;&amp;#x30D5;&amp;#x30A1;&amp;#x30A4;&amp;#x30EB;&amp;#x540D;&amp;#x304C;&amp;#x6E21;&amp;#x3055;&amp;#x308C;&amp;#x308C;&amp;#x3070;&amp;#x5B9F;&amp;#x884C;&amp;#x3057;&amp;#x3001;-e&amp;#x30AA;&amp;#x30D7;&amp;#x30B7;&amp;#x30E7;&amp;#x30F3;&amp;#x306A;&amp;#x3069;&amp;#x306E;&amp;#x5B9F;&amp;#x884C;&amp;#x3082;&amp;#x3067;&amp;#x304D;&amp;#x307E;&amp;#x3059;\n
  16. EXTERN.h&amp;#x306F;Windows&amp;#x306A;&amp;#x3069;&amp;#x7279;&amp;#x5B9A;&amp;#x306E;OS&amp;#x7528;&amp;#x306E;&amp;#x30B7;&amp;#x30F3;&amp;#x30DC;&amp;#x30EB;&amp;#x3092;&amp;#x5B9A;&amp;#x7FA9;&amp;#x3057;&amp;#x307E;&amp;#x3059;\nperl.h&amp;#x306F;&amp;#x30B3;&amp;#x30F3;&amp;#x30D1;&amp;#x30A4;&amp;#x30EB;&amp;#x30AA;&amp;#x30D7;&amp;#x30B7;&amp;#x30E7;&amp;#x30F3;&amp;#x306B;&amp;#x5F93;&amp;#x3063;&amp;#x3066;&amp;#x30B7;&amp;#x30F3;&amp;#x30DC;&amp;#x30EB;&amp;#x3092;&amp;#x5B9A;&amp;#x7FA9;&amp;#x3057;&amp;#x305F;&amp;#x308A;&amp;#x3001;&amp;#x30D8;&amp;#x30C3;&amp;#x30C0;&amp;#x30D5;&amp;#x30A1;&amp;#x30A4;&amp;#x30EB;&amp;#x3092;&amp;#x30A4;&amp;#x30F3;&amp;#x30AF;&amp;#x30EB;&amp;#x30FC;&amp;#x30C9;&amp;#x3059;&amp;#x308B;\n
  17. C++&amp;#x304B;&amp;#x3089;&amp;#x4F7F;&amp;#x3046;&amp;#x5834;&amp;#x5408;&amp;#x306F;extern &amp;#x201C;C&amp;#x201D; &amp;#x3092;&amp;#x4F7F;&amp;#x7528;\n
  18. &amp;#x30FB;perl_alloc()&amp;#x306F;&amp;#x30E1;&amp;#x30E2;&amp;#x30EA;&amp;#x306E;&amp;#x78BA;&amp;#x4FDD;\n&amp;#x30FB;perl_constract()&amp;#x304C;&amp;#x30A4;&amp;#x30F3;&amp;#x30B9;&amp;#x30BF;&amp;#x30F3;&amp;#x30B9;&amp;#x306E;&amp;#x521D;&amp;#x671F;&amp;#x5316;\n&amp;#x30FB;&amp;#x8907;&amp;#x6570;&amp;#x306E;&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x30D7;&amp;#x30EA;&amp;#x30BF;&amp;#x3092;&amp;#x4F7F;&amp;#x7528;&amp;#x3059;&amp;#x308B;&amp;#x5834;&amp;#x5408;&amp;#x306F;&amp;#x3001;PERL_SET_CONTEXT()&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x30DE;&amp;#x30AF;&amp;#x30ED;&amp;#x3092;&amp;#x4F7F;&amp;#x7528;&amp;#x3059;&amp;#x308B;&amp;#x5FC5;&amp;#x8981;&amp;#x304C;&amp;#x3042;&amp;#x308B;\n&amp;#x3053;&amp;#x308C;&amp;#x306F;&amp;#x3001;&amp;#x73FE;&amp;#x5728;&amp;#x306E;&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x30D7;&amp;#x30EA;&amp;#x30BF;&amp;#x3092;&amp;#x7279;&amp;#x5B9A;&amp;#x3059;&amp;#x308B;&amp;#x305F;&amp;#x3081;&amp;#x306E;&amp;#x30B0;&amp;#x30ED;&amp;#x30FC;&amp;#x30D0;&amp;#x30EB;&amp;#x306A;&amp;#x72B6;&amp;#x614B;&amp;#x3092;&amp;#x521D;&amp;#x671F;&amp;#x5316;&amp;#x3059;&amp;#x308B;&amp;#x305F;&amp;#x3081;&amp;#x306E;&amp;#x3082;&amp;#x306E;&amp;#x3067;&amp;#x3001;&amp;#x5B9F;&amp;#x969B;&amp;#x306B;&amp;#x306F;cthread_set_data()&amp;#x3067;&amp;#x30B9;&amp;#x30EC;&amp;#x30C3;&amp;#x30C9;&amp;#x30ED;&amp;#x30FC;&amp;#x30AB;&amp;#x30EB;&amp;#x30B9;&amp;#x30C8;&amp;#x30EC;&amp;#x30FC;&amp;#x30B8;&amp;#x306B;&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x30D7;&amp;#x30EA;&amp;#x30BF;&amp;#x306E;&amp;#x60C5;&amp;#x5831;&amp;#x3092;&amp;#x4FDD;&amp;#x5B58;&amp;#x3059;&amp;#x308B;\n
  19. &amp;#x30FB;get_hash_seed() &amp;#x30CF;&amp;#x30C3;&amp;#x30B7;&amp;#x30E5;&amp;#x30C6;&amp;#x30FC;&amp;#x30D6;&amp;#x30EB;&amp;#x306E;&amp;#x305F;&amp;#x3081;&amp;#x306E;&amp;#x30B7;&amp;#x30FC;&amp;#x30C9;&amp;#x3092;&amp;#x53D6;&amp;#x5F97;\n&amp;#x30FB;parse_body()&amp;#x3067;&amp;#x306F;yyparse()&amp;#x3067;&amp;#x69CB;&amp;#x6587;&amp;#x89E3;&amp;#x6790;&amp;#x3001;yylex()&amp;#x3067;&amp;#x5B57;&amp;#x53E5;&amp;#x89E3;&amp;#x6790;&amp;#x3001;OPCODE&amp;#x30C4;&amp;#x30EA;&amp;#x30FC;&amp;#x69CB;&amp;#x7BC9;&amp;#x3001;PL_check&amp;#x306B;&amp;#x3088;&amp;#x308B;&amp;#x6587;&amp;#x6CD5;&amp;#x30A8;&amp;#x30E9;&amp;#x30FC;&amp;#x30C1;&amp;#x30A7;&amp;#x30C3;&amp;#x30AF;&amp;#x3001;OPCODE&amp;#x30C4;&amp;#x30EA;&amp;#x30FC;&amp;#x306E;&amp;#x5909;&amp;#x63DB;&amp;#x3001;&amp;#x6700;&amp;#x9069;&amp;#x5316;&amp;#x3092;&amp;#x884C;&amp;#x308F;&amp;#x308C;&amp;#x308B;\n&amp;#x30FB;process_special_block()&amp;#x3067;BEGIN&amp;#x30D6;&amp;#x30ED;&amp;#x30C3;&amp;#x30AF;&amp;#x5B9F;&amp;#x884C;&amp;#x3001;UNITCHECK&amp;#x3001;CHECK&amp;#x3001;END&amp;#x306F;&amp;#x914D;&amp;#x5217;&amp;#x306B;unshift&amp;#x3001;INIT&amp;#x306F;push&amp;#x3055;&amp;#x308C;&amp;#x3066;&amp;#x3044;&amp;#x304F;\n\n
  20. &amp;#x3053;&amp;#x308C;&amp;#x304C;perl_parse&amp;#x306E;&amp;#x30D7;&amp;#x30ED;&amp;#x30C8;&amp;#x30BF;&amp;#x30A4;&amp;#x30D7;&amp;#x3067;&amp;#x3059;&amp;#x3002;\n&amp;#x3053;&amp;#x3053;&amp;#x3067;&amp;#x6CE8;&amp;#x76EE;&amp;#x3059;&amp;#x3079;&amp;#x304D;&amp;#x306F;&amp;#x7B2C;&amp;#x4E8C;&amp;#x5F15;&amp;#x6570;&amp;#x306E;xsinit&amp;#x3067;&amp;#x3059;&amp;#x3002;\n&amp;#x3053;&amp;#x306E;xsinit&amp;#x306F;C/C++&amp;#x3067;&amp;#x66F8;&amp;#x304B;&amp;#x308C;&amp;#x305F;&amp;#x30E2;&amp;#x30B8;&amp;#x30E5;&amp;#x30FC;&amp;#x30EB;&amp;#x3092;&amp;#x30ED;&amp;#x30FC;&amp;#x30C9;&amp;#x3059;&amp;#x308B;&amp;#x95A2;&amp;#x6570;&amp;#x3078;&amp;#x306E;&amp;#x95A2;&amp;#x6570;&amp;#x30DD;&amp;#x30A4;&amp;#x30F3;&amp;#x30BF;&amp;#x3067;&amp;#x3059;&amp;#x3002;\n&amp;#x3053;&amp;#x306E;xsinit&amp;#x3067;Dynaloader&amp;#x3084;XSLoader&amp;#xFF64;&amp;#x72EC;&amp;#x81EA;&amp;#x306E;&amp;#x30D6;&amp;#x30FC;&amp;#x30C8;&amp;#x30B9;&amp;#x30C8;&amp;#x30E9;&amp;#x30C3;&amp;#x30D7;&amp;#x304C;&amp;#x5FC5;&amp;#x8981;&amp;#x306A;&amp;#x30E2;&amp;#x30B8;&amp;#x30E5;&amp;#x30FC;&amp;#x30EB;&amp;#x304C;&amp;#x3042;&amp;#x308C;&amp;#x3070;&amp;#x305D;&amp;#x306E;&amp;#x30D6;&amp;#x30FC;&amp;#x30C8;&amp;#x30B9;&amp;#x30C8;&amp;#x30E9;&amp;#x30C3;&amp;#x30D7;&amp;#x3092;&amp;#x547C;&amp;#x3073;&amp;#x51FA;&amp;#x3057;&amp;#x307E;&amp;#x3059;&amp;#x3002;\n&amp;#x3053;&amp;#x306E;xsinit&amp;#x306F;ExtUtils::Embed&amp;#x3067;&amp;#x751F;&amp;#x6210;&amp;#x3067;&amp;#x304D;&amp;#x308B;&amp;#x306E;&amp;#x3067;&amp;#x30EA;&amp;#x30F3;&amp;#x30AF;&amp;#x3059;&amp;#x308C;&amp;#x3070;&amp;#x554F;&amp;#x984C;&amp;#x3042;&amp;#x308A;&amp;#x307E;&amp;#x305B;&amp;#x3093;\n
  21. perl_run()&amp;#x306E;&amp;#x52D5;&amp;#x4F5C;&amp;#x3068;&amp;#x3057;&amp;#x3066;&amp;#x306F;\n&amp;#x30FB;INIT&amp;#x30D6;&amp;#x30ED;&amp;#x30C3;&amp;#x30AF;&amp;#x306E;&amp;#x5B9F;&amp;#x884C;\n&amp;#x30FB;Perl&amp;#x30B3;&amp;#x30FC;&amp;#x30C9;&amp;#x306E;&amp;#x5B9F;&amp;#x884C;\n&amp;#x30FB;mod_perl&amp;#x306E;&amp;#x5834;&amp;#x5408;&amp;#x306F;&amp;#x521D;&amp;#x671F;&amp;#x5316;&amp;#x6642;&amp;#x306B;&amp;#xFF11;&amp;#x56DE;&amp;#x3060;&amp;#x3051;&amp;#x5B9F;&amp;#x884C;&amp;#x3055;&amp;#x308C;&amp;#x307E;&amp;#x3059;&amp;#x3002;&amp;#x3053;&amp;#x306E;&amp;#x3042;&amp;#x305F;&amp;#x308A;&amp;#x304C;mod_perl&amp;#x3068;&amp;#x9045;&amp;#x5EF6;&amp;#x30ED;&amp;#x30FC;&amp;#x30C9;&amp;#x3084;Attribute&amp;#x3068;&amp;#x76F8;&amp;#x6027;&amp;#x304C;&amp;#x60AA;&amp;#x3044;&amp;#x539F;&amp;#x56E0;\n&amp;#x30FB;nginx&amp;#x306E;perl module&amp;#x306F;perl_run()&amp;#x306F;&amp;#x5B9F;&amp;#x884C;&amp;#x3057;&amp;#x307E;&amp;#x305B;&amp;#x3093;\n
  22. \n
  23. \n
  24. &amp;#x554F;&amp;#xFF1A;C&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30E0;&amp;#x304B;&amp;#x3089;&amp;#x7D50;&amp;#x679C;&amp;#x3092;&amp;#x53D6;&amp;#x5F97;&amp;#x3059;&amp;#x308B;&amp;#x306B;&amp;#x306F;&amp;#x3069;&amp;#x3046;&amp;#x3059;&amp;#x308C;&amp;#x3070;&amp;#x3044;&amp;#x3044;&amp;#x306E;&amp;#x3067;&amp;#x3057;&amp;#x3087;&amp;#x3046;&amp;#x304B;&amp;#xFF1F;\n
  25. A:&amp;#x3084;&amp;#x308A;&amp;#x65B9;&amp;#x306F;&amp;#x4E00;&amp;#x3064;&amp;#x3058;&amp;#x3083;&amp;#x306A;&amp;#x3044;\n
  26. &amp;#x3053;&amp;#x3061;&amp;#x3089;&amp;#x304C;&amp;#x4E00;&amp;#x822C;&amp;#x7684;&amp;#x306A;&amp;#x65B9;&amp;#x6CD5;\nmod_perl&amp;#x3082;nginx&amp;#x306E;perl module&amp;#x3082;&amp;#x3053;&amp;#x306E;&amp;#x65B9;&amp;#x6CD5;\n&amp;#x7279;&amp;#x5B9A;&amp;#x306E;&amp;#x5909;&amp;#x6570;&amp;#x306B;&amp;#x7D50;&amp;#x679C;&amp;#x3092;&amp;#x53CE;&amp;#x3081;&amp;#x308B;&amp;#x5FC5;&amp;#x8981;&amp;#x304C;&amp;#x3042;&amp;#x308B;&amp;#x305F;&amp;#x3081;&amp;#x3001;&amp;#x81EA;&amp;#x7531;&amp;#x5EA6;&amp;#x304C;&amp;#x4F4E;&amp;#x3044;\n&amp;#x30FB;XPUSHs()&amp;#x3067;&amp;#x5F15;&amp;#x6570;&amp;#x3068;&amp;#x306A;&amp;#x308B;&amp;#x5909;&amp;#x6570;&amp;#x3092;&amp;#x30B9;&amp;#x30BF;&amp;#x30C3;&amp;#x30AF;&amp;#x306B;&amp;#x7A4D;&amp;#x3093;&amp;#x3067;&amp;#x3001;call_sv()&amp;#x3067;&amp;#x30B5;&amp;#x30D6;&amp;#x30EB;&amp;#x30FC;&amp;#x30C1;&amp;#x30F3;&amp;#x304C;&amp;#x5B9F;&amp;#x884C;&amp;#x3055;&amp;#x308C;&amp;#x308B;&amp;#x3002;\n&amp;#x30FB;count&amp;#x306F;&amp;#x623B;&amp;#x308A;&amp;#x5024;&amp;#x306E;&amp;#x6570;\n&amp;#x30FB;POPs&amp;#x3067;&amp;#x30B9;&amp;#x30BF;&amp;#x30C3;&amp;#x30AF;&amp;#x304B;&amp;#x3089;&amp;#x5F15;&amp;#x6570;&amp;#x3092;&amp;#x53D6;&amp;#x308A;&amp;#x51FA;&amp;#x3059;\n
  27. &amp;#x6A19;&amp;#x6E96;&amp;#x51FA;&amp;#x529B;&amp;#x3001;&amp;#x6A19;&amp;#x6E96;&amp;#x30A8;&amp;#x30E9;&amp;#x30FC;&amp;#x51FA;&amp;#x529B;&amp;#x306E;&amp;#x51FA;&amp;#x529B;&amp;#x5148;&amp;#x3092;&amp;#x30B9;&amp;#x30AB;&amp;#x30E9;&amp;#x5909;&amp;#x6570;&amp;#x306B;&amp;#x5909;&amp;#x3048;&amp;#x308B;\n
  28. \n
  29. Perl_do_open9()&amp;#x3067;&amp;#x30CF;&amp;#x30F3;&amp;#x30C9;&amp;#x30EB;&amp;#x306E;&amp;#x51FA;&amp;#x529B;&amp;#x5148;&amp;#x3068;&amp;#x3057;&amp;#x3066;&amp;#x30B9;&amp;#x30AB;&amp;#x30E9;&amp;#x5909;&amp;#x6570;&amp;#x306E;&amp;#x30EA;&amp;#x30D5;&amp;#x30A1;&amp;#x30EC;&amp;#x30F3;&amp;#x30B9;&amp;#x3092;&amp;#x6307;&amp;#x5B9A;&amp;#x3057;&amp;#x3066;&amp;#x3044;&amp;#x308B;\n
  30. &amp;#x4FDD;&amp;#x5B58;&amp;#x3057;&amp;#x3066;&amp;#x304A;&amp;#x3044;&amp;#x305F;&amp;#x5143;&amp;#x306E;&amp;#x30D5;&amp;#x30A1;&amp;#x30A4;&amp;#x30EB;&amp;#x30CF;&amp;#x30F3;&amp;#x30C9;&amp;#x30EB;&amp;#x3092;&amp;#x53D6;&amp;#x308A;&amp;#x51FA;&amp;#x3057;&amp;#x3066;&amp;#x3001;&amp;#x5FA9;&amp;#x5E30;&amp;#x3055;&amp;#x305B;&amp;#x308B;\n
  31. &amp;#x3084;&amp;#x3063;&amp;#x3066;&amp;#x308B;&amp;#x3053;&amp;#x3068;&amp;#x306F;&amp;#x30B3;&amp;#x30EC;&amp;#x3068;&amp;#x4F3C;&amp;#x305F;&amp;#x3088;&amp;#x3046;&amp;#x306A;&amp;#x3082;&amp;#x306E;\n
  32. &amp;#x30B3;&amp;#x30F3;&amp;#x30D1;&amp;#x30A4;&amp;#x30EB;&amp;#x306B;&amp;#x3064;&amp;#x3044;&amp;#x3066;&amp;#x306F;ExtUtils::Embed&amp;#x3092;&amp;#x5229;&amp;#x7528;&amp;#x3059;&amp;#x308C;&amp;#x3070;&amp;#x5FC5;&amp;#x8981;&amp;#x306A;&amp;#x30B3;&amp;#x30F3;&amp;#x30D1;&amp;#x30A4;&amp;#x30EB;&amp;#x30AA;&amp;#x30D7;&amp;#x30B7;&amp;#x30E7;&amp;#x30F3;&amp;#x3092;&amp;#x751F;&amp;#x6210;&amp;#x3057;&amp;#x3066;&amp;#x304F;&amp;#x308C;&amp;#x307E;&amp;#x3059;&amp;#x3002;\n&amp;#x57CB;&amp;#x3081;&amp;#x8FBC;&amp;#x307F;Perl&amp;#x3092;&amp;#x30B3;&amp;#x30F3;&amp;#x30D1;&amp;#x30A4;&amp;#x30EB;&amp;#x3059;&amp;#x308B;&amp;#x4ED6;&amp;#x306E;&amp;#x65B9;&amp;#x6CD5;&amp;#x3092;&amp;#x77E5;&amp;#x308A;&amp;#x305F;&amp;#x3044;&amp;#x5834;&amp;#x5408;&amp;#x306F;perldoc perlembed&amp;#x3092;&amp;#x898B;&amp;#x3066;&amp;#x304F;&amp;#x3060;&amp;#x3055;&amp;#x3044;\n
  33. \n
  34. &amp;#x57CB;&amp;#x3081;&amp;#x8FBC;&amp;#x307F;Perl&amp;#x3092;&amp;#x3084;&amp;#x308B;&amp;#x306B;&amp;#x3042;&amp;#x305F;&amp;#x3063;&amp;#x3066;&amp;#x3001;&amp;#x5FC5;&amp;#x8981;&amp;#x306A;&amp;#x60C5;&amp;#x5831;&amp;#x6E90;&amp;#x3067;&amp;#x3059;&amp;#x3002;\nperlembed&amp;#x306F;&amp;#x5FC5;&amp;#x8AAD;&amp;#x3068;&amp;#x3057;&amp;#x3066;&amp;#x3042;&amp;#x3068;&amp;#x306F;XS&amp;#x95A2;&amp;#x9023;&amp;#x306E;perldoc&amp;#x3092;&amp;#x8AAD;&amp;#x307F;&amp;#x307E;&amp;#x3057;&amp;#x3087;&amp;#x3046;&amp;#x3002;\n&amp;#x66F8;&amp;#x7C4D;&amp;#x3067;&amp;#x306F;&amp;#x5C11;&amp;#x3057;&amp;#x53E4;&amp;#x304F;&amp;#x3066;&amp;#x3001;&amp;#x6D0B;&amp;#x66F8;&amp;#x3067;&amp;#x3059;&amp;#x304C;Extending and Embedding Perl&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x672C;&amp;#x304C;&amp;#x3042;&amp;#x308A;&amp;#x307E;&amp;#x3059;&amp;#x3002;PDF&amp;#x7248;&amp;#x3067;&amp;#x3042;&amp;#x308C;&amp;#x3070;$36&amp;#x7A0B;&amp;#x5EA6;&amp;#x3067;&amp;#x8CB7;&amp;#x3048;&amp;#x308B;&amp;#x306F;&amp;#x305A;&amp;#x3067;&amp;#x3059;&amp;#x3002;\n
  35. &amp;#x30FB;&amp;#x57CB;&amp;#x3081;&amp;#x8FBC;&amp;#x307F;Perl&amp;#x306F;&amp;#x96E3;&amp;#x3057;&amp;#x304F;&amp;#x3042;&amp;#x308A;&amp;#x307E;&amp;#x305B;&amp;#x3093;\n&amp;#x30FB;&amp;#x3082;&amp;#x3057;&amp;#x3042;&amp;#x306A;&amp;#x305F;&amp;#x306E;C&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30E0;&amp;#x3067;Perl&amp;#x306E;&amp;#x529B;&amp;#x304C;&amp;#x5FC5;&amp;#x8981;&amp;#x306B;&amp;#x306A;&amp;#x3063;&amp;#x305F;&amp;#x3089;&amp;#x8FF7;&amp;#x308F;&amp;#x305A;&amp;#x57CB;&amp;#x3081;&amp;#x8FBC;&amp;#x307F;Perl&amp;#x306E;&amp;#x6B63;&amp;#x89E3;&amp;#x306B;&amp;#x98DB;&amp;#x3073;&amp;#x8FBC;&amp;#x307F;&amp;#x307E;&amp;#x3057;&amp;#x3087;&amp;#x3046;\n&amp;#x30FB;&amp;#x307E;&amp;#x305F;&amp;#x3001;&amp;#x57CB;&amp;#x3081;&amp;#x8FBC;&amp;#x307F;Perl&amp;#x306B;&amp;#x6311;&amp;#x6226;&amp;#x3059;&amp;#x308B;&amp;#x3053;&amp;#x3068;&amp;#x306B;&amp;#x3088;&amp;#x308A;&amp;#x3001;Perl&amp;#x306B;&amp;#x5BFE;&amp;#x3059;&amp;#x308B;&amp;#x7406;&amp;#x89E3;&amp;#x304C;&amp;#x3055;&amp;#x3089;&amp;#x306B;&amp;#x6DF1;&amp;#x307E;&amp;#x308A;&amp;#x307E;&amp;#x3059;\n
  36. &amp;#x3054;&amp;#x6E05;&amp;#x8074;&amp;#x3042;&amp;#x308A;&amp;#x304C;&amp;#x3068;&amp;#x3046;&amp;#x3054;&amp;#x3056;&amp;#x3044;&amp;#x307E;&amp;#x3057;&amp;#x305F;&amp;#x3002;\n&amp;#x4F55;&amp;#x304B;&amp;#x8CEA;&amp;#x554F;&amp;#x306F;&amp;#x3042;&amp;#x308A;&amp;#x307E;&amp;#x3059;&amp;#x3067;&amp;#x3057;&amp;#x3087;&amp;#x3046;&amp;#x304B;&amp;#xFF1F;\n