Skip to content

Commit e06836a

Browse files
committed
Remove checks for locale.h, setlocale, localeconv
The `<loccale.h>` header file, setlocale, and localeconv are part of the standard C89 [1] and on current systems can be used unconditionally. Since PHP 7.4 requires at least C89 or greater, the `HAVE_LOCALE_H`, `HAVE_SETLOCALE`, and `HAVE_LOCALECONV` symbols defined by Autoconf in configure.ac [2] can be ommitted and simplifed. The bundled libmagic (file) has also been patched already in version 5.35 and up in upstream location so when it will be patched also in php-src the check for locale.h header is still left in the configure.ac and in windows headers definition file. [1] https://port70.net/~nsz/c/c89/c89-draft.html#4.4 [2] https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/headers.m4 Omit the bundled libmagic files
1 parent 5f89157 commit e06836a

File tree

20 files changed

+19
-163
lines changed

20 files changed

+19
-163
lines changed

Zend/zend_operators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ ZEND_API void ZEND_FASTCALL zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_D
451451
convert_scalar_to_number(pzv); \
452452
}
453453

454-
#if HAVE_SETLOCALE && defined(ZEND_WIN32) && !defined(ZTS) && defined(_MSC_VER)
454+
#if defined(ZEND_WIN32) && !defined(ZTS) && defined(_MSC_VER)
455455
/* This performance improvement of tolower() on Windows gives 10-18% on bench.php */
456456
#define ZEND_USE_TOLOWER_L 1
457457
#endif

configure.ac

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,6 @@ random \
628628
rand_r \
629629
scandir \
630630
setitimer \
631-
setlocale \
632-
localeconv \
633631
setenv \
634632
setpgid \
635633
setsockopt \

ext/pcre/php_pcre.c

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,13 @@ static MUTEX_T pcre_mt = NULL;
9494
#define php_pcre_mutex_unlock()
9595
#endif
9696

97-
#if HAVE_SETLOCALE
9897
ZEND_TLS HashTable char_tables;
9998

10099
static void php_pcre_free_char_table(zval *data)
101100
{/*{{{*/
102101
void *ptr = Z_PTR_P(data);
103102
pefree(ptr, 1);
104103
}/*}}}*/
105-
#endif
106104

107105
static void pcre_handle_exec_error(int pcre_code) /* {{{ */
108106
{
@@ -271,9 +269,7 @@ static PHP_GINIT_FUNCTION(pcre) /* {{{ */
271269
#endif
272270

273271
php_pcre_init_pcre2(1);
274-
#if HAVE_SETLOCALE
275272
zend_hash_init(&char_tables, 1, NULL, php_pcre_free_char_table, 1);
276-
#endif
277273
}
278274
/* }}} */
279275

@@ -284,10 +280,7 @@ static PHP_GSHUTDOWN_FUNCTION(pcre) /* {{{ */
284280
}
285281

286282
php_pcre_shutdown_pcre2();
287-
#if HAVE_SETLOCALE
288283
zend_hash_destroy(&char_tables);
289-
#endif
290-
291284
php_pcre_mutex_free();
292285
}
293286
/* }}} */
@@ -578,36 +571,29 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
578571
char *pattern;
579572
size_t pattern_len;
580573
uint32_t poptions = 0;
581-
#if HAVE_SETLOCALE
582574
const uint8_t *tables = NULL;
583-
#endif
584575
zval *zv;
585576
pcre_cache_entry new_entry;
586577
int rc;
587578
zend_string *key;
588579
pcre_cache_entry *ret;
589580

590-
#if HAVE_SETLOCALE
591581
if (BG(locale_string) &&
592582
(ZSTR_LEN(BG(locale_string)) != 1 && ZSTR_VAL(BG(locale_string))[0] != 'C')) {
593583
key = zend_string_alloc(ZSTR_LEN(regex) + ZSTR_LEN(BG(locale_string)) + 1, 0);
594584
memcpy(ZSTR_VAL(key), ZSTR_VAL(BG(locale_string)), ZSTR_LEN(BG(locale_string)) + 1);
595585
memcpy(ZSTR_VAL(key) + ZSTR_LEN(BG(locale_string)), ZSTR_VAL(regex), ZSTR_LEN(regex) + 1);
596-
} else
597-
#endif
598-
{
586+
} else {
599587
key = regex;
600588
}
601589

602590
/* Try to lookup the cached regex entry, and if successful, just pass
603591
back the compiled pattern, otherwise go on and compile it. */
604592
zv = zend_hash_find(&PCRE_G(pcre_cache), key);
605593
if (zv) {
606-
#if HAVE_SETLOCALE
607594
if (key != regex) {
608595
zend_string_release_ex(key, 0);
609596
}
610-
#endif
611597
return (pcre_cache_entry*)Z_PTR_P(zv);
612598
}
613599

@@ -617,11 +603,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
617603
get to the end without encountering a delimiter. */
618604
while (isspace((int)*(unsigned char *)p)) p++;
619605
if (*p == 0) {
620-
#if HAVE_SETLOCALE
621606
if (key != regex) {
622607
zend_string_release_ex(key, 0);
623608
}
624-
#endif
625609
php_error_docref(NULL, E_WARNING,
626610
p < ZSTR_VAL(regex) + ZSTR_LEN(regex) ? "Null byte in regex" : "Empty regular expression");
627611
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
@@ -632,11 +616,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
632616
or a backslash. */
633617
delimiter = *p++;
634618
if (isalnum((int)*(unsigned char *)&delimiter) || delimiter == '\\') {
635-
#if HAVE_SETLOCALE
636619
if (key != regex) {
637620
zend_string_release_ex(key, 0);
638621
}
639-
#endif
640622
php_error_docref(NULL,E_WARNING, "Delimiter must not be alphanumeric or backslash");
641623
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
642624
return NULL;
@@ -677,11 +659,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
677659
}
678660

679661
if (*pp == 0) {
680-
#if HAVE_SETLOCALE
681662
if (key != regex) {
682663
zend_string_release_ex(key, 0);
683664
}
684-
#endif
685665
if (pp < ZSTR_VAL(regex) + ZSTR_LEN(regex)) {
686666
php_error_docref(NULL,E_WARNING, "Null byte in regex");
687667
} else if (start_delimiter == end_delimiter) {
@@ -742,11 +722,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
742722
}
743723
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
744724
efree(pattern);
745-
#if HAVE_SETLOCALE
746725
if (key != regex) {
747726
zend_string_release_ex(key, 0);
748727
}
749-
#endif
750728
return NULL;
751729
}
752730
}
@@ -755,15 +733,12 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
755733
php_error_docref(NULL, E_WARNING, "The /e modifier is no longer supported, use preg_replace_callback instead");
756734
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
757735
efree(pattern);
758-
#if HAVE_SETLOCALE
759736
if (key != regex) {
760737
zend_string_release_ex(key, 0);
761738
}
762-
#endif
763739
return NULL;
764740
}
765741

766-
#if HAVE_SETLOCALE
767742
if (key != regex) {
768743
tables = (uint8_t *)zend_hash_find_ptr(&char_tables, BG(locale_string));
769744
if (!tables) {
@@ -782,7 +757,6 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
782757
}
783758
pcre2_set_character_tables(cctx, tables);
784759
}
785-
#endif
786760

787761
/* Set extra options for the compile context. */
788762
if (PHP_PCRE_DEFAULT_EXTRA_COPTIONS != extra_coptions) {
@@ -798,11 +772,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
798772
}
799773

800774
if (re == NULL) {
801-
#if HAVE_SETLOCALE
802775
if (key != regex) {
803776
zend_string_release_ex(key, 0);
804777
}
805-
#endif
806778
pcre2_get_error_message(errnumber, error, sizeof(error));
807779
php_error_docref(NULL,E_WARNING, "Compilation failed: %s at offset %zu", error, erroffset);
808780
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
@@ -847,23 +819,19 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
847819

848820
rc = pcre2_pattern_info(re, PCRE2_INFO_CAPTURECOUNT, &new_entry.capture_count);
849821
if (rc < 0) {
850-
#if HAVE_SETLOCALE
851822
if (key != regex) {
852823
zend_string_release_ex(key, 0);
853824
}
854-
#endif
855825
php_error_docref(NULL, E_WARNING, "Internal pcre2_pattern_info() error %d", rc);
856826
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
857827
return NULL;
858828
}
859829

860830
rc = pcre2_pattern_info(re, PCRE2_INFO_NAMECOUNT, &new_entry.name_count);
861831
if (rc < 0) {
862-
#if HAVE_SETLOCALE
863832
if (key != regex) {
864833
zend_string_release_ex(key, 0);
865834
}
866-
#endif
867835
php_error_docref(NULL, E_WARNING, "Internal pcre_pattern_info() error %d", rc);
868836
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
869837
return NULL;
@@ -887,11 +855,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
887855
ret = zend_hash_add_new_mem(&PCRE_G(pcre_cache), key, &new_entry, sizeof(pcre_cache_entry));
888856
}
889857

890-
#if HAVE_SETLOCALE
891858
if (key != regex) {
892859
zend_string_release_ex(key, 0);
893860
}
894-
#endif
895861

896862
return ret;
897863
}

ext/pcre/php_pcre.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#include "pcre2.h"
2626
#endif
2727

28-
#if HAVE_LOCALE_H
2928
#include <locale.h>
30-
#endif
3129

3230
PHPAPI zend_string *php_pcre_replace(zend_string *regex, zend_string *subject_str, char *subject, size_t subject_len, zend_string *replace_str, size_t limit, size_t *replace_count);
3331
PHPAPI pcre2_code* pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count);

ext/readline/readline_cli.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
#include "zend_modules.h"
3434

3535
#include "SAPI.h"
36-
37-
#if HAVE_SETLOCALE
3836
#include <locale.h>
39-
#endif
4037
#include "zend.h"
4138
#include "zend_extensions.h"
4239
#include "php_ini.h"

ext/standard/basic_functions.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
7676
#endif
7777

7878
#include <string.h>
79-
80-
#if HAVE_LOCALE_H
81-
# include <locale.h>
82-
#endif
79+
#include <locale.h>
8380

8481
#if HAVE_SYS_MMAN_H
8582
# include <sys/mman.h>
@@ -3685,7 +3682,7 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */
36853682
BASIC_MINIT_SUBMODULE(password)
36863683
BASIC_MINIT_SUBMODULE(mt_rand)
36873684

3688-
#if defined(HAVE_LOCALECONV) && defined(ZTS)
3685+
#if defined(ZTS)
36893686
BASIC_MINIT_SUBMODULE(localeconv)
36903687
#endif
36913688

@@ -3769,7 +3766,7 @@ PHP_MSHUTDOWN_FUNCTION(basic) /* {{{ */
37693766
BASIC_MSHUTDOWN_SUBMODULE(url_scanner_ex)
37703767
BASIC_MSHUTDOWN_SUBMODULE(file)
37713768
BASIC_MSHUTDOWN_SUBMODULE(standard_filters)
3772-
#if defined(HAVE_LOCALECONV) && defined(ZTS)
3769+
#if defined(ZTS)
37733770
BASIC_MSHUTDOWN_SUBMODULE(localeconv)
37743771
#endif
37753772
BASIC_MSHUTDOWN_SUBMODULE(crypt)

ext/standard/formatted_print.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@
2323
#include "zend_execute.h"
2424
#include <stdio.h>
2525

26-
#ifdef HAVE_LOCALE_H
2726
#include <locale.h>
2827
#ifdef ZTS
2928
#include "ext/standard/php_string.h"
3029
#define LCONV_DECIMAL_POINT (*lconv.decimal_point)
3130
#else
3231
#define LCONV_DECIMAL_POINT (*lconv->decimal_point)
3332
#endif
34-
#else
35-
#define LCONV_DECIMAL_POINT '.'
36-
#endif
3733

3834
#define ALIGN_LEFT 0
3935
#define ALIGN_RIGHT 1
@@ -232,12 +228,10 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos,
232228
char *s = NULL;
233229
size_t s_len = 0;
234230
int is_negative = 0;
235-
#ifdef HAVE_LOCALE_H
236231
#ifdef ZTS
237232
struct lconv lconv;
238233
#else
239234
struct lconv *lconv;
240-
#endif
241235
#endif
242236

243237
PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n",
@@ -268,12 +262,10 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos,
268262
case 'E':
269263
case 'f':
270264
case 'F':
271-
#ifdef HAVE_LOCALE_H
272265
#ifdef ZTS
273266
localeconv_r(&lconv);
274267
#else
275268
lconv = localeconv();
276-
#endif
277269
#endif
278270
s = php_conv_fp((fmt == 'f')?'F':fmt, number, 0, precision,
279271
(fmt == 'f')?LCONV_DECIMAL_POINT:'.',
@@ -296,12 +288,10 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos,
296288
/*
297289
* * We use &num_buf[ 1 ], so that we have room for the sign
298290
*/
299-
#ifdef HAVE_LOCALE_H
300291
#ifdef ZTS
301292
localeconv_r(&lconv);
302293
#else
303294
lconv = localeconv();
304-
#endif
305295
#endif
306296
s = php_gcvt(number, precision, LCONV_DECIMAL_POINT, (fmt == 'G')?'E':'e', &num_buf[1]);
307297
is_negative = 0;

ext/standard/html.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
#include "php_standard.h"
4646
#include "php_string.h"
4747
#include "SAPI.h"
48-
#if HAVE_LOCALE_H
4948
#include <locale.h>
50-
#endif
5149
#if HAVE_LANGINFO_H
5250
#include <langinfo.h>
5351
#endif
@@ -408,14 +406,13 @@ static enum entity_charset determine_charset(char *charset_hint)
408406
}
409407

410408
/* try to detect the charset for the locale */
411-
#if HAVE_NL_LANGINFO && HAVE_LOCALE_H && defined(CODESET)
409+
#if HAVE_NL_LANGINFO && defined(CODESET)
412410
charset_hint = nl_langinfo(CODESET);
413411
if (charset_hint != NULL && (len=strlen(charset_hint)) != 0) {
414412
goto det_charset;
415413
}
416414
#endif
417415

418-
#if HAVE_LOCALE_H
419416
/* try to figure out the charset from the locale */
420417
{
421418
char *localename;
@@ -441,7 +438,6 @@ static enum entity_charset determine_charset(char *charset_hint)
441438
len = strlen(charset_hint);
442439
}
443440
}
444-
#endif
445441

446442
det_charset:
447443

ext/standard/php_string.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ PHP_FUNCTION(strcoll);
9898
PHP_FUNCTION(money_format);
9999
#endif
100100

101-
#if defined(HAVE_LOCALECONV) && defined(ZTS)
101+
#if defined(ZTS)
102102
PHP_MINIT_FUNCTION(localeconv);
103103
PHP_MSHUTDOWN_FUNCTION(localeconv);
104104
#endif
@@ -114,11 +114,7 @@ PHP_MINIT_FUNCTION(string_intrin);
114114
#define strnatcasecmp(a, b) \
115115
strnatcmp_ex(a, strlen(a), b, strlen(b), 1)
116116
PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len, int fold_case);
117-
118-
#ifdef HAVE_LOCALECONV
119117
PHPAPI struct lconv *localeconv_r(struct lconv *out);
120-
#endif
121-
122118
PHPAPI char *php_strtoupper(char *s, size_t len);
123119
PHPAPI char *php_strtolower(char *s, size_t len);
124120
PHPAPI zend_string *php_string_toupper(zend_string *s);

ext/standard/scanf.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@
6868
#include <ctype.h>
6969
#include "php.h"
7070
#include "php_variables.h"
71-
#ifdef HAVE_LOCALE_H
7271
#include <locale.h>
73-
#endif
7472
#include "zend_execute.h"
7573
#include "zend_operators.h"
7674
#include "zend_strtod.h"

0 commit comments

Comments
 (0)