Skip to content

Commit 7e6301c

Browse files
authored
Declare ext/iconv constants in stubs (#8714)
1 parent e7d482d commit 7e6301c

File tree

3 files changed

+58
-29
lines changed

3 files changed

+58
-29
lines changed

ext/iconv/iconv.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@
4747
#include "zend_smart_str.h"
4848
#include "ext/standard/base64.h"
4949
#include "ext/standard/quot_print.h"
50+
51+
#ifdef PHP_ICONV_IMPL
52+
#define PHP_ICONV_IMPL_VALUE PHP_ICONV_IMPL
53+
#elif HAVE_LIBICONV
54+
#define PHP_ICONV_IMPL_VALUE "libiconv"
55+
#else
56+
#define PHP_ICONV_IMPL_VALUE "unknown"
57+
#endif
58+
59+
char *get_iconv_version(void) {
60+
char *version = "unknown";
61+
62+
#ifdef HAVE_LIBICONV
63+
static char buf[16];
64+
snprintf(buf, sizeof(buf), "%d.%d", _libiconv_version >> 8, _libiconv_version & 0xff);
65+
version = buf;
66+
#elif HAVE_GLIBC_ICONV
67+
version = (char *) gnu_get_libc_version();
68+
#endif
69+
70+
return version;
71+
}
72+
73+
#define PHP_ICONV_MIME_DECODE_STRICT (1<<0)
74+
#define PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR (1<<1)
75+
5076
#include "iconv_arginfo.h"
5177

5278
#define _php_iconv_memequal(a, b, c) \
@@ -104,9 +130,6 @@ typedef enum _php_iconv_enc_scheme_t {
104130
} php_iconv_enc_scheme_t;
105131
/* }}} */
106132

107-
#define PHP_ICONV_MIME_DECODE_STRICT (1<<0)
108-
#define PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR (1<<1)
109-
110133
/* {{{ prototypes */
111134
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd);
112135
static php_iconv_err_t _php_iconv_appendc(smart_str *d, const char c, iconv_t cd);
@@ -186,37 +209,14 @@ PHP_INI_END()
186209
/* {{{ PHP_MINIT_FUNCTION */
187210
PHP_MINIT_FUNCTION(miconv)
188211
{
189-
char *version = "unknown";
190-
191212
REGISTER_INI_ENTRIES();
192213

193-
#ifdef HAVE_LIBICONV
194-
{
195-
static char buf[16];
196-
snprintf(buf, sizeof(buf), "%d.%d",
197-
_libiconv_version >> 8, _libiconv_version & 0xff);
198-
version = buf;
199-
}
200-
#elif HAVE_GLIBC_ICONV
201-
version = (char *)gnu_get_libc_version();
202-
#endif
203-
204-
#ifdef PHP_ICONV_IMPL
205-
REGISTER_STRING_CONSTANT("ICONV_IMPL", PHP_ICONV_IMPL, CONST_CS | CONST_PERSISTENT);
206-
#elif HAVE_LIBICONV
207-
REGISTER_STRING_CONSTANT("ICONV_IMPL", "libiconv", CONST_CS | CONST_PERSISTENT);
208-
#else
209-
REGISTER_STRING_CONSTANT("ICONV_IMPL", "unknown", CONST_CS | CONST_PERSISTENT);
210-
#endif
211-
REGISTER_STRING_CONSTANT("ICONV_VERSION", version, CONST_CS | CONST_PERSISTENT);
212-
213-
REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_STRICT", PHP_ICONV_MIME_DECODE_STRICT, CONST_CS | CONST_PERSISTENT);
214-
REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_CONTINUE_ON_ERROR", PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR, CONST_CS | CONST_PERSISTENT);
215-
216214
if (php_iconv_stream_filter_register_factory() != PHP_ICONV_ERR_SUCCESS) {
217215
return FAILURE;
218216
}
219217

218+
register_iconv_symbols(module_number);
219+
220220
php_output_handler_alias_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_handler_init);
221221
php_output_handler_conflict_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_conflict);
222222

ext/iconv/iconv.stub.php

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

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

5+
/**
6+
* @var string
7+
* @cname PHP_ICONV_IMPL_VALUE
8+
*/
9+
const ICONV_IMPL = UNKNOWN;
10+
/**
11+
* @var string
12+
* @cname get_iconv_version()
13+
*/
14+
const ICONV_VERSION = UNKNOWN;
15+
/**
16+
* @var int
17+
* @cname PHP_ICONV_MIME_DECODE_STRICT
18+
*/
19+
const ICONV_MIME_DECODE_STRICT = UNKNOWN;
20+
/**
21+
* @var int
22+
* @cname PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR
23+
*/
24+
const ICONV_MIME_DECODE_CONTINUE_ON_ERROR = UNKNOWN;
25+
526
function iconv_strlen(string $string, ?string $encoding = null): int|false {}
627

728
/** @refcount 1 */

ext/iconv/iconv_arginfo.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: c7198f92b39f7a15d242a74ed5f42036f858da2e */
2+
* Stub hash: 3df53b4f973d99fe56dd3b95128ab9b49027376a */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strlen, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
@@ -85,3 +85,11 @@ static const zend_function_entry ext_functions[] = {
8585
ZEND_FE(iconv_get_encoding, arginfo_iconv_get_encoding)
8686
ZEND_FE_END
8787
};
88+
89+
static void register_iconv_symbols(int module_number)
90+
{
91+
REGISTER_STRING_CONSTANT("ICONV_IMPL", PHP_ICONV_IMPL_VALUE, CONST_CS | CONST_PERSISTENT);
92+
REGISTER_STRING_CONSTANT("ICONV_VERSION", get_iconv_version(), CONST_CS | CONST_PERSISTENT);
93+
REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_STRICT", PHP_ICONV_MIME_DECODE_STRICT, CONST_CS | CONST_PERSISTENT);
94+
REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_CONTINUE_ON_ERROR", PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR, CONST_CS | CONST_PERSISTENT);
95+
}

0 commit comments

Comments
 (0)