mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Added suppot for glob() wildcard matching in ffi.preload directive
This commit is contained in:
parent
af57b6330b
commit
fea8c5481b
4 changed files with 99 additions and 13 deletions
|
@ -35,6 +35,14 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_GLOB
|
||||||
|
#ifdef PHP_WIN32
|
||||||
|
#include "win32/glob.h"
|
||||||
|
#else
|
||||||
|
#include <glob.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
ZEND_DECLARE_MODULE_GLOBALS(ffi)
|
ZEND_DECLARE_MODULE_GLOBALS(ffi)
|
||||||
|
|
||||||
typedef enum _zend_ffi_tag_kind {
|
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)
|
STD_ZEND_INI_ENTRY("ffi.preload", NULL, ZEND_INI_SYSTEM, OnUpdateString, preload, zend_ffi_globals, ffi_globals)
|
||||||
ZEND_INI_END()
|
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<globbuf.gl_pathc; i++) {
|
||||||
|
zend_ffi *ffi = zend_ffi_load(globbuf.gl_pathv[i], 1);
|
||||||
|
if (!ffi) {
|
||||||
|
globfree(&globbuf);
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
efree(ffi);
|
||||||
|
}
|
||||||
|
globfree(&globbuf);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
zend_ffi *ffi = zend_ffi_load(filename, 1);
|
||||||
|
if (!ffi) {
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
efree(ffi);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
static int zend_ffi_preload(char *preload) /* {{{ */
|
static int zend_ffi_preload(char *preload) /* {{{ */
|
||||||
{
|
{
|
||||||
zend_ffi *ffi;
|
zend_ffi *ffi;
|
||||||
char *s = NULL, *e, *filename;
|
char *s = NULL, *e, *filename;
|
||||||
|
zend_bool is_glob = 0;
|
||||||
|
|
||||||
e = preload;
|
e = preload;
|
||||||
while (*e) {
|
while (*e) {
|
||||||
|
@ -4847,15 +4895,30 @@ static int zend_ffi_preload(char *preload) /* {{{ */
|
||||||
case ZEND_PATHS_SEPARATOR:
|
case ZEND_PATHS_SEPARATOR:
|
||||||
if (s) {
|
if (s) {
|
||||||
filename = estrndup(s, e-s);
|
filename = estrndup(s, e-s);
|
||||||
ffi = zend_ffi_load(filename, 1);
|
|
||||||
efree(filename);
|
|
||||||
if (!ffi) {
|
|
||||||
return FAILURE;
|
|
||||||
}
|
|
||||||
efree(ffi);
|
|
||||||
s = NULL;
|
s = NULL;
|
||||||
|
if (!is_glob) {
|
||||||
|
ffi = zend_ffi_load(filename, 1);
|
||||||
|
efree(filename);
|
||||||
|
if (!ffi) {
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
efree(ffi);
|
||||||
|
} else {
|
||||||
|
int ret = zend_ffi_preload_glob(filename);
|
||||||
|
|
||||||
|
efree(filename);
|
||||||
|
if (ret != SUCCESS) {
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
is_glob = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case '*':
|
||||||
|
case '?':
|
||||||
|
case '[':
|
||||||
|
is_glob = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (!s) {
|
if (!s) {
|
||||||
s = e;
|
s = e;
|
||||||
|
@ -4866,12 +4929,20 @@ static int zend_ffi_preload(char *preload) /* {{{ */
|
||||||
}
|
}
|
||||||
if (s) {
|
if (s) {
|
||||||
filename = estrndup(s, e-s);
|
filename = estrndup(s, e-s);
|
||||||
ffi = zend_ffi_load(filename, 1);
|
if (!is_glob) {
|
||||||
efree(filename);
|
ffi = zend_ffi_load(filename, 1);
|
||||||
if (!ffi) {
|
efree(filename);
|
||||||
return FAILURE;
|
if (!ffi) {
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
efree(ffi);
|
||||||
|
} else {
|
||||||
|
int ret = zend_ffi_preload_glob(filename);
|
||||||
|
efree(filename);
|
||||||
|
if (ret != SUCCESS) {
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
efree(ffi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
|
15
ext/ffi/tests/303.phpt
Normal file
15
ext/ffi/tests/303.phpt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
--TEST--
|
||||||
|
FFI 303: FFI preloading flob
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require_once('skipif.inc'); ?>
|
||||||
|
<?php if (substr(PHP_OS, 0, 3) == 'WIN') die('skip not for Windows'); ?>
|
||||||
|
--INI--
|
||||||
|
ffi.enable=1
|
||||||
|
ffi.preload={PWD}/300*.h
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$ffi = FFI::scope("TEST_300");
|
||||||
|
$ffi->printf("Hello World from %s!\n", "PHP");
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Hello World from PHP!
|
|
@ -1946,5 +1946,5 @@ ldap.max_links = -1
|
||||||
; "true" - always enabled
|
; "true" - always enabled
|
||||||
;ffi.enable=preload
|
;ffi.enable=preload
|
||||||
|
|
||||||
; List of headers files to preload
|
; List of headers files to preload, wilcards allowed.
|
||||||
;ffi.preload=
|
;ffi.preload=
|
||||||
|
|
|
@ -1948,5 +1948,5 @@ ldap.max_links = -1
|
||||||
; "true" - always enabled
|
; "true" - always enabled
|
||||||
;ffi.enable=preload
|
;ffi.enable=preload
|
||||||
|
|
||||||
; List of headers files to preload
|
; List of headers files to preload, wilcards allowed.
|
||||||
;ffi.preload=
|
;ffi.preload=
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue