Skip to content

Declare ext/iconv constants in stubs #8714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@
#include "zend_smart_str.h"
#include "ext/standard/base64.h"
#include "ext/standard/quot_print.h"

#ifdef PHP_ICONV_IMPL
#define PHP_ICONV_IMPL_VALUE PHP_ICONV_IMPL
#elif HAVE_LIBICONV
#define PHP_ICONV_IMPL_VALUE "libiconv"
#else
#define PHP_ICONV_IMPL_VALUE "unknown"
#endif

char *get_iconv_version(void) {
char *version = "unknown";

#ifdef HAVE_LIBICONV
static char buf[16];
snprintf(buf, sizeof(buf), "%d.%d", _libiconv_version >> 8, _libiconv_version & 0xff);
version = buf;
#elif HAVE_GLIBC_ICONV
version = (char *) gnu_get_libc_version();
#endif

return version;
}

#define PHP_ICONV_MIME_DECODE_STRICT (1<<0)
#define PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR (1<<1)

#include "iconv_arginfo.h"

#define _php_iconv_memequal(a, b, c) \
Expand Down Expand Up @@ -104,9 +130,6 @@ typedef enum _php_iconv_enc_scheme_t {
} php_iconv_enc_scheme_t;
/* }}} */

#define PHP_ICONV_MIME_DECODE_STRICT (1<<0)
#define PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR (1<<1)

/* {{{ prototypes */
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd);
static php_iconv_err_t _php_iconv_appendc(smart_str *d, const char c, iconv_t cd);
Expand Down Expand Up @@ -186,37 +209,14 @@ PHP_INI_END()
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(miconv)
{
char *version = "unknown";

REGISTER_INI_ENTRIES();

#ifdef HAVE_LIBICONV
{
static char buf[16];
snprintf(buf, sizeof(buf), "%d.%d",
_libiconv_version >> 8, _libiconv_version & 0xff);
version = buf;
}
#elif HAVE_GLIBC_ICONV
version = (char *)gnu_get_libc_version();
#endif

#ifdef PHP_ICONV_IMPL
REGISTER_STRING_CONSTANT("ICONV_IMPL", PHP_ICONV_IMPL, CONST_CS | CONST_PERSISTENT);
#elif HAVE_LIBICONV
REGISTER_STRING_CONSTANT("ICONV_IMPL", "libiconv", CONST_CS | CONST_PERSISTENT);
#else
REGISTER_STRING_CONSTANT("ICONV_IMPL", "unknown", CONST_CS | CONST_PERSISTENT);
#endif
REGISTER_STRING_CONSTANT("ICONV_VERSION", version, CONST_CS | CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_STRICT", PHP_ICONV_MIME_DECODE_STRICT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_CONTINUE_ON_ERROR", PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR, CONST_CS | CONST_PERSISTENT);

if (php_iconv_stream_filter_register_factory() != PHP_ICONV_ERR_SUCCESS) {
return FAILURE;
}

register_iconv_symbols(module_number);

php_output_handler_alias_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_handler_init);
php_output_handler_conflict_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_conflict);

Expand Down
21 changes: 21 additions & 0 deletions ext/iconv/iconv.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

/** @generate-class-entries */

/**
* @var string
* @cname PHP_ICONV_IMPL_VALUE
*/
const ICONV_IMPL = UNKNOWN;
/**
* @var string
* @cname get_iconv_version()
*/
const ICONV_VERSION = UNKNOWN;
/**
* @var int
* @cname PHP_ICONV_MIME_DECODE_STRICT
*/
const ICONV_MIME_DECODE_STRICT = UNKNOWN;
/**
* @var int
* @cname PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR
*/
const ICONV_MIME_DECODE_CONTINUE_ON_ERROR = UNKNOWN;

function iconv_strlen(string $string, ?string $encoding = null): int|false {}

/** @refcount 1 */
Expand Down
10 changes: 9 additions & 1 deletion ext/iconv/iconv_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: c7198f92b39f7a15d242a74ed5f42036f858da2e */
* Stub hash: 3df53b4f973d99fe56dd3b95128ab9b49027376a */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strlen, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
Expand Down Expand Up @@ -85,3 +85,11 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(iconv_get_encoding, arginfo_iconv_get_encoding)
ZEND_FE_END
};

static void register_iconv_symbols(int module_number)
{
REGISTER_STRING_CONSTANT("ICONV_IMPL", PHP_ICONV_IMPL_VALUE, CONST_CS | CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("ICONV_VERSION", get_iconv_version(), CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_STRICT", PHP_ICONV_MIME_DECODE_STRICT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_CONTINUE_ON_ERROR", PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR, CONST_CS | CONST_PERSISTENT);
}