Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102050 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5784 invoked from network); 17 Apr 2018 08:55:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2018 08:55:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain zend.com from 104.47.34.112 cause and error) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 104.47.34.112 mail-by2nam01on0112.outbound.protection.outlook.com Received: from [104.47.34.112] ([104.47.34.112:54123] helo=NAM01-BY2-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2E/0A-36099-C66B5DA5 for ; Tue, 17 Apr 2018 04:55:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=RWSoftware.onmicrosoft.com; s=selector1-zend-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=qo6fCZYJHbHcQrn0o4HzGRvvWf+QtT3drSujFi0fwXE=; b=swYt73cQff1BjOjfdZV4KnhzrdC2u/r+jbskSHUzJ2CO+qIZz/gg71xDQks86RZG1pJ41ISVd4Vmguq6OnBm/xKI/k7t3NLRh/ULZqVzrBPeLiRySsLlgZVr2kq5dZTWaytnFx3VJh9ZWRUCWdR59n5xMvQFsyO8sIGbxQvyJI0= Received: from BN6PR02MB3234.namprd02.prod.outlook.com (10.161.152.32) by BN6PR02MB2513.namprd02.prod.outlook.com (10.173.141.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.675.10; Tue, 17 Apr 2018 08:55:03 +0000 Received: from BN6PR02MB3234.namprd02.prod.outlook.com ([fe80::b5e1:42c:d6ad:56c]) by BN6PR02MB3234.namprd02.prod.outlook.com ([fe80::b5e1:42c:d6ad:56c%13]) with mapi id 15.20.0675.015; Tue, 17 Apr 2018 08:55:03 +0000 To: =?iso-8859-2?Q?Micha=B3_Brzuchalski?= CC: Stanislav Malyshev , Zeev Suraski , Xinchen Hui , Nikita Popov , Bob Weinand , "Anatol Belski (ab@php.net)" , "PHP internals list" Thread-Topic: [PHP-DEV] PHP FFI extenesion Thread-Index: AQHT0yrBnLpXxgz1HEWdw/jxKSLJkaQEFM4AgAB9ZWeAAAGVAIAAAlrlgAAFVQCAABEhCg== Date: Tue, 17 Apr 2018 08:55:03 +0000 Message-ID: References: <56794c33-a728-d399-2462-b62ba1b7a509@gmail.com> , In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=dmitry@zend.com; x-originating-ip: [212.232.72.197] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BN6PR02MB2513;7:9eCLvS3P+4HraahqrqveA0mzh3aJEMiq+3R9ZJN+Wwj1Z8SMsDrRDlEtR6fNinrCWctuVVydG2BKi/VmzXF4yJqRnabY8uIRCg8s401SQzqEhRYGPKmtIwBhK65+oPEwUH5q5pfdbs9Z+5hCY2c8kqE3zKBoLrjwNSGgQty8DEsU8Upw2VSFYgnIs2cvR++ToDPVRO+w/hsxyiTJRZuAUxOdUwQ7DpjUHTnGfBM7QSso63VollQykvn7mhSdxcmf x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10019020)(366004)(39380400002)(376002)(346002)(396003)(39850400004)(189003)(377424004)(199004)(966005)(478600001)(6606003)(229853002)(8936002)(4326008)(8676002)(81166006)(81156014)(5660300001)(5250100002)(74316002)(7736002)(53366004)(53376002)(66066001)(236005)(55016002)(2900100001)(53936002)(39060400002)(86362001)(6916009)(3846002)(6116002)(54896002)(6246003)(6436002)(6306002)(25786009)(11346002)(9686003)(76176011)(26005)(59450400001)(93886005)(316002)(102836004)(53546011)(6506007)(476003)(2906002)(7696005)(19627405001)(68736007)(3280700002)(33656002)(486006)(3660700001)(105586002)(446003)(99286004)(97736004)(106356001)(606006)(14454004)(54906003)(186003)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR02MB2513;H:BN6PR02MB3234.namprd02.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:BN6PR02MB2513; x-ms-traffictypediagnostic: BN6PR02MB2513: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(166708455590820)(85827821059158)(185789414550570); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231232)(944501327)(52105095)(3002001)(93006095)(93001095)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(6072148)(201708071742011);SRVR:BN6PR02MB2513;BCL:0;PCL:0;RULEID:;SRVR:BN6PR02MB2513; x-forefront-prvs: 0645BEB7AA received-spf: None (protection.outlook.com: zend.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 3yxfsXxTRFIETDnYb12bffpdqIVKbsbp6+qoCxp7pWoZ6todBECPWLgLy9w1TG62GRAlR0tAv7qDNg8i/bUxQ1N78RDhOs4mQN3zrkhLefjauUZxypvxhXrOeCM0OgcB/vlNsaHguzQi8ElEVM9+Jv98DkOINpZLN6vh5zjB5zXV9C7zcXxZjX0Zp3WcWic8 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: multipart/alternative; boundary="_000_BN6PR02MB3234A38F7ED99529068D0A56BFB70BN6PR02MB3234namp_" MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 0078bd62-1b22-40b5-88a2-08d5a440e8d1 X-OriginatorOrg: zend.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0078bd62-1b22-40b5-88a2-08d5a440e8d1 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Apr 2018 08:55:03.3232 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 32210298-c08b-4829-8097-6b12c025a892 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB2513 Subject: Re: [PHP-DEV] PHP FFI extenesion From: dmitry@zend.com (Dmitry Stogov) --_000_BN6PR02MB3234A38F7ED99529068D0A56BFB70BN6PR02MB3234namp_ Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Now, I got your idea. Subclassing CData, and use that types for type hinting may make sense. I'll put this idea in my TODO, but with low priority. Thanks. Dmitry. ________________________________ From: Micha=B3 Brzuchalski Sent: Tuesday, April 17, 2018 10:51:32 AM To: Dmitry Stogov Cc: Stanislav Malyshev; Zeev Suraski; Xinchen Hui; Nikita Popov; Bob Weinan= d; Anatol Belski (ab@php.net); PHP internals list Subject: Re: [PHP-DEV] PHP FFI extenesion 2018-04-17 9:46 GMT+02:00 Dmitry Stogov >: Hi Michal, I didn't think in this way. I liked to make the simplest API. I don't expect wide FFI usage in frameworks :) BTW: I like the idea of use C type names (probably, we may reuse original C= type names without additional registration). currently we can do: $tz =3D $libc->new("struct timezone"); My point was ability to provide an identity to objects wich acts as a struc= ts. CData class has no idea of what struct type it is and I cannot type hin= t over that, thats why I thought it would be usefull. I could then prepare a vendor using pure PHP and wrap everything using type= s. I'll think, if we can existend API to use something like: $tz =3D FFI::new(= $libc->timezone); At least, this should eliminate C parsing overhead. Thanks. Dmitry. ________________________________ From: Micha=B3 Brzuchalski > Sent: Tuesday, April 17, 2018 10:24:02 AM To: Dmitry Stogov Cc: Stanislav Malyshev; Zeev Suraski; Xinchen Hui; Nikita Popov; Bob Weinan= d; Anatol Belski (ab@php.net); PHP internals list Subject: Re: [PHP-DEV] PHP FFI extenesion Hi Dmitry! I am not much experienced with C but as a user, I'm just wondering if there= is a possibility to extend FFI class and autoregister all or just chosen s= tructs as classes, for eg. class Libc extends FFI { public function __construct() { parent::__construct("...code", "...lib"); // tmp notation $this->register('struct timeval', Libc\Timeval::class); // I assume= they would extend CData $this->register('struct timezone', Libc\Timezone::class); // as abo= ve } } So I can instantiate $tz =3D new Libc\Timezone(); $tv =3D new Libc\Timeval(); and then pass them FFI function (new Libc())->gettimeofday($tv, $tz); var_dump($tv-tv_sec, $tv->tv_usec, $tz); I would be able to prepare than a vendor package with a specified autoloade= r. Would that make sense? Also wouldn't it better if CData class share the same prefixes like FFICdat= a or FFI\CData? Cheers, Michal 2018-04-17 9:18 GMT+02:00 Dmitry Stogov >: On Apr 17, 2018 2:49 AM, Stanislav Malyshev > wrote: Hi! > I've spent some time thinking about simple FFI for PHP, and finally, borr= owed most ideas from LuaJIT. > > This is an initial PoC. It was tested on Linux only. > > > https://github.com/dstogov/php-ffi > > > I would appreciate review, comments and ideas about missing features and = functionality. > Looks interesting. On a cursory look, couple of thoughts: - I think all the classes involved should be made non-serializable and non-unserializable. Agree. - Does it load shared libraries, or only uses ones already loaded? If the former, I think there should be a way to unload them at the request end (even though it might be performance issue, and may be not possible if persistent resources are involved), otherwise we leak state between requests. I have a bit opposit idea. We will keep FFI for CLI but disable it for web = apps (like dl()). At the same time, we will develop a technology to preload and reuse PHP fi= les across requests. And allow FFI there. - OTOH, people may want to load a set of persistent definitions from a config file, etc. - the ffi definition probably won't change much, and having locked down set of FFI interfaces the rest of the code is using might be beneficial Yeah. Like this. - Since this thing is dealing with raw pointers, etc., from PHP code, there may be a lot of crashes from using this extension in a wrong way. I wonder which facilities we could provide for helping people to debug it (for people who aren't super-comfortable using gdb on PHP engine). Programming using FFI, is very similar to C. I'm not sure, if we may provide good debugging facilities. Thanks for review. Dmitry. -- Stas Malyshev smalyshev@gmail.com Hi! > I've spent some time thinking about simple FFI for PHP, and finally, borr= owed most ideas from LuaJIT. > > This is an initial PoC. It was tested on Linux only. > > > https://github.com/dstogov/php-ffi > > > I would appreciate review, comments and ideas about missing features and = functionality. > Looks interesting. On a cursory look, couple of thoughts: - I think all the classes involved should be made non-serializable and non-unserializable. - Does it load shared libraries, or only uses ones already loaded? If the former, I think there should be a way to unload them at the request end (even though it might be performance issue, and may be not possible if persistent resources are involved), otherwise we leak state between requests. - OTOH, people may want to load a set of persistent definitions from a config file, etc. - the ffi definition probably won't change much, and having locked down set of FFI interfaces the rest of the code is using might be beneficial - Since this thing is dealing with raw pointers, etc., from PHP code, there may be a lot of crashes from using this extension in a wrong way. I wonder which facilities we could provide for helping people to debug it (for people who aren't super-comfortable using gdb on PHP engine). -- Stas Malyshev smalyshev@gmail.com -- regards / pozdrawiam, -- Micha=B3 Brzuchalski about.me/brzuchal brzuchalski.com -- regards / pozdrawiam, -- Micha=B3 Brzuchalski about.me/brzuchal brzuchalski.com --_000_BN6PR02MB3234A38F7ED99529068D0A56BFB70BN6PR02MB3234namp_--