Commit graph

345 commits

Author SHA1 Message Date
Nikita Popov
1cba7764b4
Remove zend_atoi() (#7232)
It's the same as (int) zend_atol() -- it doesn't try to do anything
integer size specific. Canonicalize to one function in preparation
for renaming zend_atol() to something less misleading.

FFI test is adjusted to use a zend_test function. It just calls
zend_atol() internally, but could really be anything.

Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2021-07-13 09:22:31 +02:00
Nikita Popov
821a5a1239 Drop fast_div_function
This is the same as div_function nowadays.
2021-06-14 11:32:28 +02:00
George Peter Banyard
b6958bb847
Implement "Deprecate implicit non-integer-compatible float to int conversions" RFC. (#6661)
RFC: https://wiki.php.net/rfc/implicit-float-int-deprecate

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-05-31 15:48:45 +01:00
Nikita Popov
0c5711856f Add zend_ulong_to_str() API
No point in going through a smart_str and append_unsigned if we
can construct the result directly...
2021-04-13 15:56:24 +02:00
Nikita Popov
65a5c184d7 Add functions to convert i64/u64 to string
PDO implement half of this, but this functionality is generally
useful. Provide these as zend_u64_to_str and zend_i64_to_str to
complement zend_long_to_str.
2021-04-13 15:43:23 +02:00
Dmitry Stogov
5e01542526 Improve basename(). Avoid calling mblen() for ASCII compatible locales. 2021-02-19 15:42:21 +03:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
Nikita Popov
16cf1b915d compare_function() returns zend_result 2021-01-15 11:51:28 +01:00
Nikita Popov
058756b3bb Remove the convert_to_long_base function
This function is unused in php-src, and has somewhat dubious
semantics, especially since we switched convert_to_long to not
use strtol for the base 10 case.

If you want to convert strings from a different base, use
ZEND_STRTOL directly.
2021-01-15 10:43:26 +01:00
Nikita Popov
b429228420 Remove zend_locale_sprintf_double()
This function is unused, and also not particularly useful now that
PHP no longer prints doubles in a locale-sensitive way unless
someone really goes out of their way to force it.
2021-01-14 12:13:34 +01:00
Nikita Popov
422d1665a2 Make convert_to_*_ex simple aliases of convert_to_*
Historically, the _ex variants separated the zval first, if a
conversion was necessary. This distinction no longer makes sense
since PHP 7.

The only difference that was still left is that _ex checked whether
the type is the same first, but the usage of these macros did not
actually distinguish on whether such an inlined check is valuable
or not in a given context.

Also drop the unused convert_to_explicit_type macros.
2021-01-14 12:11:11 +01:00
George Peter Banyard
fa8d9b1183 Improve type declarations for Zend APIs
Voidification of Zend API which always succeeded
Use bool argument types instead of int for boolean arguments
Use bool return type for functions which return true/false (1/0)
Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics

Closes GH-6002
2020-08-28 15:41:27 +02:00
George Peter Banyard
b2248789ed Implement 'Saner Numeric Strings' RFC:
RFC: https://wiki.php.net/rfc/saner-numeric-strings

This removes the -1 allow_error mode from is_numeric_string functions and replaces it by
a trailing boolean out argument to preserve BC in a couple of places.

Most of the changes can be resumed to "numeric" strings which emitted a E_NOTICE now emit
a E_WARNING and "numeric" strings which emitted a E_WARNING now throw a TypeError.

This mostly affects:
 - String offsets
 - Arithmetic operations
 - Bitwise operations

Closes GH-5762
2020-07-29 02:51:09 +01:00
George Peter Banyard
25acc4a6b4 Fix [-Wundef] warning in Zend folder 2020-05-12 22:01:51 +02:00
Nikita Popov
53f5cfd99e Drop multi_convert_* APIs
These are no longer used internally, and I'd rather they weren't
used externally either.
2020-05-12 17:10:06 +02:00
Máté Kocsis
4a816584a4
Make float to string casts locale-independent
From now on, float to string casting will always behave locale-independently.
RFC: https://wiki.php.net/rfc/locale_independent_float_to_string
Closes GH-5224

Co-authored-by: George Peter Banyard <girgias@php.net>
2020-05-08 10:52:23 +02:00
Nikita Popov
9c0afc859c Remove op_func from TRY_BINARY_OP1 macro
And move the operator overloading helpers into zend_operators.c,
there's no reason for them to be in the header.
2020-04-01 10:15:03 +02:00
Nikita Popov
fb5bfcb75b Add a ZEND_UNCOMPARABLE value
To explicitly indicate that objects are uncomparable. For now
this has no functional difference from the usual 1 return value,
but makes intent clearer.
2020-03-31 12:36:48 +02:00
Christoph M. Becker
1ff6911d6a Merge branch 'PHP-7.4'
* PHP-7.4:
  Avoid undefined behavior
2019-12-30 23:18:34 +01:00
Christoph M. Becker
98df5c97f4 Avoid undefined behavior 2019-12-30 23:17:39 +01:00
Nikita Popov
c858d17f06 Optimize instanceof_function
Split out the simple equality check into an inline function --
this is one of the common cases.

Replace instanceof_function_ex with zend_class_implements_interface.
There are a few more places where it may be used.
2019-10-25 10:51:17 +02:00
Nikita Popov
19bea48c9a Merge branch 'PHP-7.4'
* PHP-7.4:
  Clean up and clarify instanceof_function_ex()
2019-10-24 17:42:04 +02:00
Nikita Popov
435f269108 Clean up and clarify instanceof_function_ex()
The instanceof_interface_only() function was dead code (always
returned zero).

Clarify that the last parameter indicates whether the passed CE
is interface or class and rewrite the code in terms of assertions.
2019-10-24 17:40:25 +02:00
Dmitry Stogov
b02b81299c Comparison cleanup:
- introduce zend_compare() that returns -1,0,1 dirctly (without intermediate zval)
- remove compare_objects() object handler, and keep only compare() handler
2019-10-07 17:57:49 +03:00
Nikita Popov
33bf1495b2 Don't use asm arithmetic under msan
Clang 9 supports asm goto, so these no longer get automatically
skipped.
2019-09-29 11:38:34 +02:00
Nikita Popov
d26eb10f08 Merge branch 'PHP-7.4' 2019-09-16 15:01:22 +02:00
Nikita Popov
8c0c06da86 Merge branch 'PHP-7.3' into PHP-7.4 2019-09-16 15:01:14 +02:00
Nikita Popov
8a11f1284e Merge branch 'PHP-7.2' into PHP-7.3 2019-09-16 15:01:05 +02:00
Nikita Popov
2f6efd835d Fixed bug #78545
By using an explicit (double) cast.
2019-09-16 15:00:20 +02:00
Nikita Popov
937d5f6598 Compute needle end only after checking it's non-empty 2019-08-28 09:32:18 +02:00
George Peter Banyard
6d578482a9 Improve strpos and strstr function family implementation 2019-08-26 17:11:37 +02:00
Peter Kokot
7f994990ea Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove HAVE_STRCOLL check
2019-06-28 00:13:25 +02:00
Peter Kokot
638c21765c Remove HAVE_STRCOLL check
The strcoll function is defined in the C89 standard and should be
on today's systems always available via the <string.h> header.

https://port70.net/~nsz/c/c89/c89-draft.html#4.11.4.3

- Remove also SKIPIF strcoll check in test
2019-06-28 00:05:55 +02:00
Nikita Popov
6aaab9adf7 Merge branch 'PHP-7.4' 2019-06-20 16:24:31 +02:00
Nikita Popov
e4455c32ed Bail out earlier in zend_memnrstr
To avoid decrementing a null pointer lateron. As we need to check
for NULL here anayway, we should take the chance to bail out right
away.
2019-06-20 16:21:53 +02:00
Dmitry Stogov
63deb0d569 Merge branch 'PHP-7.4'
* PHP-7.4:
  Use ZEND_ASSUME() to perform the following check only on "slow" path.
2019-06-06 14:23:02 +03:00
Dmitry Stogov
741468d145 Use ZEND_ASSUME() to perform the following check only on "slow" path. 2019-06-06 14:22:10 +03:00
Dmitry Stogov
b4d21310cb Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed reference-counting
2019-06-06 01:40:59 +03:00
Dmitry Stogov
90a2e4ba66 Fixed reference-counting 2019-06-06 01:40:40 +03:00
Nikita Popov
7686b0b889 Merge branch 'PHP-7.4' 2019-06-05 14:53:50 +02:00
Nikita Popov
a31f46421d Allow exceptions in __toString()
RFC: https://wiki.php.net/rfc/tostring_exceptions

And convert some object to string conversion related recoverable
fatal errors into Error exceptions.

Improve exception safety of internal code performing string
conversions.
2019-06-05 14:25:07 +02:00
Nikita Popov
31a516cf96 Remove set() object handler 2019-05-29 10:00:06 +02:00
Dmitry Stogov
40b2ffe201 Merge branch 'PHP-7.4'
* PHP-7.4:
  speed up increment and decrement operators with overflow detection
2019-05-07 15:42:25 +03:00
Sebastian Pop
79a84e00fa speed up increment and decrement operators with overflow detection
On A72, google-benchmark measure before and after the patch:
--------------------------------------------------------
Benchmark              Time             CPU   Iterations
--------------------------------------------------------
BM_inc_before       6.54 ns         6.54 ns    106985447
BM_dec_before       6.54 ns         6.54 ns    107011667
BM_inc_after        4.36 ns         4.36 ns    160525864
BM_dec_after        4.36 ns         4.36 ns    160524243

Before the patch:
fast_long_add_function:
	ldr	x0, [x1]
	add	x2, x0, 1
	cmp	x2, x0
	blt	.L11
	str	x2, [x1]
	ret
.L11:
	mov	x0, 4890909195324358656
	mov	w2, 5
	str	x0, [x1]
	str	w2, [x1, 8]
	ret

With the patch:
fast_long_add_function:
	ldr x5, [x1]
	adds x5,x5,1
	bvs .L2
	str x5, [x1]
	ret
.L2:
	mov	x0, 4890909195324358656
	mov	w2, 5
	str	x0, [x1]
	str	w2, [x1, 8]
	ret

    php$ ./sapi/cli/php Zend/bench.php

Base:                         Patch:
simple             0.091      simple             0.091
simplecall         0.014      simplecall         0.014
simpleucall        0.041      simpleucall        0.041
simpleudcall       0.045      simpleudcall       0.045
mandel             0.193      mandel             0.193
mandel2            0.229      mandel2            0.229
ackermann(7)       0.044      ackermann(7)       0.044
ary(50000)         0.010      ary(50000)         0.010
ary2(50000)        0.008      ary2(50000)        0.008
ary3(2000)         0.096      ary3(2000)         0.102
fibo(30)           0.149      fibo(30)           0.148
hash1(50000)       0.016      hash1(50000)       0.016
hash2(500)         0.020      hash2(500)         0.020
heapsort(20000)    0.055      heapsort(20000)    0.055
matrix(20)         0.057      matrix(20)         0.057
nestedloop(12)     0.091      nestedloop(12)     0.091
sieve(30)          0.032      sieve(30)          0.032
strcat(200000)     0.010      strcat(200000)     0.010
------------------------      ------------------------
Total              1.199      Total              1.204

    php$ ./sapi/cli/php Zend/micro_bench.php

Base:                                      Patch:
empty_loop         0.051                   empty_loop         0.050
func()             0.181    0.130          func()             0.181    0.131
undef_func()       0.186    0.135          undef_func()       0.186    0.136
int_func()         0.116    0.064          int_func()         0.116    0.065
$x = self::$x      0.235    0.183          $x = self::$x      0.229    0.179
self::$x = 0       0.198    0.147          self::$x = 0       0.199    0.148
isset(self::$x)    0.229    0.178          isset(self::$x)    0.225    0.174
empty(self::$x)    0.231    0.180          empty(self::$x)    0.227    0.177
$x = Foo::$x       0.144    0.093          $x = Foo::$x       0.142    0.092
Foo::$x = 0        0.107    0.056          Foo::$x = 0        0.105    0.054
isset(Foo::$x)     0.140    0.088          isset(Foo::$x)     0.140    0.089
empty(Foo::$x)     0.148    0.097          empty(Foo::$x)     0.144    0.094
self::f()          0.238    0.187          self::f()          0.240    0.190
Foo::f()           0.209    0.158          Foo::f()           0.201    0.150
$x = $this->x      0.123    0.072          $x = $this->x      0.120    0.070
$this->x = 0       0.124    0.073          $this->x = 0       0.124    0.074
$this->x += 2      0.151    0.099          $this->x += 2      0.151    0.101
++$this->x         0.137    0.086          ++$this->x         0.139    0.088
--$this->x         0.137    0.086          --$this->x         0.137    0.087
$this->x++         0.170    0.119          $this->x++         0.172    0.122
$this->x--         0.171    0.119          $this->x--         0.172    0.122
isset($this->x)    0.170    0.119          isset($this->x)    0.170    0.120
empty($this->x)    0.179    0.128          empty($this->x)    0.179    0.129
$this->f()         0.194    0.143          $this->f()         0.194    0.144
$x = Foo::TEST     0.188    0.137          $x = Foo::TEST     0.188    0.138
new Foo()          0.482    0.431          new Foo()          0.482    0.432
$x = TEST          0.109    0.058          $x = TEST          0.109    0.059
$x = $_GET         0.190    0.138          $x = $_GET         0.188    0.137
$x = $GLOBALS['v'] 0.242    0.191          $x = $GLOBALS['v'] 0.246    0.196
$x = $hash['v']    0.196    0.145          $x = $hash['v']    0.192    0.142
$x = $str[0]       0.146    0.094          $x = $str[0]       0.142    0.092
$x = $a ?: null    0.144    0.093          $x = $a ?: null    0.144    0.094
$x = $f ?: tmp     0.174    0.123          $x = $f ?: tmp     0.174    0.124
$x = $f ? $f : $a  0.153    0.101          $x = $f ? $f : $a  0.153    0.102
$x = $f ? $f : tmp 0.148    0.097          $x = $f ? $f : tmp 0.148    0.098
------------------------                   ------------------------
Total              6.143                   Total              6.108
2019-05-07 15:42:19 +03:00
Dmitry Stogov
b27f97d858 Merge branch 'PHP-7.4'
* PHP-7.4:
  speed up add and sub operators with overflow detection
2019-05-07 15:38:27 +03:00
Sebastian Pop
adc3b72076 speed up add and sub operators with overflow detection
On A72, google-benchmark measure before and after the patch:
--------------------------------------------------------
Benchmark              Time             CPU   Iterations
--------------------------------------------------------
BM_add_before       13.3 ns         13.3 ns     52626058
BM_sub_before       8.72 ns         8.72 ns     80259343
BM_add_after        4.80 ns         4.80 ns    145926004
BM_sub_after        4.80 ns         4.80 ns    145936496

Before the patch:
fast_long_add_function:
	ldr	x1, [x1]
	ldr	x2, [x2]
	add	x3, x1, x2
	eor	x4, x1, x2
	tbz	x4, #63, .L5
.L2:
	mov	w1, 4
	str	x3, [x0]
	str	w1, [x0, 8]
	ret
	.p2align 2
.L5:
	eor	x4, x1, x3
	tbz	x4, #63, .L2
	scvtf	d0, x1
	scvtf	d1, x2
	mov	w1, 5
	str	w1, [x0, 8]
	fadd	d0, d0, d1
	str	d0, [x0]
	ret

With the patch:
fast_long_add_function:
	ldr    x5, [x1]
	ldr    x6, [x2]
	adds	x5, x5, x6
	bvs	.L2
	mov	w6, 4
	str	x5, [x0]
	str	w6, [x0, 8]
	ret
.L2:
	ldr	x1, [x1]
	mov	w3, 5
	ldr	x2, [x2]
	str	w3, [x0, 8]
	scvtf	d0, x1
	scvtf	d1, x2
	fadd	d0, d0, d1
	str	d0, [x0]
	ret

    php$ ./sapi/cli/php Zend/bench.php

Base:                         Patch:
simple             0.091      simple             0.091
simplecall         0.014      simplecall         0.014
simpleucall        0.041      simpleucall        0.041
simpleudcall       0.045      simpleudcall       0.045
mandel             0.193      mandel             0.193
mandel2            0.229      mandel2            0.229
ackermann(7)       0.044      ackermann(7)       0.044
ary(50000)         0.010      ary(50000)         0.010
ary2(50000)        0.008      ary2(50000)        0.008
ary3(2000)         0.096      ary3(2000)         0.095
fibo(30)           0.149      fibo(30)           0.148
hash1(50000)       0.016      hash1(50000)       0.016
hash2(500)         0.020      hash2(500)         0.020
heapsort(20000)    0.055      heapsort(20000)    0.054
matrix(20)         0.057      matrix(20)         0.057
nestedloop(12)     0.091      nestedloop(12)     0.091
sieve(30)          0.032      sieve(30)          0.032
strcat(200000)     0.010      strcat(200000)     0.010
------------------------      ------------------------
Total              1.199      Total              1.197

    php$ ./sapi/cli/php Zend/micro_bench.php

Base:                                      Patch:
empty_loop         0.051                   empty_loop         0.051
func()             0.181    0.130          func()             0.181    0.130
undef_func()       0.186    0.135          undef_func()       0.186    0.135
int_func()         0.116    0.064          int_func()         0.116    0.064
$x = self::$x      0.235    0.183          $x = self::$x      0.233    0.182
self::$x = 0       0.198    0.147          self::$x = 0       0.198    0.147
isset(self::$x)    0.229    0.178          isset(self::$x)    0.229    0.178
empty(self::$x)    0.231    0.180          empty(self::$x)    0.231    0.180
$x = Foo::$x       0.144    0.093          $x = Foo::$x       0.144    0.093
Foo::$x = 0        0.107    0.056          Foo::$x = 0        0.107    0.056
isset(Foo::$x)     0.140    0.088          isset(Foo::$x)     0.140    0.088
empty(Foo::$x)     0.148    0.097          empty(Foo::$x)     0.148    0.097
self::f()          0.238    0.187          self::f()          0.238    0.187
Foo::f()           0.209    0.158          Foo::f()           0.209    0.158
$x = $this->x      0.123    0.072          $x = $this->x      0.123    0.072
$this->x = 0       0.124    0.073          $this->x = 0       0.124    0.073
$this->x += 2      0.151    0.099          $this->x += 2      0.153    0.101
++$this->x         0.137    0.086          ++$this->x         0.138    0.086
--$this->x         0.137    0.086          --$this->x         0.138    0.086
$this->x++         0.170    0.119          $this->x++         0.172    0.121
$this->x--         0.171    0.119          $this->x--         0.172    0.121
isset($this->x)    0.170    0.119          isset($this->x)    0.170    0.119
empty($this->x)    0.179    0.128          empty($this->x)    0.179    0.128
$this->f()         0.194    0.143          $this->f()         0.194    0.143
$x = Foo::TEST     0.188    0.137          $x = Foo::TEST     0.188    0.136
new Foo()          0.482    0.431          new Foo()          0.479    0.427
$x = TEST          0.109    0.058          $x = TEST          0.109    0.058
$x = $_GET         0.190    0.138          $x = $_GET         0.190    0.139
$x = $GLOBALS['v'] 0.242    0.191          $x = $GLOBALS['v'] 0.242    0.191
$x = $hash['v']    0.196    0.145          $x = $hash['v']    0.196    0.145
$x = $str[0]       0.146    0.094          $x = $str[0]       0.145    0.094
$x = $a ?: null    0.144    0.093          $x = $a ?: null    0.144    0.093
$x = $f ?: tmp     0.174    0.123          $x = $f ?: tmp     0.174    0.123
$x = $f ? $f : $a  0.153    0.101          $x = $f ? $f : $a  0.153    0.101
$x = $f ? $f : tmp 0.148    0.097          $x = $f ? $f : tmp 0.148    0.097
------------------------                   ------------------------
Total              6.143                   Total              6.143
2019-05-07 15:38:17 +03:00
Peter Kokot
e6f86fb17c Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove checks for locale.h, setlocale, localeconv
2019-04-07 18:34:02 +02:00
Peter Kokot
e06836a1a3 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
2019-04-07 18:32:54 +02:00
Dmitry Stogov
0deb6419e8 Merge branch 'PHP-7.4'
* PHP-7.4:
  Make is_identical() functions return zend_bool (instead of int)
2019-04-04 18:18:52 +03:00
Dmitry Stogov
9038d5c6ee Make is_identical() functions return zend_bool (instead of int) 2019-04-04 18:18:12 +03:00