Skip to content

Commit 4ab5272

Browse files
committed
Massive first pass at conversion to internal glob
Have not tested yet. the big things are: - Should be invisible to userland PHP code. - A lot of :%s/GLOB_/PHP_GLOB_/g; the diff can be noisy as a result, especially in comments. - Prefixes everything with PHP_ to avoid conflicts with system glob in case it gets included transitively. - A lot of weird shared definitions that were sprawled out to other headers are now included in php_glob.h. - A lot of (but not yet all cases) of HAVE_GLOB are removed, since we can always fall back to php_glob. - Using the system glob is not wired up yet; it'll need more shim ifdefs for each flag type than just glob_t/glob/globfree defs.
1 parent 90ce93f commit 4ab5272

File tree

11 files changed

+175
-277
lines changed

11 files changed

+175
-277
lines changed

ext/ffi/ffi.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5356,16 +5356,15 @@ ZEND_INI_END()
53565356

53575357
static zend_result zend_ffi_preload_glob(const char *filename) /* {{{ */
53585358
{
5359-
#ifdef HAVE_GLOB
5360-
glob_t globbuf;
5359+
php_glob_t globbuf;
53615360
int ret;
53625361
unsigned int i;
53635362

5364-
memset(&globbuf, 0, sizeof(glob_t));
5363+
memset(&globbuf, 0, sizeof(globbuf));
53655364

5366-
ret = glob(filename, 0, NULL, &globbuf);
5367-
#ifdef GLOB_NOMATCH
5368-
if (ret == GLOB_NOMATCH || !globbuf.gl_pathc) {
5365+
ret = php_glob(filename, 0, NULL, &globbuf);
5366+
#ifdef PHP_GLOB_NOMATCH
5367+
if (ret == PHP_GLOB_NOMATCH || !globbuf.gl_pathc) {
53695368
#else
53705369
if (!globbuf.gl_pathc) {
53715370
#endif
@@ -5374,20 +5373,13 @@ static zend_result zend_ffi_preload_glob(const char *filename) /* {{{ */
53745373
for(i=0 ; i<globbuf.gl_pathc; i++) {
53755374
zend_ffi *ffi = zend_ffi_load(globbuf.gl_pathv[i], 1);
53765375
if (!ffi) {
5377-
globfree(&globbuf);
5376+
php_globfree(&globbuf);
53785377
return FAILURE;
53795378
}
53805379
efree(ffi);
53815380
}
5382-
globfree(&globbuf);
5381+
php_globfree(&globbuf);
53835382
}
5384-
#else
5385-
zend_ffi *ffi = zend_ffi_load(filename, 1);
5386-
if (!ffi) {
5387-
return FAILURE;
5388-
}
5389-
efree(ffi);
5390-
#endif
53915383

53925384
return SUCCESS;
53935385
}

ext/opcache/zend_accelerator_blacklist.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,15 @@ static void zend_accel_blacklist_loadone(zend_blacklist *blacklist, char *filena
314314

315315
void zend_accel_blacklist_load(zend_blacklist *blacklist, char *filename)
316316
{
317-
#ifdef HAVE_GLOB
318-
glob_t globbuf;
317+
php_glob_t globbuf;
319318
int ret;
320319
unsigned int i;
321320

322-
memset(&globbuf, 0, sizeof(glob_t));
321+
memset(&globbuf, 0, sizeof(globbuf));
323322

324-
ret = glob(filename, 0, NULL, &globbuf);
325-
#ifdef GLOB_NOMATCH
326-
if (ret == GLOB_NOMATCH || !globbuf.gl_pathc) {
323+
ret = php_glob(filename, 0, NULL, &globbuf);
324+
#ifdef PHP_GLOB_NOMATCH
325+
if (ret == PHP_GLOB_NOMATCH || !globbuf.gl_pathc) {
327326
#else
328327
if (!globbuf.gl_pathc) {
329328
#endif
@@ -332,11 +331,8 @@ void zend_accel_blacklist_load(zend_blacklist *blacklist, char *filename)
332331
for(i=0 ; i<globbuf.gl_pathc; i++) {
333332
zend_accel_blacklist_loadone(blacklist, globbuf.gl_pathv[i]);
334333
}
335-
globfree(&globbuf);
334+
php_globfree(&globbuf);
336335
}
337-
#else
338-
zend_accel_blacklist_loadone(blacklist, filename);
339-
#endif
340336
zend_accel_blacklist_update_regexp(blacklist);
341337
}
342338

ext/standard/dir.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ PHP_FUNCTION(readdir)
338338
}
339339
/* }}} */
340340

341-
#ifdef HAVE_GLOB
342341
/* {{{ Find pathnames matching a pattern */
343342
PHP_FUNCTION(glob)
344343
{
@@ -351,7 +350,7 @@ PHP_FUNCTION(glob)
351350
char *pattern = NULL;
352351
size_t pattern_len;
353352
zend_long flags = 0;
354-
glob_t globbuf;
353+
php_glob_t globbuf;
355354
size_t n;
356355
int ret;
357356
bool basedir_limit = 0;
@@ -368,7 +367,7 @@ PHP_FUNCTION(glob)
368367
RETURN_FALSE;
369368
}
370369

371-
if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {
370+
if ((PHP_GLOB_AVAILABLE_FLAGS & flags) != flags) {
372371
php_error_docref(NULL, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform");
373372
RETURN_FALSE;
374373
}
@@ -392,14 +391,14 @@ PHP_FUNCTION(glob)
392391
#endif
393392

394393

395-
memset(&globbuf, 0, sizeof(glob_t));
394+
memset(&globbuf, 0, sizeof(globbuf));
396395
globbuf.gl_offs = 0;
397-
if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) {
398-
#ifdef GLOB_NOMATCH
399-
if (GLOB_NOMATCH == ret) {
396+
if (0 != (ret = php_glob(pattern, flags & PHP_GLOB_FLAGMASK, NULL, &globbuf))) {
397+
#ifdef PHP_GLOB_NOMATCH
398+
if (PHP_GLOB_NOMATCH == ret) {
400399
/* Some glob implementation simply return no data if no matches
401-
were found, others return the GLOB_NOMATCH error code.
402-
We don't want to treat GLOB_NOMATCH as an error condition
400+
were found, others return the PHP_GLOB_NOMATCH error code.
401+
We don't want to treat PHP_GLOB_NOMATCH as an error condition
403402
so that PHP glob() behaves the same on both types of
404403
implementations and so that 'foreach (glob() as ...'
405404
can be used for simple glob() calls without further error
@@ -413,7 +412,7 @@ PHP_FUNCTION(glob)
413412

414413
/* now catch the FreeBSD style of "no matches" */
415414
if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
416-
#ifdef GLOB_NOMATCH
415+
#ifdef PHP_GLOB_NOMATCH
417416
no_results:
418417
#endif
419418
array_init(return_value);
@@ -428,15 +427,15 @@ PHP_FUNCTION(glob)
428427
continue;
429428
}
430429
}
431-
/* we need to do this every time since GLOB_ONLYDIR does not guarantee that
430+
/* we need to do this every time since PHP_GLOB_ONLYDIR does not guarantee that
432431
* all directories will be filtered. GNU libc documentation states the
433432
* following:
434433
* If the information about the type of the file is easily available
435434
* non-directories will be rejected but no extra work will be done to
436435
* determine the information for each file. I.e., the caller must still be
437436
* able to filter directories out.
438437
*/
439-
if (flags & GLOB_ONLYDIR) {
438+
if (flags & PHP_GLOB_ONLYDIR) {
440439
zend_stat_t s = {0};
441440

442441
if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) {
@@ -451,15 +450,14 @@ PHP_FUNCTION(glob)
451450
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp);
452451
}
453452

454-
globfree(&globbuf);
453+
php_globfree(&globbuf);
455454

456455
if (basedir_limit && !zend_hash_num_elements(Z_ARRVAL_P(return_value))) {
457456
zend_array_destroy(Z_ARR_P(return_value));
458457
RETURN_FALSE;
459458
}
460459
}
461460
/* }}} */
462-
#endif
463461

464462
/* {{{ List files & directories inside the specified path */
465463
PHP_FUNCTION(scandir)

ext/standard/dir.stub.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,64 +13,62 @@
1313
*/
1414
const PATH_SEPARATOR = UNKNOWN;
1515

16-
#ifdef HAVE_GLOB
17-
#if (defined(GLOB_BRACE) && GLOB_BRACE != 0)
16+
#if (defined(PHP_GLOB_BRACE) && PHP_GLOB_BRACE != 0)
1817
/**
1918
* @var int
20-
* @cvalue GLOB_BRACE
19+
* @cvalue PHP_GLOB_BRACE
2120
*/
2221
const GLOB_BRACE = UNKNOWN;
2322
#endif
24-
#if (defined(GLOB_ERR) && GLOB_ERR != 0)
23+
#if (defined(PHP_GLOB_ERR) && PHP_GLOB_ERR != 0)
2524
/**
2625
* @var int
27-
* @cvalue GLOB_ERR
26+
* @cvalue PHP_GLOB_ERR
2827
*/
2928
const GLOB_ERR = UNKNOWN;
3029
#endif
31-
#if (defined(GLOB_MARK) && GLOB_MARK != 0)
30+
#if (defined(PHP_GLOB_MARK) && PHP_GLOB_MARK != 0)
3231
/**
3332
* @var int
34-
* @cvalue GLOB_MARK
33+
* @cvalue PHP_GLOB_MARK
3534
*/
3635
const GLOB_MARK = UNKNOWN;
3736
#endif
38-
#if (defined(GLOB_NOCHECK) && GLOB_NOCHECK != 0)
37+
#if (defined(PHP_GLOB_NOCHECK) && PHP_GLOB_NOCHECK != 0)
3938
/**
4039
* @var int
41-
* @cvalue GLOB_NOCHECK
40+
* @cvalue PHP_GLOB_NOCHECK
4241
*/
4342
const GLOB_NOCHECK = UNKNOWN;
4443
#endif
45-
#if (defined(GLOB_NOESCAPE) && GLOB_NOESCAPE != 0)
44+
#if (defined(PHP_GLOB_NOESCAPE) && PHP_GLOB_NOESCAPE != 0)
4645
/**
4746
* @var int
48-
* @cvalue GLOB_NOESCAPE
47+
* @cvalue PHP_GLOB_NOESCAPE
4948
*/
5049
const GLOB_NOESCAPE = UNKNOWN;
5150
#endif
52-
#if (defined(GLOB_NOSORT) && GLOB_NOSORT != 0)
51+
#if (defined(PHP_GLOB_NOSORT) && PHP_GLOB_NOSORT != 0)
5352
/**
5453
* @var int
55-
* @cvalue GLOB_NOSORT
54+
* @cvalue PHP_GLOB_NOSORT
5655
*/
5756
const GLOB_NOSORT = UNKNOWN;
5857
#endif
59-
#ifdef GLOB_ONLYDIR
58+
#ifdef PHP_GLOB_ONLYDIR
6059
/**
6160
* @var int
62-
* @cvalue GLOB_ONLYDIR
61+
* @cvalue PHP_GLOB_ONLYDIR
6362
*/
6463
const GLOB_ONLYDIR = UNKNOWN;
6564
#endif
66-
#ifdef GLOB_AVAILABLE_FLAGS
65+
#ifdef PHP_GLOB_AVAILABLE_FLAGS
6766
/**
6867
* @var int
69-
* @cvalue GLOB_AVAILABLE_FLAGS
68+
* @cvalue PHP_GLOB_AVAILABLE_FLAGS
7069
*/
7170
const GLOB_AVAILABLE_FLAGS = UNKNOWN;
7271
#endif
73-
#endif
7472
/**
7573
* @var int
7674
* @cvalue PHP_SCANDIR_SORT_ASCENDING

ext/standard/dir_arginfo.h

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/php_dir_int.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,6 @@
1919

2020
#include "php_glob.h"
2121

22-
#ifdef HAVE_GLOB
23-
24-
#ifndef GLOB_BRACE
25-
#define GLOB_BRACE 0
26-
#endif
27-
28-
#ifndef GLOB_ERR
29-
#define GLOB_ERR 0
30-
#endif
31-
32-
#ifndef GLOB_MARK
33-
#define GLOB_MARK 0
34-
#endif
35-
36-
#ifndef GLOB_NOCHECK
37-
#define GLOB_NOCHECK 0
38-
#endif
39-
40-
#ifndef GLOB_NOESCAPE
41-
#define GLOB_NOESCAPE 0
42-
#endif
43-
44-
#ifndef GLOB_NOSORT
45-
#define GLOB_NOSORT 0
46-
#endif
47-
48-
#ifndef GLOB_ONLYDIR
49-
#define GLOB_ONLYDIR (1<<30)
50-
#define GLOB_EMULATE_ONLYDIR
51-
#define GLOB_FLAGMASK (~GLOB_ONLYDIR)
52-
#else
53-
#define GLOB_FLAGMASK (~0)
54-
#endif
55-
56-
/* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
57-
#define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
58-
59-
#endif /* HAVE_GLOB */
60-
6122
char dirsep_str[2], pathsep_str[2];
6223

6324
#endif /* PHP_DIR_INT_H */

0 commit comments

Comments
 (0)