Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102048 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 355 invoked from network); 17 Apr 2018 07:46:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2018 07:46:37 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain zend.com from 104.47.36.128 cause and error) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 104.47.36.128 mail-sn1nam02on0128.outbound.protection.outlook.com Received: from [104.47.36.128] ([104.47.36.128:26256] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 33/29-36099-B56A5DA5 for ; Tue, 17 Apr 2018 03:46:35 -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=G0fbOfQgnCPLB4La/RLOOmArV6XPeu63YJDj0wB+z78=; b=C0GsEg5RMSNwuS8iF/RfcJ+VV0VyVnS7FjmfEHSDzbHp06MBhMLnb5nRJdMpsbf9QlJQsa4Z7SjhOUPbOVWURyQzgc8xVe0coP6+kcYDpvthWVbiDbxKh4OxRv94I+nC8K+LSNcLPWP9/i8LOou39j4OyMZEIHQM3LBMJAHHtMs= Received: from BN6PR02MB3234.namprd02.prod.outlook.com (10.161.152.32) by BN6PR02MB2737.namprd02.prod.outlook.com (10.175.95.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.696.12; Tue, 17 Apr 2018 07:46:30 +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 07:46:30 +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/jxKSLJkaQEFM4AgAB9ZWeAAAGVAIAAAlrl Date: Tue, 17 Apr 2018 07:46:29 +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;BN6PR02MB2737;7:/qYpg9gdY0jJHdC2r66Z0EvMVkfz2flkMGT7F+EOGG/r3bvGMWoTWmAyjnenZ7nfySZ1aF4gV1V6WvbGifte3UkKcSXroN77bUoHlm6rQk+rxt2MOMM8lweiddcBX7wNVRQo8ggGKoYioOD+GHo0YXaUhcpKqo2/XkniY4gIRo1lz2rmCmUNGOfxdy4B3kgelf1j+9+r+SJlwD5Kp3x34i5Hw7+rl88tIe07p32YCEdlHAeX7JuMySCmKQM+3xIE x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10019020)(366004)(346002)(39850400004)(396003)(376002)(39380400002)(377424004)(199004)(189003)(316002)(81166006)(9686003)(6506007)(53376002)(99286004)(6246003)(53366004)(59450400001)(5660300001)(53546011)(39060400002)(86362001)(8676002)(236005)(486006)(7696005)(478600001)(476003)(55016002)(6606003)(2900100001)(53936002)(6306002)(6116002)(106356001)(6436002)(105586002)(11346002)(54906003)(102836004)(33656002)(76176011)(6916009)(229853002)(3846002)(54896002)(66066001)(2906002)(446003)(5250100002)(186003)(606006)(4326008)(3660700001)(3280700002)(74316002)(7736002)(26005)(966005)(68736007)(25786009)(81156014)(14454004)(97736004)(19627405001)(93886005)(8936002)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR02MB2737;H:BN6PR02MB3234.namprd02.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:BN6PR02MB2737; x-ms-traffictypediagnostic: BN6PR02MB2737: 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)(3231232)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6041310)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011);SRVR:BN6PR02MB2737;BCL:0;PCL:0;RULEID:;SRVR:BN6PR02MB2737; x-forefront-prvs: 0645BEB7AA received-spf: None (protection.outlook.com: zend.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: I36JdiOuT6kmjugMYvJ5eQc+pP22arTNxsFWTpRmnqr5mKryb/vAjPZktR6Qfg4cde/MT3Bi6ma3RdqTaGJqGBjFPmRZstoBjCwh4B7wasC2ExhFVvl+1GB9BcmLZGgcO6O/y6SDPR/MpguBRP4cLizJgfYg8eadqxtEu9nTNA7PUDWvvUk390MGhA1PbfUH spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: multipart/alternative; boundary="_000_BN6PR02MB323410849DDE3D30E225D2D0BFB70BN6PR02MB3234namp_" MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 7c169a5b-85b1-4f64-703c-08d5a4375516 X-OriginatorOrg: zend.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c169a5b-85b1-4f64-703c-08d5a4375516 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Apr 2018 07:46:29.9873 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 32210298-c08b-4829-8097-6b12c025a892 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB2737 Subject: Re: [PHP-DEV] PHP FFI extenesion From: dmitry@zend.com (Dmitry Stogov) --_000_BN6PR02MB323410849DDE3D30E225D2D0BFB70BN6PR02MB3234namp_ Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable 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"); 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 --_000_BN6PR02MB323410849DDE3D30E225D2D0BFB70BN6PR02MB3234namp_--