Submission: Inline_C
| From: | George Schlossnagle | Date: | Thu, 26 Sep 2002 03:03:57 +0000 |
| Subject: | Submission: Inline_C | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-9518@lists.php.net to get a copy of this message | ||
Inline_C is a class that allows you to write critical function code in C, from within userland php. Basically it provides 'glue' and a build system for taking PHP_FUNCTION definitions, and wrapping the build and dl() process. The interface is like:
<?
require_once("Inline_C.php");
$function1 = <<<EOF
PHP_FUNCTION(times)
{
long i,j;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &i,&j) == FAILURE) {
WRONG_PARAM_COUNT;
}
RETURN_LONG(i*j);
}
EOF;
$inline = new Inline_C;
$inline->add_code($function1);
// To link against libfoo
//$inline->library("foo","/usr/local/lib");
$inline->compile();
for($i=0;$i<10;$i++) {
for($j=0; $j<10; $j++) {
print "$i * $j = ".times($i,$j)."\n";
}
}
?>
Code is available at http://www.omniti.com/~george/Inline.tar.gz. Basic testing has been done on 4.2.3 and HEAD.
// George Schlossnagle
// Principal Consultant
// OmniTI, Inc http://www.omniti.com// (c) 240.460.5234 (e) george@omniti.com // 1024D/1100A5A0 1370 F70A 9365 96C9 2F5E 56C2 B2B9 262F 1100 A5A0