cvs: presentations / PECL_Gen.xml /slides/PECL_Gen compilation.xml compilation_1.xml compilation_2.xml extension.xml extension_tag.xml function.xml
function_2.xml invocation.xml loading.xml modes.xml parameters.xml parameters_2.xml parameters_3.xml phpinfo.xml phpinfo_2.xml testing1.xml title.xml
/slides/PECL_Gen/examples x1.configure-make x1.dl x1.install x1.log x1.php-ini x1.phpinfo x1.phpize x1.tree x1.xml x2.png x2.xml x3.php x3.result
x3.snippet x3.xml x4.php x4.result x4.snippet x4.xml
| From: | Hartmut Holzgraefe | Date: | Thu, 22 Apr 2004 16:14:32 +0000 |
| Subject: | cvs: presentations / PECL_Gen.xml /slides/PECL_Gen compilation.xml compilation_1.xml compilation_2.xml extension.xml extension_tag.xml function.xml function_2.xml invocation.xml loading.xml modes.xml parameters.xml parameters_2.xml parameters_3.xml phpinfo.xml phpinfo_2.xml testing1.xml title.xml /slides/PECL_Gen/examples x1.configure-make x1.dl x1.install x1.log x1.php-ini x1.phpinfo x1.phpize x1.tree x1.xml x2.png x2.xml x3.php x3.result x3.snippet x3.xml x4.php x4.result x4.snippet x4.xml |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-983@lists.php.net to get a copy of this message | ||
hholzgra Thu Apr 22 12:14:32 2004 EDT
Added files:
/presentations PECL_Gen.xml
/presentations/slides/PECL_Gen compilation.xml compilation_1.xml
compilation_2.xml extension.xml
extension_tag.xml function.xml
function_2.xml invocation.xml
loading.xml modes.xml parameters.xml
parameters_2.xml parameters_3.xml
phpinfo.xml phpinfo_2.xml
testing1.xml title.xml
/presentations/slides/PECL_Gen/examples x1.configure-make x1.dl
x1.install x1.log
x1.php-ini x1.phpinfo
x1.phpize x1.tree x1.xml
x2.png x2.xml x3.php
x3.result x3.snippet x3.xml
x4.php x4.result x4.snippet
x4.xml
Log:
slides for PECL_Gen talk prepared for PaWS
http://cvs.php.net/co.php/presentations/PECL_Gen.xml?r=1.1&p=1 Index: presentations/PECL_Gen.xml +++ presentations/PECL_Gen.xml <presentation> <title>PECL_Gen - a code generator for PHP extensions</title> <event>PAWS - PHP and Web Standards Conference</event> <location>Manchester</location> <date>...rescheduled...</date> <speaker>Hartmut Holzgraefe</speaker> <navmode>html</navmode> <basefontsize>12pt</basefontsize> <topic>Code Generators</topic> <logo1>images/animated_elephant.gif</logo1> <slide>slides/PECL_Gen/title.xml</slide> <slide>slides/PECL_Gen/modes.xml</slide> <slide>slides/PECL_Gen/extension_tag.xml</slide> <slide>slides/PECL_Gen/invocation.xml</slide> <slide>slides/PECL_Gen/compilation.xml</slide> <slide>slides/PECL_Gen/compilation_1.xml</slide> <slide>slides/PECL_Gen/compilation_2.xml</slide> <slide>slides/PECL_Gen/loading.xml</slide> <slide>slides/PECL_Gen/testing1.xml</slide> <slide>slides/PECL_Gen/phpinfo.xml</slide> <slide>slides/PECL_Gen/phpinfo_2.xml</slide> <slide>slides/PECL_Gen/function.xml</slide> <slide>slides/PECL_Gen/function_2.xml</slide> <slide>slides/PECL_Gen/parameters.xml</slide> <slide>slides/PECL_Gen/parameters_2.xml</slide> <slide>slides/PECL_Gen/parameters_3.xml</slide> <slide>slides/PECL_Gen/returning.xml</slide> <slide>slides/PECL_Gen/special_functions.xml</slide> <slide>slides/PECL_Gen/constants.xml</slide> <slide>slides/PECL_Gen/php_ini.xml</slide> <slide>slides/PECL_Gen/resources.xml</slide> <slide>slides/PECL_Gen/custom_code.xml</slide> <slide>slides/PECL_Gen/dependencies.xml</slide> <slide>slides/PECL_Gen/makefile_fragments.xml</slide> <slide>slides/PECL_Gen/documentation.xml</slide> <slide>slides/PECL_Gen/tests.xml</slide> <slide>slides/PECL_Gen/classes.xml</slide> <slide>slides/PECL_Gen/streams.xml</slide> <slide>slides/PECL_Gen/outlook.xml</slide> </presentation> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/compilation.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/compilation.xml +++ presentations/slides/PECL_Gen/compilation.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Compilation (Unix etc.)</title> <blurb> The generated extension contains only the bare minimum of needed files, anything else needed for configuring and bulding the extension is generated by the tool %phpize% that is part of your PHP installation: </blurb> <example filename="examples/x1.phpize" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/compilation_1.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/compilation_1.xml +++ presentations/slides/PECL_Gen/compilation_1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Compilation (Unix etc.)</title> <blurb> %phpize% generates the %configure% script and other files needed to configure and optimize the extensions build infrastructure on the target system. Next you run %configure% anf %make% (for now there are no configure options to be taken care of): </blurb> <example filename="examples/x1.configure-make" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/compilation_2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/compilation_2.xml +++ presentations/slides/PECL_Gen/compilation_2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Compilation (Unix etc.)</title> <blurb> If all went well the final step installs your new extension in the PHP extension directory so that it can be used: </blurb> <example filename="examples/x1.install" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/extension.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/extension.xml +++ presentations/slides/PECL_Gen/extension.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%<extension%gt;%</title> <list title="PECL_Gen has thre modes of operation"> <li>full extension generation from an XML spec</li> <li>single function skeleton from a prototype given on the command line</li> <li>%ext_skel% backwards compatibility</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/extension_tag.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/extension_tag.xml +++ presentations/slides/PECL_Gen/extension_tag.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;extension&gt;%</title> <blurb> The *%&lt;extension&gt;%* tag is the top level tag of every extension description. The name of the extension is specified in its *%name%* attribute. A minimal extension looks like this: </blurb> <example type="xml" linenumbers="true" filename="examples/x1.xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/function.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/function.xml +++ presentations/slides/PECL_Gen/function.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding a function</title> <blurb> A fancy %phpinfo()% is nice to have, but what PHP extensions really are about is functionality, so lets add a function to our extension: </blurb> <example filename="examples/x3.snippet" linenumbers="1" format="xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/function_2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/function_2.xml +++ presentations/slides/PECL_Gen/function_2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding a function</title> <blurb> After generating and compiling the new extension we can test it using the folling small script: </blurb> <example filename="examples/x3.php" fontsize="1em"/> <blurb> And, as expected, the result of this little script is %'foobar'% </blurb> <example filename="examples/x3.result" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/invocation.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/invocation.xml +++ presentations/slides/PECL_Gen/invocation.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Invocation</title> <blurb> Creating the actual extension source is as easy as: </blurb> <example filename="examples/x1.log" fontsize="1em"/> <blurb> This will create the following directory from *%x1.xml%*: </blurb> <example filename="examples/x1.tree" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/loading.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/loading.xml +++ presentations/slides/PECL_Gen/loading.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Loading the Extension</title> <blurb> You have now successfully created your new PHP shared extension. To activate it you have to load the extension into PHP. </blurb> <blurb> To load the extension at startup so that it is always available with PHP you have to add an %extension% directive to your %php.ini% file: </blurb> <example filename="examples/x1.php-ini" fontsize="1em"/> <blurb> To load the extension at runtime only where it is really needed you may use PHPs %dl()% function: </blurb> <example filename="examples/x1.dl" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/modes.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/modes.xml +++ presentations/slides/PECL_Gen/modes.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Modes of Operation</title> <list title="PECL_Gen has three modes of operation"> <li>full extension generation from an XML spec</li> <li>single function skeleton from a prototype given on the command line</li> <li>%ext_skel% backwards compatibility</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/parameters.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/parameters.xml +++ presentations/slides/PECL_Gen/parameters.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Function parameters</title> <blurb> Lets add some parameters to our function: </blurb> <example filename="examples/x4.snippet" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/parameters_2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/parameters_2.xml +++ presentations/slides/PECL_Gen/parameters_2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Function parameters</title> <blurb> Now our test script looks like this: </blurb> <example filename="examples/x4.php" fontsize="1em"/> <blurb> And its result is: </blurb> <example filename="examples/x4.result" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/parameters_3.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/parameters_3.xml +++ presentations/slides/PECL_Gen/parameters_3.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Function parameters</title> <blurb> *How does it work?* </blurb> <blurb> For each parameter in your functions prototype there will be a local C variable of the same name and an appropriate type. </blurb> <blurb> For %string% parameters the actual string length is storen in an additional %int% variable that is named like the parameter but with an additional %'_len'% suffix. </blurb> <blurb> The mapping from PHP to C variable types is as follows: <![CDATA[ <table> <tr><th>PHP type</th><th>C type</th></tr> <tr><td><b><tt>bool</tt></b></td><td><tt>zend_bool</tt></td></tr> <tr><td><b><tt>int</tt></b></td><td><tt>long</tt></td></tr> <tr><td><b><tt>float</tt></b></td><td><tt>double</tt></td></tr> <tr><td><b><tt>string</tt></b></td><td><tt>char *</tt></td></tr> <tr><td><b><tt>array</tt></b></td><td><tt>zval *</tt></td></tr> <tr><td><b><tt>object</tt></b></td><td><tt>zval *</tt></td></tr> <tr><td><b><tt>resource</tt></b></td><td><tt>zval *</tt></td></tr> <tr><td><b><tt>callback</tt></b></td><td><tt>zval *</tt></td></tr> <tr><td><b><tt>mixed</tt></b></td><td><tt>zval *</tt></td></tr> </table> ]]> </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/phpinfo.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/phpinfo.xml +++ presentations/slides/PECL_Gen/phpinfo.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>A fancy %phpinfo()%</title> <blurb> Lets start by adding some more stuff to our %phpinfo()% entry: </blurb> <example filename="examples/x2.xml" linenumbers="1" type="xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/phpinfo_2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/phpinfo_2.xml +++ presentations/slides/PECL_Gen/phpinfo_2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>A fancy %phpinfo()%</title> <blurb> Now our %phpinfo()% entry looks like this: <![CDATA[ <hr> <h3 style="text-align: center;">x2</h3> <table align="center" border="0" cellpadding="3" width="600" style="border-collapse: collapse;"> <tr style="background-color: #cccccc; color: #000000;"><td style="border: 1px solid #000000; font-size: 75%; vertical-align: baseline;"> <img src='/~hartmut/phpinfo.php?=X2_LOGO_ID' align='right' alt='image' border='0'> <p>My first Extension</p> <p>Version 0.1alpha (2002-02-28)</p> <p><b>Authors:</b></p> <p>Hartmut Holzgraefe <hartmut@php.net></p> </td></tr> </table><br /> ]]> </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/testing1.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/testing1.xml +++ presentations/slides/PECL_Gen/testing1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Testing the Extension</title> <blurb> Even without having specified anything but the extensions name we now already have: </blurb> <list> <li>a ready-to-compile source tree</li> <li>a loadable extension module</li> <li>a %phpinfo()% entry</li> </list> <example filename="examples/x1.phpinfo" fontsize="1em"/> <blurb> Nothing really usefull but not too bad for less than five minutes of work. </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/title.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/title.xml +++ presentations/slides/PECL_Gen/title.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>PECL_GEN</title> <list title="PECL_Gen is"> <li>an XML based PHP extension code generator</li> <li>replacing the older %ext_skel% script</li> <li>implemented using PHP 5 and PEAR only</li> </list> <list title="PECL_Gen creates"> <li>functions</li> <li>constants</li> <li>%php.ini% configuration directives</li> <li>resource types</li> <li>per thread global variables</li> <li>%configure%, %Makefile% and VisualStudio project files</li> <li>documentation</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.configure-make?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.configure-make +++ presentations/slides/PECL_Gen/examples/x1.configure-make $ configure $ make http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.dl?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.dl +++ presentations/slides/PECL_Gen/examples/x1.dl <?php dl("x1.so"); ... ?> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.install?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.install +++ presentations/slides/PECL_Gen/examples/x1.install $ sudo make install http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.log?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.log +++ presentations/slides/PECL_Gen/examples/x1.log $ pecl-gen x1.xml Creating 'x1' extension in '/home/hartmut/projects/x1' Your extension has been created in directory x1. See x1/README for further instructions. http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.php-ini?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.php-ini +++ presentations/slides/PECL_Gen/examples/x1.php-ini ... extension=x1.so ... http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.phpinfo?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.phpinfo +++ presentations/slides/PECL_Gen/examples/x1.phpinfo x1 The unknown extension Version 0.0.7unkown (2004-02-16) http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.phpize?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.phpize +++ presentations/slides/PECL_Gen/examples/x1.phpize $ cd x1 $ phpize http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.tree?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.tree +++ presentations/slides/PECL_Gen/examples/x1.tree x1 |-- EXPERIMENTAL |-- README |-- config.m4 |-- manual | `-- x1 | |-- configure.xml | |-- functions | `-- reference.xml |-- package.xml |-- php_x1.h |-- tests |-- x1.c `-- x1.dsp http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.xml +++ presentations/slides/PECL_Gen/examples/x1.xml <?xml version="1.0"?> <extension name="x1"/> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x2.xml +++ presentations/slides/PECL_Gen/examples/x2.xml <?xml version="1.0"?> <extension name="x2"> <summary>My first Extension</summary> <logo src='x2.png' mimetype='image/png'/> <maintainers> <maintainer> <user>hholzgra</user> <name>Hartmut Holzgraefe</name> <email>hartmut@php.net</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1</version> <date>2002-02-28</date> <state>alpha</state> <license>php</license> <notes> - first experimental draft </notes> </release> </extension> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x3.php?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x3.php +++ presentations/slides/PECL_Gen/examples/x3.php <?php // x3.php dl("x3.so"); echo foobar(); ?> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x3.result?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x3.result +++ presentations/slides/PECL_Gen/examples/x3.result $ php x3.php foobar http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x3.snippet?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x3.snippet +++ presentations/slides/PECL_Gen/examples/x3.snippet <extension name="x3"> [...] <functions> <function name="foobar"> <proto>string foobar(void)</proto> <summary>A dummy function</summary> <description> This function returns a static string. </description> <code> RETURN_STRING("foobar", 1); </code> </function> </functions> [...] </extension> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x3.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x3.xml +++ presentations/slides/PECL_Gen/examples/x3.xml <?xml version="1.0"?> <extension name="x3"> <summary>My first Extension</summary> <logo src='x2.png' mimetype='image/png'/> <release> <version>0.1</version> <date>2002-02-28</date> <state>alpha</state> <license>php</license> <notes> - first experimental draft </notes> </release> <deps language="cpp"/> <functions> <function name="foobar"> <proto>string foobar(void)</proto> <summary>A dummy function</summary> <description> This function returns a static string. </description> <code> RETURN_STRING("foobar", 1); </code> </function> </functions> </extension> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x4.php?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x4.php +++ presentations/slides/PECL_Gen/examples/x4.php <?php // x4.php dl("x4.so"); echo foobar("Go! ", 3); ?> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x4.result?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x4.result +++ presentations/slides/PECL_Gen/examples/x4.result $ php x4.php Go! Go! Go! http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x4.snippet?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x4.snippet +++ presentations/slides/PECL_Gen/examples/x4.snippet <functions> <function name="foobar"> <proto>string foobar(string foo, int bar)</proto> <summary>A dummy function</summary> <description> This function returns a given string 'foo' 'bar' times. </description> <code> <![CDATA[ int i, len; char *newstr; len = foo_len * bar; newstr = (char *)emalloc(len + 1); *newstr = '\0'; for (i=0; i<bar; i++) { strcat(newstr, foo); } RETURN_STRINGL(newstr, len, 0); ]]> </code> </function> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x4.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x4.xml +++ presentations/slides/PECL_Gen/examples/x4.xml <?xml version="1.0"?> <extension name="x4"> <summary>My first Extension</summary> <logo src='x2.png' mimetype='image/png'/> <release> <version>0.1</version> <date>2002-02-28</date> <state>alpha</state> <license>php</license> <notes> - first experimental draft </notes> </release> <deps language="cpp"/> <functions> <function name="foobar"> <proto>string foobar(string foo, int bar)</proto> <summary>A dummy function</summary> <description> This function returns a given string 'foo' 'bar' times. </description> <code> <![CDATA[ int i, len; char *newstr; len = foo_len * bar; newstr = (char *)emalloc(len + 1); *newstr = '\0'; for (i=0; i<bar; i++) { strcat(newstr, foo); } RETURN_STRINGL(newstr, len, 0); ]]> </code> </function> </functions> </extension>
http://cvs.php.net/co.php/presentations/PECL_Gen.xml?r=1.1&p=1 Index: presentations/PECL_Gen.xml +++ presentations/PECL_Gen.xml <presentation> <title>PECL_Gen - a code generator for PHP extensions</title> <event>PAWS - PHP and Web Standards Conference</event> <location>Manchester</location> <date>...rescheduled...</date> <speaker>Hartmut Holzgraefe</speaker> <navmode>html</navmode> <basefontsize>12pt</basefontsize> <topic>Code Generators</topic> <logo1>images/animated_elephant.gif</logo1> <slide>slides/PECL_Gen/title.xml</slide> <slide>slides/PECL_Gen/modes.xml</slide> <slide>slides/PECL_Gen/extension_tag.xml</slide> <slide>slides/PECL_Gen/invocation.xml</slide> <slide>slides/PECL_Gen/compilation.xml</slide> <slide>slides/PECL_Gen/compilation_1.xml</slide> <slide>slides/PECL_Gen/compilation_2.xml</slide> <slide>slides/PECL_Gen/loading.xml</slide> <slide>slides/PECL_Gen/testing1.xml</slide> <slide>slides/PECL_Gen/phpinfo.xml</slide> <slide>slides/PECL_Gen/phpinfo_2.xml</slide> <slide>slides/PECL_Gen/function.xml</slide> <slide>slides/PECL_Gen/function_2.xml</slide> <slide>slides/PECL_Gen/parameters.xml</slide> <slide>slides/PECL_Gen/parameters_2.xml</slide> <slide>slides/PECL_Gen/parameters_3.xml</slide> <slide>slides/PECL_Gen/returning.xml</slide> <slide>slides/PECL_Gen/special_functions.xml</slide> <slide>slides/PECL_Gen/constants.xml</slide> <slide>slides/PECL_Gen/php_ini.xml</slide> <slide>slides/PECL_Gen/resources.xml</slide> <slide>slides/PECL_Gen/custom_code.xml</slide> <slide>slides/PECL_Gen/dependencies.xml</slide> <slide>slides/PECL_Gen/makefile_fragments.xml</slide> <slide>slides/PECL_Gen/documentation.xml</slide> <slide>slides/PECL_Gen/tests.xml</slide> <slide>slides/PECL_Gen/classes.xml</slide> <slide>slides/PECL_Gen/streams.xml</slide> <slide>slides/PECL_Gen/outlook.xml</slide> </presentation> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/compilation.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/compilation.xml +++ presentations/slides/PECL_Gen/compilation.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Compilation (Unix etc.)</title> <blurb> The generated extension contains only the bare minimum of needed files, anything else needed for configuring and bulding the extension is generated by the tool %phpize% that is part of your PHP installation: </blurb> <example filename="examples/x1.phpize" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/compilation_1.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/compilation_1.xml +++ presentations/slides/PECL_Gen/compilation_1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Compilation (Unix etc.)</title> <blurb> %phpize% generates the %configure% script and other files needed to configure and optimize the extensions build infrastructure on the target system. Next you run %configure% anf %make% (for now there are no configure options to be taken care of): </blurb> <example filename="examples/x1.configure-make" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/compilation_2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/compilation_2.xml +++ presentations/slides/PECL_Gen/compilation_2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Compilation (Unix etc.)</title> <blurb> If all went well the final step installs your new extension in the PHP extension directory so that it can be used: </blurb> <example filename="examples/x1.install" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/extension.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/extension.xml +++ presentations/slides/PECL_Gen/extension.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%<extension%gt;%</title> <list title="PECL_Gen has thre modes of operation"> <li>full extension generation from an XML spec</li> <li>single function skeleton from a prototype given on the command line</li> <li>%ext_skel% backwards compatibility</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/extension_tag.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/extension_tag.xml +++ presentations/slides/PECL_Gen/extension_tag.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;extension&gt;%</title> <blurb> The *%&lt;extension&gt;%* tag is the top level tag of every extension description. The name of the extension is specified in its *%name%* attribute. A minimal extension looks like this: </blurb> <example type="xml" linenumbers="true" filename="examples/x1.xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/function.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/function.xml +++ presentations/slides/PECL_Gen/function.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding a function</title> <blurb> A fancy %phpinfo()% is nice to have, but what PHP extensions really are about is functionality, so lets add a function to our extension: </blurb> <example filename="examples/x3.snippet" linenumbers="1" format="xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/function_2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/function_2.xml +++ presentations/slides/PECL_Gen/function_2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding a function</title> <blurb> After generating and compiling the new extension we can test it using the folling small script: </blurb> <example filename="examples/x3.php" fontsize="1em"/> <blurb> And, as expected, the result of this little script is %'foobar'% </blurb> <example filename="examples/x3.result" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/invocation.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/invocation.xml +++ presentations/slides/PECL_Gen/invocation.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Invocation</title> <blurb> Creating the actual extension source is as easy as: </blurb> <example filename="examples/x1.log" fontsize="1em"/> <blurb> This will create the following directory from *%x1.xml%*: </blurb> <example filename="examples/x1.tree" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/loading.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/loading.xml +++ presentations/slides/PECL_Gen/loading.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Loading the Extension</title> <blurb> You have now successfully created your new PHP shared extension. To activate it you have to load the extension into PHP. </blurb> <blurb> To load the extension at startup so that it is always available with PHP you have to add an %extension% directive to your %php.ini% file: </blurb> <example filename="examples/x1.php-ini" fontsize="1em"/> <blurb> To load the extension at runtime only where it is really needed you may use PHPs %dl()% function: </blurb> <example filename="examples/x1.dl" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/modes.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/modes.xml +++ presentations/slides/PECL_Gen/modes.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Modes of Operation</title> <list title="PECL_Gen has three modes of operation"> <li>full extension generation from an XML spec</li> <li>single function skeleton from a prototype given on the command line</li> <li>%ext_skel% backwards compatibility</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/parameters.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/parameters.xml +++ presentations/slides/PECL_Gen/parameters.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Function parameters</title> <blurb> Lets add some parameters to our function: </blurb> <example filename="examples/x4.snippet" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/parameters_2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/parameters_2.xml +++ presentations/slides/PECL_Gen/parameters_2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Function parameters</title> <blurb> Now our test script looks like this: </blurb> <example filename="examples/x4.php" fontsize="1em"/> <blurb> And its result is: </blurb> <example filename="examples/x4.result" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/parameters_3.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/parameters_3.xml +++ presentations/slides/PECL_Gen/parameters_3.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Function parameters</title> <blurb> *How does it work?* </blurb> <blurb> For each parameter in your functions prototype there will be a local C variable of the same name and an appropriate type. </blurb> <blurb> For %string% parameters the actual string length is storen in an additional %int% variable that is named like the parameter but with an additional %'_len'% suffix. </blurb> <blurb> The mapping from PHP to C variable types is as follows: <![CDATA[ <table> <tr><th>PHP type</th><th>C type</th></tr> <tr><td><b><tt>bool</tt></b></td><td><tt>zend_bool</tt></td></tr> <tr><td><b><tt>int</tt></b></td><td><tt>long</tt></td></tr> <tr><td><b><tt>float</tt></b></td><td><tt>double</tt></td></tr> <tr><td><b><tt>string</tt></b></td><td><tt>char *</tt></td></tr> <tr><td><b><tt>array</tt></b></td><td><tt>zval *</tt></td></tr> <tr><td><b><tt>object</tt></b></td><td><tt>zval *</tt></td></tr> <tr><td><b><tt>resource</tt></b></td><td><tt>zval *</tt></td></tr> <tr><td><b><tt>callback</tt></b></td><td><tt>zval *</tt></td></tr> <tr><td><b><tt>mixed</tt></b></td><td><tt>zval *</tt></td></tr> </table> ]]> </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/phpinfo.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/phpinfo.xml +++ presentations/slides/PECL_Gen/phpinfo.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>A fancy %phpinfo()%</title> <blurb> Lets start by adding some more stuff to our %phpinfo()% entry: </blurb> <example filename="examples/x2.xml" linenumbers="1" type="xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/phpinfo_2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/phpinfo_2.xml +++ presentations/slides/PECL_Gen/phpinfo_2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>A fancy %phpinfo()%</title> <blurb> Now our %phpinfo()% entry looks like this: <![CDATA[ <hr> <h3 style="text-align: center;">x2</h3> <table align="center" border="0" cellpadding="3" width="600" style="border-collapse: collapse;"> <tr style="background-color: #cccccc; color: #000000;"><td style="border: 1px solid #000000; font-size: 75%; vertical-align: baseline;"> <img src='/~hartmut/phpinfo.php?=X2_LOGO_ID' align='right' alt='image' border='0'> <p>My first Extension</p> <p>Version 0.1alpha (2002-02-28)</p> <p><b>Authors:</b></p> <p>Hartmut Holzgraefe <hartmut@php.net></p> </td></tr> </table><br /> ]]> </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/testing1.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/testing1.xml +++ presentations/slides/PECL_Gen/testing1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Testing the Extension</title> <blurb> Even without having specified anything but the extensions name we now already have: </blurb> <list> <li>a ready-to-compile source tree</li> <li>a loadable extension module</li> <li>a %phpinfo()% entry</li> </list> <example filename="examples/x1.phpinfo" fontsize="1em"/> <blurb> Nothing really usefull but not too bad for less than five minutes of work. </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/title.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/title.xml +++ presentations/slides/PECL_Gen/title.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>PECL_GEN</title> <list title="PECL_Gen is"> <li>an XML based PHP extension code generator</li> <li>replacing the older %ext_skel% script</li> <li>implemented using PHP 5 and PEAR only</li> </list> <list title="PECL_Gen creates"> <li>functions</li> <li>constants</li> <li>%php.ini% configuration directives</li> <li>resource types</li> <li>per thread global variables</li> <li>%configure%, %Makefile% and VisualStudio project files</li> <li>documentation</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.configure-make?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.configure-make +++ presentations/slides/PECL_Gen/examples/x1.configure-make $ configure $ make http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.dl?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.dl +++ presentations/slides/PECL_Gen/examples/x1.dl <?php dl("x1.so"); ... ?> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.install?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.install +++ presentations/slides/PECL_Gen/examples/x1.install $ sudo make install http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.log?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.log +++ presentations/slides/PECL_Gen/examples/x1.log $ pecl-gen x1.xml Creating 'x1' extension in '/home/hartmut/projects/x1' Your extension has been created in directory x1. See x1/README for further instructions. http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.php-ini?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.php-ini +++ presentations/slides/PECL_Gen/examples/x1.php-ini ... extension=x1.so ... http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.phpinfo?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.phpinfo +++ presentations/slides/PECL_Gen/examples/x1.phpinfo x1 The unknown extension Version 0.0.7unkown (2004-02-16) http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.phpize?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.phpize +++ presentations/slides/PECL_Gen/examples/x1.phpize $ cd x1 $ phpize http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.tree?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.tree +++ presentations/slides/PECL_Gen/examples/x1.tree x1 |-- EXPERIMENTAL |-- README |-- config.m4 |-- manual | `-- x1 | |-- configure.xml | |-- functions | `-- reference.xml |-- package.xml |-- php_x1.h |-- tests |-- x1.c `-- x1.dsp http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x1.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x1.xml +++ presentations/slides/PECL_Gen/examples/x1.xml <?xml version="1.0"?> <extension name="x1"/> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x2.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x2.xml +++ presentations/slides/PECL_Gen/examples/x2.xml <?xml version="1.0"?> <extension name="x2"> <summary>My first Extension</summary> <logo src='x2.png' mimetype='image/png'/> <maintainers> <maintainer> <user>hholzgra</user> <name>Hartmut Holzgraefe</name> <email>hartmut@php.net</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1</version> <date>2002-02-28</date> <state>alpha</state> <license>php</license> <notes> - first experimental draft </notes> </release> </extension> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x3.php?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x3.php +++ presentations/slides/PECL_Gen/examples/x3.php <?php // x3.php dl("x3.so"); echo foobar(); ?> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x3.result?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x3.result +++ presentations/slides/PECL_Gen/examples/x3.result $ php x3.php foobar http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x3.snippet?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x3.snippet +++ presentations/slides/PECL_Gen/examples/x3.snippet <extension name="x3"> [...] <functions> <function name="foobar"> <proto>string foobar(void)</proto> <summary>A dummy function</summary> <description> This function returns a static string. </description> <code> RETURN_STRING("foobar", 1); </code> </function> </functions> [...] </extension> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x3.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x3.xml +++ presentations/slides/PECL_Gen/examples/x3.xml <?xml version="1.0"?> <extension name="x3"> <summary>My first Extension</summary> <logo src='x2.png' mimetype='image/png'/> <release> <version>0.1</version> <date>2002-02-28</date> <state>alpha</state> <license>php</license> <notes> - first experimental draft </notes> </release> <deps language="cpp"/> <functions> <function name="foobar"> <proto>string foobar(void)</proto> <summary>A dummy function</summary> <description> This function returns a static string. </description> <code> RETURN_STRING("foobar", 1); </code> </function> </functions> </extension> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x4.php?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x4.php +++ presentations/slides/PECL_Gen/examples/x4.php <?php // x4.php dl("x4.so"); echo foobar("Go! ", 3); ?> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x4.result?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x4.result +++ presentations/slides/PECL_Gen/examples/x4.result $ php x4.php Go! Go! Go! http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x4.snippet?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x4.snippet +++ presentations/slides/PECL_Gen/examples/x4.snippet <functions> <function name="foobar"> <proto>string foobar(string foo, int bar)</proto> <summary>A dummy function</summary> <description> This function returns a given string 'foo' 'bar' times. </description> <code> <![CDATA[ int i, len; char *newstr; len = foo_len * bar; newstr = (char *)emalloc(len + 1); *newstr = '\0'; for (i=0; i<bar; i++) { strcat(newstr, foo); } RETURN_STRINGL(newstr, len, 0); ]]> </code> </function> http://cvs.php.net/co.php/presentations/slides/PECL_Gen/examples/x4.xml?r=1.1&p=1 Index: presentations/slides/PECL_Gen/examples/x4.xml +++ presentations/slides/PECL_Gen/examples/x4.xml <?xml version="1.0"?> <extension name="x4"> <summary>My first Extension</summary> <logo src='x2.png' mimetype='image/png'/> <release> <version>0.1</version> <date>2002-02-28</date> <state>alpha</state> <license>php</license> <notes> - first experimental draft </notes> </release> <deps language="cpp"/> <functions> <function name="foobar"> <proto>string foobar(string foo, int bar)</proto> <summary>A dummy function</summary> <description> This function returns a given string 'foo' 'bar' times. </description> <code> <![CDATA[ int i, len; char *newstr; len = foo_len * bar; newstr = (char *)emalloc(len + 1); *newstr = '\0'; for (i=0; i<bar; i++) { strcat(newstr, foo); } RETURN_STRINGL(newstr, len, 0); ]]> </code> </function> </functions> </extension>