Skip to content

Commit e957e25

Browse files
authored
Move constants from dir.c to stub file (#13312)
1 parent 5941cda commit e957e25

File tree

4 files changed

+174
-68
lines changed

4 files changed

+174
-68
lines changed

ext/standard/dir.c

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "fopen_wrappers.h"
2121
#include "file.h"
2222
#include "php_dir.h"
23+
#include "php_dir_int.h"
2324
#include "php_string.h"
2425
#include "php_scandir.h"
2526
#include "basic_functions.h"
@@ -35,15 +36,6 @@
3536
#include "win32/readdir.h"
3637
#endif
3738

38-
39-
#ifdef HAVE_GLOB
40-
#ifndef PHP_WIN32
41-
#include <glob.h>
42-
#else
43-
#include "win32/glob.h"
44-
#endif
45-
#endif
46-
4739
typedef struct {
4840
zend_resource *default_dir;
4941
} php_dir_globals;
@@ -117,6 +109,8 @@ PHP_MINIT_FUNCTION(dir)
117109
{
118110
static char dirsep_str[2], pathsep_str[2];
119111

112+
register_dir_symbols(module_number);
113+
120114
dir_class_entry_ptr = register_class_Directory();
121115

122116
#ifdef ZTS
@@ -131,64 +125,6 @@ PHP_MINIT_FUNCTION(dir)
131125
pathsep_str[1] = '\0';
132126
REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_PERSISTENT);
133127

134-
REGISTER_LONG_CONSTANT("SCANDIR_SORT_ASCENDING", PHP_SCANDIR_SORT_ASCENDING, CONST_PERSISTENT);
135-
REGISTER_LONG_CONSTANT("SCANDIR_SORT_DESCENDING", PHP_SCANDIR_SORT_DESCENDING, CONST_PERSISTENT);
136-
REGISTER_LONG_CONSTANT("SCANDIR_SORT_NONE", PHP_SCANDIR_SORT_NONE, CONST_PERSISTENT);
137-
138-
#ifdef HAVE_GLOB
139-
140-
#ifdef GLOB_BRACE
141-
REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_PERSISTENT);
142-
#else
143-
# define GLOB_BRACE 0
144-
#endif
145-
146-
#ifdef GLOB_MARK
147-
REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_PERSISTENT);
148-
#else
149-
# define GLOB_MARK 0
150-
#endif
151-
152-
#ifdef GLOB_NOSORT
153-
REGISTER_LONG_CONSTANT("GLOB_NOSORT", GLOB_NOSORT, CONST_PERSISTENT);
154-
#else
155-
# define GLOB_NOSORT 0
156-
#endif
157-
158-
#ifdef GLOB_NOCHECK
159-
REGISTER_LONG_CONSTANT("GLOB_NOCHECK", GLOB_NOCHECK, CONST_PERSISTENT);
160-
#else
161-
# define GLOB_NOCHECK 0
162-
#endif
163-
164-
#ifdef GLOB_NOESCAPE
165-
REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_PERSISTENT);
166-
#else
167-
# define GLOB_NOESCAPE 0
168-
#endif
169-
170-
#ifdef GLOB_ERR
171-
REGISTER_LONG_CONSTANT("GLOB_ERR", GLOB_ERR, CONST_PERSISTENT);
172-
#else
173-
# define GLOB_ERR 0
174-
#endif
175-
176-
#ifndef GLOB_ONLYDIR
177-
# define GLOB_ONLYDIR (1<<30)
178-
# define GLOB_EMULATE_ONLYDIR
179-
# define GLOB_FLAGMASK (~GLOB_ONLYDIR)
180-
#else
181-
# define GLOB_FLAGMASK (~0)
182-
#endif
183-
184-
/* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
185-
#define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
186-
187-
REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_PERSISTENT);
188-
REGISTER_LONG_CONSTANT("GLOB_AVAILABLE_FLAGS", GLOB_AVAILABLE_FLAGS, CONST_PERSISTENT);
189-
190-
#endif /* HAVE_GLOB */
191-
192128
return SUCCESS;
193129
}
194130
/* }}} */

ext/standard/dir.stub.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,80 @@
22

33
/** @generate-class-entries */
44

5+
#ifdef HAVE_GLOB
6+
#if (defined(GLOB_BRACE) && GLOB_BRACE != 0)
7+
/**
8+
* @var int
9+
* @cvalue GLOB_BRACE
10+
*/
11+
const GLOB_BRACE = UNKNOWN;
12+
#endif
13+
#if (defined(GLOB_ERR) && GLOB_ERR != 0)
14+
/**
15+
* @var int
16+
* @cvalue GLOB_ERR
17+
*/
18+
const GLOB_ERR = UNKNOWN;
19+
#endif
20+
#if (defined(GLOB_MARK) && GLOB_MARK != 0)
21+
/**
22+
* @var int
23+
* @cvalue GLOB_MARK
24+
*/
25+
const GLOB_MARK = UNKNOWN;
26+
#endif
27+
#if (defined(GLOB_NOCHECK) && GLOB_NOCHECK != 0)
28+
/**
29+
* @var int
30+
* @cvalue GLOB_NOCHECK
31+
*/
32+
const GLOB_NOCHECK = UNKNOWN;
33+
#endif
34+
#if (defined(GLOB_NOESCAPE) && GLOB_NOESCAPE != 0)
35+
/**
36+
* @var int
37+
* @cvalue GLOB_NOESCAPE
38+
*/
39+
const GLOB_NOESCAPE = UNKNOWN;
40+
#endif
41+
#if (defined(GLOB_NOSORT) && GLOB_NOSORT != 0)
42+
/**
43+
* @var int
44+
* @cvalue GLOB_NOSORT
45+
*/
46+
const GLOB_NOSORT = UNKNOWN;
47+
#endif
48+
#ifdef GLOB_ONLYDIR
49+
/**
50+
* @var int
51+
* @cvalue GLOB_ONLYDIR
52+
*/
53+
const GLOB_ONLYDIR = UNKNOWN;
54+
#endif
55+
#ifdef GLOB_AVAILABLE_FLAGS
56+
/**
57+
* @var int
58+
* @cvalue GLOB_AVAILABLE_FLAGS
59+
*/
60+
const GLOB_AVAILABLE_FLAGS = UNKNOWN;
61+
#endif
62+
#endif
63+
/**
64+
* @var int
65+
* @cvalue PHP_SCANDIR_SORT_ASCENDING
66+
*/
67+
const SCANDIR_SORT_ASCENDING = UNKNOWN;
68+
/**
69+
* @var int
70+
* @cvalue PHP_SCANDIR_SORT_DESCENDING
71+
*/
72+
const SCANDIR_SORT_DESCENDING = UNKNOWN;
73+
/**
74+
* @var int
75+
* @cvalue PHP_SCANDIR_SORT_NONE
76+
*/
77+
const SCANDIR_SORT_NONE = UNKNOWN;
78+
579
class Directory
680
{
781
public readonly string $path;

ext/standard/dir_arginfo.h

Lines changed: 32 additions & 1 deletion
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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.01 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| https://www.php.net/license/3_01.txt |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| license@php.net so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
*/
14+
15+
#ifndef PHP_DIR_INT_H
16+
#define PHP_DIR_INT_H
17+
18+
#ifdef HAVE_GLOB
19+
#ifndef PHP_WIN32
20+
#include <glob.h>
21+
#else
22+
#include "win32/glob.h"
23+
#endif
24+
#endif
25+
26+
#ifdef HAVE_GLOB
27+
28+
#ifndef GLOB_BRACE
29+
#define GLOB_BRACE 0
30+
#endif
31+
32+
#ifndef GLOB_ERR
33+
#define GLOB_ERR 0
34+
#endif
35+
36+
#ifndef GLOB_MARK
37+
#define GLOB_MARK 0
38+
#endif
39+
40+
#ifndef GLOB_NOCHECK
41+
#define GLOB_NOCHECK 0
42+
#endif
43+
44+
#ifndef GLOB_NOESCAPE
45+
#define GLOB_NOESCAPE 0
46+
#endif
47+
48+
#ifndef GLOB_NOSORT
49+
#define GLOB_NOSORT 0
50+
#endif
51+
52+
#ifndef GLOB_ONLYDIR
53+
#define GLOB_ONLYDIR (1<<30)
54+
#define GLOB_EMULATE_ONLYDIR
55+
#define GLOB_FLAGMASK (~GLOB_ONLYDIR)
56+
#else
57+
#define GLOB_FLAGMASK (~0)
58+
#endif
59+
60+
/* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
61+
#define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
62+
63+
#endif /* HAVE_GLOB */
64+
65+
#endif /* PHP_DIR_INT_H */

0 commit comments

Comments
 (0)