cvs: presentations / UDF_Gen.xml /slides/UDF_Gen adding_code.xml adding_files.xml aggregate.xml compilation.xml compilation_1.xml compilation_2.xml
extension_tag.xml function.xml function_2.xml installation.xml invocation.xml loading.xml modes.xml mysql_2004.png parameters.xml parameters_2.xml
parameters_3.xml phpinfo.xml phpinfo_2.xml return_values.xml tag_code.xml tag_data.xml tag_function.xml tag_parameter.xml testing1.xml title.xml
whats_next.xml why.xml /slides/UDF_Gen/examples dep_file.xml install.sh phpize return_result.c tag_code.xml 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.create x3.php x3.result x3.snippet x3.txt x3.xml x4.php x4.result x4.snippet x4.xml
| From: | Hartmut Holzgraefe | Date: | Thu, 22 Apr 2004 14:08:53 +0000 |
| Subject: | cvs: presentations / UDF_Gen.xml /slides/UDF_Gen adding_code.xml adding_files.xml aggregate.xml compilation.xml compilation_1.xml compilation_2.xml extension_tag.xml function.xml function_2.xml installation.xml invocation.xml loading.xml modes.xml mysql_2004.png parameters.xml parameters_2.xml parameters_3.xml phpinfo.xml phpinfo_2.xml return_values.xml tag_code.xml tag_data.xml tag_function.xml tag_parameter.xml testing1.xml title.xml whats_next.xml why.xml /slides/UDF_Gen/examples dep_file.xml install.sh phpize return_result.c tag_code.xml 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.create x3.php x3.result x3.snippet x3.txt x3.xml x4.php x4.result x4.snippet x4.xml |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-982@lists.php.net to get a copy of this message | ||
hholzgra Thu Apr 22 10:08:53 2004 EDT
Added files:
/presentations UDF_Gen.xml
/presentations/slides/UDF_Gen adding_code.xml adding_files.xml
aggregate.xml compilation.xml
compilation_1.xml compilation_2.xml
extension_tag.xml function.xml
function_2.xml installation.xml
invocation.xml loading.xml modes.xml
mysql_2004.png parameters.xml
parameters_2.xml parameters_3.xml
phpinfo.xml phpinfo_2.xml
return_values.xml tag_code.xml
tag_data.xml tag_function.xml
tag_parameter.xml testing1.xml
title.xml whats_next.xml why.xml
/presentations/slides/UDF_Gen/examples dep_file.xml install.sh
phpize return_result.c
tag_code.xml
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.create x3.php x3.result
x3.snippet x3.txt x3.xml
x4.php x4.result x4.snippet
x4.xml
Log:
UDF_Gen - MySQL user defined function code generator based on PECL_Gen
http://cvs.php.net/co.php/presentations/UDF_Gen.xml?r=1.1&p=1 Index: presentations/UDF_Gen.xml +++ presentations/UDF_Gen.xml <presentation navbarbackground="#DAE6EA"> <title>UDF_Gen - a code generator for Mysql UDFs</title> <event>FOSDEM 2004</event> <location>Brussels</location> <date>Februrary 20 2004</date> <speaker>Hartmut Holzgraefe</speaker> <navmode>html</navmode> <basefontsize>12pt</basefontsize> <topic>Code Generators</topic> <logo1>presentations/slides/UDF_Gen/mysql_2004.png</logo1> <slide>slides/UDF_Gen/why.xml</slide> <slide>slides/UDF_Gen/title.xml</slide> <slide>slides/UDF_Gen/installation.xml</slide> <slide>slides/UDF_Gen/extension_tag.xml</slide> <slide>slides/UDF_Gen/invocation.xml</slide> <slide>slides/UDF_Gen/compilation.xml</slide> <slide>slides/UDF_Gen/function.xml</slide> <slide>slides/UDF_Gen/loading.xml</slide> <slide>slides/UDF_Gen/aggregate.xml</slide> <slide>slides/UDF_Gen/tag_function.xml</slide> <slide>slides/UDF_Gen/tag_parameter.xml</slide> <slide>slides/UDF_Gen/tag_code.xml</slide> <slide>slides/UDF_Gen/return_values.xml</slide> <slide>slides/UDF_Gen/tag_data.xml</slide> <slide>slides/UDF_Gen/adding_code.xml</slide> <slide>slides/UDF_Gen/adding_files.xml</slide> <slide>slides/UDF_Gen/whats_next.xml</slide> </presentation> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/adding_code.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/adding_code.xml +++ presentations/slides/UDF_Gen/adding_code.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>adding custom code</title> <blurb> Custom C code may be added using *%&lt;code&gt;%* sections outside of *%&lt;function&gt;%* declarations at any time. </blurb> <blurb> If the *role* attribute is set to '*header*' the code will be inserted right after the default %#include% statements, else it will be appended after any automatically generated code. </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/adding_files.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/adding_files.xml +++ presentations/slides/UDF_Gen/adding_files.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>adding files</title> <blurb> Additional code files may be specified within the *%&lt;deps&gt;%* section. </blurb> <example type="xml" linenumbers="true" filename="examples/dep_file.xml" fontsize="1em"/> <blurb> These files are copied to the newly created source directory and added to the *%Makefile%*s list of source files for the UDF shared object. </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/aggregate.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/aggregate.xml +++ presentations/slides/UDF_Gen/aggregate.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding an aggregate function</title> <blurb> Adding an aggregate function requires some additional effort as an aggregate function on the SQL level is actually implemented by a small family of C functions and private data passed between them. </blurb> <blurb> Aggregate private data is declared using the &lt;data&gt; tag. For each aggregate group it is initialized by the code given in &lt;clear&gt;. For each row of the group the &lt;add&gt; code is executed, receiving the declared &lt;parameter&gt;s just like a normal function. Finally the &lt;result&gt; code is executed and expected to pass the functions. </blurb> <blurb> See the following example for a simple reimplementation of the standard AVG() function: </blurb> <example filename="examples/x4.xml" linenumbers="1" format="xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/compilation.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/compilation.xml +++ presentations/slides/UDF_Gen/compilation.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Compilation</title> <blurb> The generated extension directory already contains a ready to use %configure% file, so compilation is as usual. </blurb> <blurb> The only step you need to perform manually right now is putting the generated %x1.so% extension file to a library directory where the mysql server can find it. </blurb> <example filename="examples/x1.phpize" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/compilation_1.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/compilation_1.xml +++ presentations/slides/UDF_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/UDF_Gen/compilation_2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/compilation_2.xml +++ presentations/slides/UDF_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/UDF_Gen/extension_tag.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/extension_tag.xml +++ presentations/slides/UDF_Gen/extension_tag.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;udf&gt;%</title> <blurb> An UDF_Gen description file specifies anything down to the actual function code (including parameter passing) in a rather simple XML format. </blurb> <blurb> While implementing an UDF one no longer needs to implement all the boring repetitive interface stuff but can start with the actual functionality right away. </blurb> <blurb> The *%&lt;udf&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/UDF_Gen/function.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/function.xml +++ presentations/slides/UDF_Gen/function.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding a function</title> <blurb> Lets add a simple function to the extension so that we can really use it: </blurb> <example filename="examples/x3.xml" linenumbers="1" format="xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/function_2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/function_2.xml +++ presentations/slides/UDF_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/UDF_Gen/installation.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/installation.xml +++ presentations/slides/UDF_Gen/installation.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Installation</title> <blurb> UDF requires %PHP5% and %PECL_Gen% from the %PECL% repository. UDF_Gen itself is not (yet?) part of %PECL% but available independently at %http://www.php-groupies.de/php/UDF_Gen-0.2.0.tgz% </blurb> <blurb> %PECL_Gen% and %UDF_Gen% are both installed using the %PECL% installer </blurb> <example filename="examples/install.sh" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/invocation.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/invocation.xml +++ presentations/slides/UDF_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/UDF_Gen/loading.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/loading.xml +++ presentations/slides/UDF_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 UDF shared extension. To activate it you have to load the extension into a mysql server. This is done using %CREATE FUNCTION ...% </blurb> <blurb> When you open the generated code file %x3.cpp% you'll see a comment block at the top showing the %CREATE% statements needed to install all functions provided by this extension. </blurb> <example filename="examples/x3.create" fontsize="1em"/> <example filename="examples/x3.txt" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/modes.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/modes.xml +++ presentations/slides/UDF_Gen/modes.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Modes of Operation</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/UDF_Gen/parameters.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/parameters.xml +++ presentations/slides/UDF_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/UDF_Gen/parameters_2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/parameters_2.xml +++ presentations/slides/UDF_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/UDF_Gen/parameters_3.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/parameters_3.xml +++ presentations/slides/UDF_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/UDF_Gen/phpinfo.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/phpinfo.xml +++ presentations/slides/UDF_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/UDF_Gen/phpinfo_2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/phpinfo_2.xml +++ presentations/slides/UDF_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/UDF_Gen/return_values.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/return_values.xml +++ presentations/slides/UDF_Gen/return_values.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>returning results</title> <blurb> For now there is no special support for returning values although it may be added at a later version. </blurb> <blurb> To return an *int* or *real* result you just use a plain C return statement with the appropriate return value. </blurb> <blurb> To return a *%NULL%* value from any function you have to set the variable pointed to by the *%is_null%* function parameter to *1*. </blurb> <blurb> For strings up to 255 characters long you have to copy the string to the location pointed to by the *%result%* paramter and store its length in the varibale pointed to by the *%length%* parameter. Returning longer strings requires memory allocation within the UDF and is not yet supported. </blurb> <blurb> *%datetime*% values need to be returned as strings for now. </blurb> <example type="xml" linenumbers="true" filename="examples/return_result.c" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/tag_code.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/tag_code.xml +++ presentations/slides/UDF_Gen/tag_code.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;code&gt;%</title> <blurb> The actual function code is put into %&lt;code&gt;% tags. </blurb> <blurb> XML encoding the code can be avoided using %&lt;![CDATA ... ]]&gt;% sections. </blurb> <example type="xml" linenumbers="true" filename="examples/tag_code.xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/tag_data.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/tag_data.xml +++ presentations/slides/UDF_Gen/tag_data.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;data&gt;%</title> <blurb> Aggregate UDF related stuff ... to be done ... </blurb> <example type="xml" linenumbers="true" filename="examples/tag_data.xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/tag_function.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/tag_function.xml +++ presentations/slides/UDF_Gen/tag_function.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;function&gt;%</title> <blurb> The *%&lt;function&gt;%* tag is used to define both normal and aggregate functions. Name, type and returned data type have to be specified using attributes. </blurb> <list> <li>*name* - function name</li> <li>*type* - either *normal* (default) or *aggregate*</li> <li>*null* - *true* if function may return *NULL*, else *false* (default)</li> <li>*returns* - return type: *string*, *int*, *real* or *datetime*</li> <li>*length* - for *real* and *integer*</li> <li>*decimals* - for *real*</li> </list> <blurb> Function parameters are defined using the *%&lt;parameter&gt;%* tag. </blurb> <blurb> Data private to a function is declared within the *%&lt;data&gt;%* tag. </blurb> <blurb> The *%&lt;code&gt;%* tag takes the code for normal functions, aggregate function code is put into the *%&lt;clear&gt;%*, *%&lt;add&gt;%* and *%&lt;result&gt;%* tags </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/tag_parameter.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/tag_parameter.xml +++ presentations/slides/UDF_Gen/tag_parameter.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;parameter&gt;%</title> <blurb> The *%&lt;parameter&gt;%* tag defines function parameter names and types using the *name* and *type* attributes: </blurb> <list> <li>*name* - parameter name</li> <li>*type* - *string*, *int*, *real* or *datetime*</li> </list> <blurb> Code to check the parameter count and types is generated automatically. </blurb> <blurb> Local C variables are created that take the parameter value and optional information. For a parameter named *foobar* the following variables are created: </blurb> <list> <li> *foobar* - takes the parameter value. Depending on the parameter type this is either a *double*, *long long*, *char&#42;* or *time_t* </li> <li> *foobar_is_null* - for *int*, *real* and *datetime* this indicates whether a *NULL* value was passed (for *string* types *foobar* itself is a NULL pointer) </li> <li> *foobar_len* - for *string* this contains the actual string length </li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/testing1.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/testing1.xml +++ presentations/slides/UDF_Gen/testing1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>What else is possible?</title> <list> <li>other argument types (string, double, date, ...)</li> <li>adding source file to the project (including e.g. flex/bison code)</li> <li>...</li> </list> <blurb> See %ora_funcs.xml% as a reference example that implements most standard Oracle SQL functions not available in plain SQL. </blurb> <blurb> It includes stuff like all implemented parameter types and incorprates a %flex% code file for %TO_CHAR% argument parsing. </blurb> <blurb> ... </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/title.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/title.xml +++ presentations/slides/UDF_Gen/title.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>UDF_GEN</title> <list title="UDF_Gen is"> <li>an XML based UDF function code generator</li> <li>based on the PECL_Gen PHP extension code generator</li> <li>implemented using PHP 5 and PEAR only</li> </list> <list title="UDF_Gen creates"> <li>functions</li> <li>%configure% and %Makefile% infrastructure</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/whats_next.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/whats_next.xml +++ presentations/slides/UDF_Gen/whats_next.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Whats next?</title> <blurb> See %ora_funcs.xml% in the UDF_Gen tar archive for a working example that uses all currently supported features of UDF_Gen. </blurb> <blurb> Additional features will be added soon, especially: </blurb> <list> <li>library and header file detection for %configure%</li> <li>improved support for returning data</li> <li>constant and optional parameter support</li> <li>documentation stub generation</li> <li>maybe test case generation</li> <li>...</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/why.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/why.xml +++ presentations/slides/UDF_Gen/why.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>UDF</title> <list title="User Defined Functions"> <li>add SQL functions to MySQL servers</li> <li>functions are imported from shared libraries</li> <li>to be implemented in C/C++</li> <li>wrapper libraries for other languages exist</li> </list> <list title="why UDFs?"> <li>add missing functionality</li> <li>gain performance</li> <li>interface to existing libraries</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/dep_file.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/dep_file.xml +++ presentations/slides/UDF_Gen/examples/dep_file.xml <deps> <file name="helper_code.c" /> </deps> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/install.sh?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/install.sh +++ presentations/slides/UDF_Gen/examples/install.sh $ pear -d master_server=pecl.php.net install PECL_Gen $ pear install http://www.php-groupies.de/php/UDF_Gen-0.2.0.tgz http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/return_result.c?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/return_result.c +++ presentations/slides/UDF_Gen/examples/return_result.c // returning an INT return 42; // returning a REAL return 3.14; // returning a NULL value for INT or REAL *is_null = 1; return 0; // returing a STRING (up to 255 characters) strcpy(result, string); *length = strlen(string); return; // returning a binary safe STRING memcpy(result, string, str_len); *length = str_len; return; // returning a NULL STRING *is_null = 1; return; // returing a DATETIME strcpy(result, "2000-01-01 00:00:00"); *length = strlen(result); return; http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/tag_code.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/tag_code.xml +++ presentations/slides/UDF_Gen/examples/tag_code.xml <code> // XML entity encoding (hard to read) if (i < 1) p = &1; </code> <code> <![CDATA[ // CDATA syntax is harder to remember // but the code within is far more readable if (i < 1) p = &1; ]]> </code> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.configure-make?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.configure-make +++ presentations/slides/UDF_Gen/examples/x1.configure-make $ configure $ make http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.dl?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.dl +++ presentations/slides/UDF_Gen/examples/x1.dl <?php dl("x1.so"); ... ?> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.install?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.install +++ presentations/slides/UDF_Gen/examples/x1.install $ sudo make install http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.log?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.log +++ presentations/slides/UDF_Gen/examples/x1.log $ udf-gen x1.xml Creating 'x1' extension in '/home/hartmut/examples/x1' Running 'aclocal' Running 'autoconf' Running 'automake' Your extension has been created in directory x1. See x1/README amd x1/INSTALL for further instructions. http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.php-ini?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.php-ini +++ presentations/slides/UDF_Gen/examples/x1.php-ini ... extension=x1.so ... http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.phpinfo?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.phpinfo +++ presentations/slides/UDF_Gen/examples/x1.phpinfo x1 The unknown extension Version 0.0.7unkown (2004-02-16) http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.phpize?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.phpize +++ presentations/slides/UDF_Gen/examples/x1.phpize $ cd x1 $ configure $ make $ sudo cp .libs/x1.so /usr/lib http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.tree?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.tree +++ presentations/slides/UDF_Gen/examples/x1.tree x1 |-- AUTHORS |-- COPYING |-- ChangeLog |-- INSTALL |-- Makefile.am |-- Makefile.in |-- NEWS |-- README |-- aclocal.m4 |-- autom4te.cache | |-- output.0 | |-- requests | `-- traces.0 |-- config.guess |-- config.sub |-- configure |-- configure.in |-- depcomp |-- install-sh |-- ltmain.sh |-- missing |-- mkinstalldirs |-- udf_x1.h `-- x1.cpp http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.xml +++ presentations/slides/UDF_Gen/examples/x1.xml <?xml version="1.0"?> <udf name="x1"/> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x2.xml +++ presentations/slides/UDF_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/UDF_Gen/examples/x3.create?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.create +++ presentations/slides/UDF_Gen/examples/x3.create /* register the functions provided by this UDF module using CREATE FUNCTION ex_sqr RETURNS REAL SONAME "example.so"; register the functions provided by this UDF module using DROP FUNCTION ex_sqr; */ http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x3.php?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.php +++ presentations/slides/UDF_Gen/examples/x3.php <?php // x3.php dl("x3.so"); echo foobar(); ?> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x3.result?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.result +++ presentations/slides/UDF_Gen/examples/x3.result $ php x3.php foobar http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x3.snippet?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.snippet +++ presentations/slides/UDF_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/UDF_Gen/examples/x3.txt?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.txt +++ presentations/slides/UDF_Gen/examples/x3.txt mysql> CREATE FUNCTION ex_sqr RETURNS REAL SONAME "example.so"; Query OK, 0 rows affected (0.00 sec) mysql> select ex_sqr(3); +-----------+ | ex_sqr(3) | +-----------+ | 9 | +-----------+ 1 row in set (0.01 sec) mysql> DROP FUNCTION ex_sqr; Query OK, 0 rows affected (0.01 sec) http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x3.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.xml +++ presentations/slides/UDF_Gen/examples/x3.xml <?xml version="1.0"?> <udf name="x3"> <maintainer> <name>Hartmut Holzgraefe</name> <email>hartmut@php.net</email> </maintainer> <license>LGPL</license> <function name="ex_sqr" returns="real"> <param name="p1" type="real"/> <code> return p1*p1; </code> </function> </udf> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x4.php?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x4.php +++ presentations/slides/UDF_Gen/examples/x4.php <?php // x4.php dl("x4.so"); echo foobar("Go! ", 3); ?> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x4.result?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x4.result +++ presentations/slides/UDF_Gen/examples/x4.result $ php x4.php Go! Go! Go! http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x4.snippet?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x4.snippet +++ presentations/slides/UDF_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/UDF_Gen/examples/x4.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x4.xml +++ presentations/slides/UDF_Gen/examples/x4.xml <?xml version="1.0"?> <udf name="x4"> <maintainer> <name>Hartmut Holzgraefe</name> <email>hartmut@php.net</email> </maintainer> <license>LGPL</license> <function name="ex_avg" type="aggregate" returns="real" null="yes"> <param name="x" type="real"/> <data> <element name="count" type="int" default="0"/> <element name="sum_x" type="real" default="0.0"/> </data> <clear> <![CDATA[ data->count = 0; data->sum_x = 0.0; ]]> </clear> <add> <![CDATA[ if (!x_is_null) { data->count++; data->sum_x += x; } ]]> </add> <result> <![CDATA[ if (data->count < 1) { *is_null = 1; return 0.0; } *is_null = 0; return data->sum_x / data->count; ]]> </result> </function> </udf>
http://cvs.php.net/co.php/presentations/UDF_Gen.xml?r=1.1&p=1 Index: presentations/UDF_Gen.xml +++ presentations/UDF_Gen.xml <presentation navbarbackground="#DAE6EA"> <title>UDF_Gen - a code generator for Mysql UDFs</title> <event>FOSDEM 2004</event> <location>Brussels</location> <date>Februrary 20 2004</date> <speaker>Hartmut Holzgraefe</speaker> <navmode>html</navmode> <basefontsize>12pt</basefontsize> <topic>Code Generators</topic> <logo1>presentations/slides/UDF_Gen/mysql_2004.png</logo1> <slide>slides/UDF_Gen/why.xml</slide> <slide>slides/UDF_Gen/title.xml</slide> <slide>slides/UDF_Gen/installation.xml</slide> <slide>slides/UDF_Gen/extension_tag.xml</slide> <slide>slides/UDF_Gen/invocation.xml</slide> <slide>slides/UDF_Gen/compilation.xml</slide> <slide>slides/UDF_Gen/function.xml</slide> <slide>slides/UDF_Gen/loading.xml</slide> <slide>slides/UDF_Gen/aggregate.xml</slide> <slide>slides/UDF_Gen/tag_function.xml</slide> <slide>slides/UDF_Gen/tag_parameter.xml</slide> <slide>slides/UDF_Gen/tag_code.xml</slide> <slide>slides/UDF_Gen/return_values.xml</slide> <slide>slides/UDF_Gen/tag_data.xml</slide> <slide>slides/UDF_Gen/adding_code.xml</slide> <slide>slides/UDF_Gen/adding_files.xml</slide> <slide>slides/UDF_Gen/whats_next.xml</slide> </presentation> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/adding_code.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/adding_code.xml +++ presentations/slides/UDF_Gen/adding_code.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>adding custom code</title> <blurb> Custom C code may be added using *%&lt;code&gt;%* sections outside of *%&lt;function&gt;%* declarations at any time. </blurb> <blurb> If the *role* attribute is set to '*header*' the code will be inserted right after the default %#include% statements, else it will be appended after any automatically generated code. </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/adding_files.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/adding_files.xml +++ presentations/slides/UDF_Gen/adding_files.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>adding files</title> <blurb> Additional code files may be specified within the *%&lt;deps&gt;%* section. </blurb> <example type="xml" linenumbers="true" filename="examples/dep_file.xml" fontsize="1em"/> <blurb> These files are copied to the newly created source directory and added to the *%Makefile%*s list of source files for the UDF shared object. </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/aggregate.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/aggregate.xml +++ presentations/slides/UDF_Gen/aggregate.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding an aggregate function</title> <blurb> Adding an aggregate function requires some additional effort as an aggregate function on the SQL level is actually implemented by a small family of C functions and private data passed between them. </blurb> <blurb> Aggregate private data is declared using the &lt;data&gt; tag. For each aggregate group it is initialized by the code given in &lt;clear&gt;. For each row of the group the &lt;add&gt; code is executed, receiving the declared &lt;parameter&gt;s just like a normal function. Finally the &lt;result&gt; code is executed and expected to pass the functions. </blurb> <blurb> See the following example for a simple reimplementation of the standard AVG() function: </blurb> <example filename="examples/x4.xml" linenumbers="1" format="xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/compilation.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/compilation.xml +++ presentations/slides/UDF_Gen/compilation.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Compilation</title> <blurb> The generated extension directory already contains a ready to use %configure% file, so compilation is as usual. </blurb> <blurb> The only step you need to perform manually right now is putting the generated %x1.so% extension file to a library directory where the mysql server can find it. </blurb> <example filename="examples/x1.phpize" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/compilation_1.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/compilation_1.xml +++ presentations/slides/UDF_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/UDF_Gen/compilation_2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/compilation_2.xml +++ presentations/slides/UDF_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/UDF_Gen/extension_tag.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/extension_tag.xml +++ presentations/slides/UDF_Gen/extension_tag.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;udf&gt;%</title> <blurb> An UDF_Gen description file specifies anything down to the actual function code (including parameter passing) in a rather simple XML format. </blurb> <blurb> While implementing an UDF one no longer needs to implement all the boring repetitive interface stuff but can start with the actual functionality right away. </blurb> <blurb> The *%&lt;udf&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/UDF_Gen/function.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/function.xml +++ presentations/slides/UDF_Gen/function.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding a function</title> <blurb> Lets add a simple function to the extension so that we can really use it: </blurb> <example filename="examples/x3.xml" linenumbers="1" format="xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/function_2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/function_2.xml +++ presentations/slides/UDF_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/UDF_Gen/installation.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/installation.xml +++ presentations/slides/UDF_Gen/installation.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Installation</title> <blurb> UDF requires %PHP5% and %PECL_Gen% from the %PECL% repository. UDF_Gen itself is not (yet?) part of %PECL% but available independently at %http://www.php-groupies.de/php/UDF_Gen-0.2.0.tgz% </blurb> <blurb> %PECL_Gen% and %UDF_Gen% are both installed using the %PECL% installer </blurb> <example filename="examples/install.sh" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/invocation.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/invocation.xml +++ presentations/slides/UDF_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/UDF_Gen/loading.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/loading.xml +++ presentations/slides/UDF_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 UDF shared extension. To activate it you have to load the extension into a mysql server. This is done using %CREATE FUNCTION ...% </blurb> <blurb> When you open the generated code file %x3.cpp% you'll see a comment block at the top showing the %CREATE% statements needed to install all functions provided by this extension. </blurb> <example filename="examples/x3.create" fontsize="1em"/> <example filename="examples/x3.txt" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/modes.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/modes.xml +++ presentations/slides/UDF_Gen/modes.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Modes of Operation</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/UDF_Gen/parameters.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/parameters.xml +++ presentations/slides/UDF_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/UDF_Gen/parameters_2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/parameters_2.xml +++ presentations/slides/UDF_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/UDF_Gen/parameters_3.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/parameters_3.xml +++ presentations/slides/UDF_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/UDF_Gen/phpinfo.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/phpinfo.xml +++ presentations/slides/UDF_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/UDF_Gen/phpinfo_2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/phpinfo_2.xml +++ presentations/slides/UDF_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/UDF_Gen/return_values.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/return_values.xml +++ presentations/slides/UDF_Gen/return_values.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>returning results</title> <blurb> For now there is no special support for returning values although it may be added at a later version. </blurb> <blurb> To return an *int* or *real* result you just use a plain C return statement with the appropriate return value. </blurb> <blurb> To return a *%NULL%* value from any function you have to set the variable pointed to by the *%is_null%* function parameter to *1*. </blurb> <blurb> For strings up to 255 characters long you have to copy the string to the location pointed to by the *%result%* paramter and store its length in the varibale pointed to by the *%length%* parameter. Returning longer strings requires memory allocation within the UDF and is not yet supported. </blurb> <blurb> *%datetime*% values need to be returned as strings for now. </blurb> <example type="xml" linenumbers="true" filename="examples/return_result.c" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/tag_code.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/tag_code.xml +++ presentations/slides/UDF_Gen/tag_code.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;code&gt;%</title> <blurb> The actual function code is put into %&lt;code&gt;% tags. </blurb> <blurb> XML encoding the code can be avoided using %&lt;![CDATA ... ]]&gt;% sections. </blurb> <example type="xml" linenumbers="true" filename="examples/tag_code.xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/tag_data.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/tag_data.xml +++ presentations/slides/UDF_Gen/tag_data.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;data&gt;%</title> <blurb> Aggregate UDF related stuff ... to be done ... </blurb> <example type="xml" linenumbers="true" filename="examples/tag_data.xml" fontsize="1em"/> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/tag_function.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/tag_function.xml +++ presentations/slides/UDF_Gen/tag_function.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;function&gt;%</title> <blurb> The *%&lt;function&gt;%* tag is used to define both normal and aggregate functions. Name, type and returned data type have to be specified using attributes. </blurb> <list> <li>*name* - function name</li> <li>*type* - either *normal* (default) or *aggregate*</li> <li>*null* - *true* if function may return *NULL*, else *false* (default)</li> <li>*returns* - return type: *string*, *int*, *real* or *datetime*</li> <li>*length* - for *real* and *integer*</li> <li>*decimals* - for *real*</li> </list> <blurb> Function parameters are defined using the *%&lt;parameter&gt;%* tag. </blurb> <blurb> Data private to a function is declared within the *%&lt;data&gt;%* tag. </blurb> <blurb> The *%&lt;code&gt;%* tag takes the code for normal functions, aggregate function code is put into the *%&lt;clear&gt;%*, *%&lt;add&gt;%* and *%&lt;result&gt;%* tags </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/tag_parameter.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/tag_parameter.xml +++ presentations/slides/UDF_Gen/tag_parameter.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>%&lt;parameter&gt;%</title> <blurb> The *%&lt;parameter&gt;%* tag defines function parameter names and types using the *name* and *type* attributes: </blurb> <list> <li>*name* - parameter name</li> <li>*type* - *string*, *int*, *real* or *datetime*</li> </list> <blurb> Code to check the parameter count and types is generated automatically. </blurb> <blurb> Local C variables are created that take the parameter value and optional information. For a parameter named *foobar* the following variables are created: </blurb> <list> <li> *foobar* - takes the parameter value. Depending on the parameter type this is either a *double*, *long long*, *char&#42;* or *time_t* </li> <li> *foobar_is_null* - for *int*, *real* and *datetime* this indicates whether a *NULL* value was passed (for *string* types *foobar* itself is a NULL pointer) </li> <li> *foobar_len* - for *string* this contains the actual string length </li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/testing1.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/testing1.xml +++ presentations/slides/UDF_Gen/testing1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>What else is possible?</title> <list> <li>other argument types (string, double, date, ...)</li> <li>adding source file to the project (including e.g. flex/bison code)</li> <li>...</li> </list> <blurb> See %ora_funcs.xml% as a reference example that implements most standard Oracle SQL functions not available in plain SQL. </blurb> <blurb> It includes stuff like all implemented parameter types and incorprates a %flex% code file for %TO_CHAR% argument parsing. </blurb> <blurb> ... </blurb> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/title.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/title.xml +++ presentations/slides/UDF_Gen/title.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>UDF_GEN</title> <list title="UDF_Gen is"> <li>an XML based UDF function code generator</li> <li>based on the PECL_Gen PHP extension code generator</li> <li>implemented using PHP 5 and PEAR only</li> </list> <list title="UDF_Gen creates"> <li>functions</li> <li>%configure% and %Makefile% infrastructure</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/whats_next.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/whats_next.xml +++ presentations/slides/UDF_Gen/whats_next.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Whats next?</title> <blurb> See %ora_funcs.xml% in the UDF_Gen tar archive for a working example that uses all currently supported features of UDF_Gen. </blurb> <blurb> Additional features will be added soon, especially: </blurb> <list> <li>library and header file detection for %configure%</li> <li>improved support for returning data</li> <li>constant and optional parameter support</li> <li>documentation stub generation</li> <li>maybe test case generation</li> <li>...</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/why.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/why.xml +++ presentations/slides/UDF_Gen/why.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>UDF</title> <list title="User Defined Functions"> <li>add SQL functions to MySQL servers</li> <li>functions are imported from shared libraries</li> <li>to be implemented in C/C++</li> <li>wrapper libraries for other languages exist</li> </list> <list title="why UDFs?"> <li>add missing functionality</li> <li>gain performance</li> <li>interface to existing libraries</li> </list> </slide> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/dep_file.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/dep_file.xml +++ presentations/slides/UDF_Gen/examples/dep_file.xml <deps> <file name="helper_code.c" /> </deps> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/install.sh?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/install.sh +++ presentations/slides/UDF_Gen/examples/install.sh $ pear -d master_server=pecl.php.net install PECL_Gen $ pear install http://www.php-groupies.de/php/UDF_Gen-0.2.0.tgz http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/return_result.c?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/return_result.c +++ presentations/slides/UDF_Gen/examples/return_result.c // returning an INT return 42; // returning a REAL return 3.14; // returning a NULL value for INT or REAL *is_null = 1; return 0; // returing a STRING (up to 255 characters) strcpy(result, string); *length = strlen(string); return; // returning a binary safe STRING memcpy(result, string, str_len); *length = str_len; return; // returning a NULL STRING *is_null = 1; return; // returing a DATETIME strcpy(result, "2000-01-01 00:00:00"); *length = strlen(result); return; http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/tag_code.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/tag_code.xml +++ presentations/slides/UDF_Gen/examples/tag_code.xml <code> // XML entity encoding (hard to read) if (i < 1) p = &1; </code> <code> <![CDATA[ // CDATA syntax is harder to remember // but the code within is far more readable if (i < 1) p = &1; ]]> </code> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.configure-make?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.configure-make +++ presentations/slides/UDF_Gen/examples/x1.configure-make $ configure $ make http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.dl?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.dl +++ presentations/slides/UDF_Gen/examples/x1.dl <?php dl("x1.so"); ... ?> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.install?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.install +++ presentations/slides/UDF_Gen/examples/x1.install $ sudo make install http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.log?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.log +++ presentations/slides/UDF_Gen/examples/x1.log $ udf-gen x1.xml Creating 'x1' extension in '/home/hartmut/examples/x1' Running 'aclocal' Running 'autoconf' Running 'automake' Your extension has been created in directory x1. See x1/README amd x1/INSTALL for further instructions. http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.php-ini?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.php-ini +++ presentations/slides/UDF_Gen/examples/x1.php-ini ... extension=x1.so ... http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.phpinfo?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.phpinfo +++ presentations/slides/UDF_Gen/examples/x1.phpinfo x1 The unknown extension Version 0.0.7unkown (2004-02-16) http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.phpize?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.phpize +++ presentations/slides/UDF_Gen/examples/x1.phpize $ cd x1 $ configure $ make $ sudo cp .libs/x1.so /usr/lib http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.tree?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.tree +++ presentations/slides/UDF_Gen/examples/x1.tree x1 |-- AUTHORS |-- COPYING |-- ChangeLog |-- INSTALL |-- Makefile.am |-- Makefile.in |-- NEWS |-- README |-- aclocal.m4 |-- autom4te.cache | |-- output.0 | |-- requests | `-- traces.0 |-- config.guess |-- config.sub |-- configure |-- configure.in |-- depcomp |-- install-sh |-- ltmain.sh |-- missing |-- mkinstalldirs |-- udf_x1.h `-- x1.cpp http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x1.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x1.xml +++ presentations/slides/UDF_Gen/examples/x1.xml <?xml version="1.0"?> <udf name="x1"/> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x2.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x2.xml +++ presentations/slides/UDF_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/UDF_Gen/examples/x3.create?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.create +++ presentations/slides/UDF_Gen/examples/x3.create /* register the functions provided by this UDF module using CREATE FUNCTION ex_sqr RETURNS REAL SONAME "example.so"; register the functions provided by this UDF module using DROP FUNCTION ex_sqr; */ http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x3.php?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.php +++ presentations/slides/UDF_Gen/examples/x3.php <?php // x3.php dl("x3.so"); echo foobar(); ?> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x3.result?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.result +++ presentations/slides/UDF_Gen/examples/x3.result $ php x3.php foobar http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x3.snippet?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.snippet +++ presentations/slides/UDF_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/UDF_Gen/examples/x3.txt?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.txt +++ presentations/slides/UDF_Gen/examples/x3.txt mysql> CREATE FUNCTION ex_sqr RETURNS REAL SONAME "example.so"; Query OK, 0 rows affected (0.00 sec) mysql> select ex_sqr(3); +-----------+ | ex_sqr(3) | +-----------+ | 9 | +-----------+ 1 row in set (0.01 sec) mysql> DROP FUNCTION ex_sqr; Query OK, 0 rows affected (0.01 sec) http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x3.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x3.xml +++ presentations/slides/UDF_Gen/examples/x3.xml <?xml version="1.0"?> <udf name="x3"> <maintainer> <name>Hartmut Holzgraefe</name> <email>hartmut@php.net</email> </maintainer> <license>LGPL</license> <function name="ex_sqr" returns="real"> <param name="p1" type="real"/> <code> return p1*p1; </code> </function> </udf> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x4.php?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x4.php +++ presentations/slides/UDF_Gen/examples/x4.php <?php // x4.php dl("x4.so"); echo foobar("Go! ", 3); ?> http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x4.result?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x4.result +++ presentations/slides/UDF_Gen/examples/x4.result $ php x4.php Go! Go! Go! http://cvs.php.net/co.php/presentations/slides/UDF_Gen/examples/x4.snippet?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x4.snippet +++ presentations/slides/UDF_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/UDF_Gen/examples/x4.xml?r=1.1&p=1 Index: presentations/slides/UDF_Gen/examples/x4.xml +++ presentations/slides/UDF_Gen/examples/x4.xml <?xml version="1.0"?> <udf name="x4"> <maintainer> <name>Hartmut Holzgraefe</name> <email>hartmut@php.net</email> </maintainer> <license>LGPL</license> <function name="ex_avg" type="aggregate" returns="real" null="yes"> <param name="x" type="real"/> <data> <element name="count" type="int" default="0"/> <element name="sum_x" type="real" default="0.0"/> </data> <clear> <![CDATA[ data->count = 0; data->sum_x = 0.0; ]]> </clear> <add> <![CDATA[ if (!x_is_null) { data->count++; data->sum_x += x; } ]]> </add> <result> <![CDATA[ if (data->count < 1) { *is_null = 1; return 0.0; } *is_null = 0; return data->sum_x / data->count; ]]> </result> </function> </udf>