From fea8c5481bfae651167d90393ddae89e591b0d55 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 23 Oct 2019 17:18:11 +0300 Subject: [PATCH] Added suppot for glob() wildcard matching in ffi.preload directive --- ext/ffi/ffi.c | 93 +++++++++++++++++++++++++++++++++++++----- ext/ffi/tests/303.phpt | 15 +++++++ php.ini-development | 2 +- php.ini-production | 2 +- 4 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 ext/ffi/tests/303.phpt diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index e2476653f7..ca6e7c4ef5 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -35,6 +35,14 @@ #include #include +#ifdef HAVE_GLOB +#ifdef PHP_WIN32 +#include "win32/glob.h" +#else +#include +#endif +#endif + ZEND_DECLARE_MODULE_GLOBALS(ffi) typedef enum _zend_ffi_tag_kind { @@ -4836,10 +4844,50 @@ ZEND_INI_BEGIN() STD_ZEND_INI_ENTRY("ffi.preload", NULL, ZEND_INI_SYSTEM, OnUpdateString, preload, zend_ffi_globals, ffi_globals) ZEND_INI_END() +static int zend_ffi_preload_glob(const char *filename) /* {{{ */ +{ +#ifdef HAVE_GLOB + glob_t globbuf; + int ret; + unsigned int i; + + memset(&globbuf, 0, sizeof(glob_t)); + + ret = glob(filename, 0, NULL, &globbuf); +#ifdef GLOB_NOMATCH + if (ret == GLOB_NOMATCH || !globbuf.gl_pathc) { +#else + if (!globbuf.gl_pathc) { +#endif + /* pass */ + } else { + for(i=0 ; i + +--INI-- +ffi.enable=1 +ffi.preload={PWD}/300*.h +--FILE-- +printf("Hello World from %s!\n", "PHP"); +?> +--EXPECT-- +Hello World from PHP! diff --git a/php.ini-development b/php.ini-development index 3f0c90cfca..f44c541a7a 100644 --- a/php.ini-development +++ b/php.ini-development @@ -1946,5 +1946,5 @@ ldap.max_links = -1 ; "true" - always enabled ;ffi.enable=preload -; List of headers files to preload +; List of headers files to preload, wilcards allowed. ;ffi.preload= diff --git a/php.ini-production b/php.ini-production index 867de11c60..b7f2536fd9 100644 --- a/php.ini-production +++ b/php.ini-production @@ -1948,5 +1948,5 @@ ldap.max_links = -1 ; "true" - always enabled ;ffi.enable=preload -; List of headers files to preload +; List of headers files to preload, wilcards allowed. ;ffi.preload= -- 2.40.0