Re: Anyone seen an Inline::C implementation in php

From: Date: Mon, 23 Sep 2002 06:06:18 +0000
Subject: Re: Anyone seen an Inline::C implementation in php
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-9338@lists.php.net to get a copy of this message
Its more designed for some kind of auto generating tool - eg. a toolkit ontop of the basic inline C stuff.. - eg. similar to php-gtk generator code. George Schlossnagle wrote:
Having thought about this a bit more.... Do you think that interface is ideal? One of the benefits of the current implementation is that it does all the naming for you (based off the md5 checksum of the body of the code). This means that you are prevented from having name-space conflicts and eliminates the naming issues. Also, while I definitely like the idea of simplifying function coding, I think that it's hard to do so without either
    o  creating a 'new' macro language just as difficult as the C macros
    o  eliminating flexibility
$function->setArguments("ll","i","j"); is not so much shorter than
    long i,j;
    if (zend_parse_parameters(ZEND_NUM_ARGS()  TSRMLS_CC, "ll", &i,&j) == FAILURE) {
        WRONG_PARAM_COUNT;
    }
(though that makes it a good candidate for a C macro!) And certainly $function->declareVar("l",i); is longer than long i; and means that now you have to learn to program C in a completely new way. On Monday, September 23, 2002, at 12:52 AM, George Schlossnagle wrote:
Cool - I hadn't even considered that. It also desperately needs an interface for linking against external libraries. And as much as I hate to do so (for reasons of elegance), rewriting a dl() implementation that allows you to reasonably set the directory to load from and an option for loading modules permanently into a child (so you don't actually do the dl everytime). Writing this is of course trivial (and in fact could be done with Inline_C itself ;), but I really liked this being pure userspace php.... :) George On Sunday, September 22, 2002, at 11:36 PM, Alan Knowles wrote:
Very interesting ... my mind exploded with lots of ideas about tools for this.. - $t = new PHP_InlineC; $function = $t->addfunction('time'); $function->addVars("long i", "long j", "long k"); $function->setArguments("ll", "i","j"); $function->addC("k = i * j;") $function->returnLong("k"); $t->setModuleName('timetest'); $t->build(); $t->load(); which could grow into a whole toolkit for autobuilding C modules.... wow.... Alan George Schlossnagle wrote:
Well, here's my first shot. http://www.omniti.com/~george/Inline.tar.gz I have only tested this on my system (freebsd 4.5), so it almost certainly has bugs. To try it out, run mkbuildtree <your desired runtime builddir> You need to run this command as your webserver/php-running user (or ensure that all relevant permisions are ok afterwards) This will install a build tree for your runtime modules in the specified dir, and will create Inline.php from Inline.php.in, making some critical substitutions specific to your system. Due to the implementation of dl(), we have to do some funky magic. If extension_dir (php.ini) is null or ./, your modules will be installed into buildir/inline_libs/, otherwise it will be installed in ini_get(extension_dir)/inline_libs. Either way, since these things are runtime compiled, the webserver user will need write permission to these directories. I would like to avoid writing my own dl(), since as it stands, all the code is in userspace php, which I think is very positive. I have not given signficant testing when extension_dir is somethng other than ./, so ymmv. Compiled functions are cached and reused when possible. There is a test.php script bundled with the tar ball, it demonstrates a sample usage. Like I said, this is highly beta, but comments/patches/feedback are welcome. George (p.s. I doubt this works on windows - I dont even own a windows box, let alone one with a compiler. patches are welcome) On Wednesday, September 18, 2002, at 06:40 PM, George Schlossnagle wrote:
I'm considering implementing something like perl's Inline::C in php, but I want to avoid re-inventing the wheel. Anyone see anything thike this? Basically the goal would be able to write something like: <?pseudocode $function_def = <<<EOF php_function(times){
   int i,j;    return if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, &i,&j) = FAILURE)
RETURN_LONG(i*j); } EOF Inline_C($function_def); times(2,2); ?> Inline_C would take the block of code, wrap it in module glue, compile it, cache the binary somewhere, the call dl() on it. Anyone seen anything like this for php? -- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
// 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
-- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.pear.dev (#9338) next »