Commit Graph

196 Commits

Author SHA1 Message Date
Niels Dossche
47b3fe4710 Handle indirect zvals and use up-to-date properties in SplFixedArray::__serialize
Closes GH-10925.
2023-03-30 21:43:39 +02:00
Niels Dossche
0d524eda94 Revert "Handle indirect zvals in SplFixedArray::__serialize"
This reverts commit e698938229.
2023-03-27 21:47:02 +02:00
Niels Dossche
e698938229 Handle indirect zvals in SplFixedArray::__serialize
Closes GH-10925.
2023-03-27 21:02:29 +02:00
Niels Dossche
a082696699 Fix GH-10907: Unable to serialize processed SplFixedArrays in PHP 8.2.4
The properties table can also contain numeric entries after a rebuild of
the table based on the array. Since the array can only contain numeric
entries, and the properties table can contain a mix of both, we'll add
the numeric entries from the array and only the string entries from the
properties table. To implement this we simply check if the key from the
properties table is a string.

Closes GH-10921.
2023-03-24 18:08:32 +01:00
Nikita Popov
70ad93dd6e Fix serialization of empty SplFixedArray
Avoid null pointer deref.
2022-09-15 22:36:19 +02:00
Bob Weinand
d1fc0017c9 Revert "Fix compilation on MacOS"
This reverts commit 800c6672e5.

Reverted along with a01dd9feda.
2022-09-14 11:28:06 +02:00
Bob Weinand
800c6672e5 Fix compilation on MacOS
memrchr has an always available equivalent under the name of zend_memrchr.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Máté Kocsis
adb45a63c0
Fix GH-9186 @strict-properties can be bypassed using unserialization (#9354)
* Emit deprecation warnings when adding dynamic properties to classes during unserialization - this will become an Error in php 9.0.
  (Adding dynamic properties in other contexts was already a deprecation warning - the use case of unserialization was overlooked)
* Throw an error when attempting to add a dynamic property to a `readonly` class when unserializing
* Add new serialization methods `__serialize`/`__unserialize` for SplFixedArray to avoid creating deprecated dynamic
  properties that would then be added to the backing fixed-size array
* Don't add named dynamic/declared properties (e.g. $obj->foo) of SplFixedArray to the backing array when unserializing
* Update tests to declare properties or to expect the deprecation warning
* Add news entry

Co-authored-by: Tyson Andre <tysonandre775@hotmail.com>
2022-08-30 07:46:32 -04:00
Ilija Tovilo
3b92a96610
Convert return type of various object handlers from int to zend_result (#8755) 2022-06-26 01:00:19 +02:00
George Peter Banyard
cfc38a6014
SPL: minor refactoring (#8341)
Use more appropriate types and return macros
2022-04-13 20:34:23 +01:00
Tyson Andre
b50315e73c Merge branch 'PHP-8.1'
Conflicts:
	ext/spl/tests/fixedarray_023.phpt
	ext/spl/spl_fixedarray.c (fix compile error)
2022-02-23 19:52:59 -05:00
Tyson Andre
5d907dfcee Merge branch 'PHP-8.0' into PHP-8.1 2022-02-23 19:26:24 -05:00
Tyson Andre
cd1c6f0b81
Fixes infinite recursion introduced by patch to SplFixedArray (#8105)
Closes GH-8079

Track whether the spl_fixedarray was modified since the last call to
get_properties
2022-02-23 19:23:00 -05:00
Dmitry Stogov
c77bbcd464 Fixed GH-8041 (php 8.2.0-dev crashes with assertion for cloning/get_object_vars on non-empty SplFixedArray) 2022-02-11 16:46:12 +03:00
Dmitry Stogov
a04d181578 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed GH-8044 (var_export/debug_zval_dump HT_ASSERT_RC1 debug failure for SplFixedArray)
2022-02-11 15:36:09 +03:00
Dmitry Stogov
a584d12667 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed GH-8044 (var_export/debug_zval_dump HT_ASSERT_RC1 debug failure for SplFixedArray)
2022-02-11 15:35:57 +03:00
Dmitry Stogov
52ae6417ca Fixed GH-8044 (var_export/debug_zval_dump HT_ASSERT_RC1 debug failure for SplFixedArray) 2022-02-11 15:33:31 +03:00
Tyson Andre
024d5f4b63 Cache method overrides of ArrayAccess in zend_class_entry
Previously, code such as subclasses of SplFixedArray would check for method
overrides when instantiating the objects.

This optimization was mentioned as a followup to GH-6552
2021-12-04 11:35:38 -05:00
Christoph M. Becker
9800845d43
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix #80663: Recursive SplFixedArray::setSize() may cause double-free
2021-09-28 15:55:40 +02:00
Christoph M. Becker
e73cc7aea9
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix #80663: Recursive SplFixedArray::setSize() may cause double-free
2021-09-28 15:55:11 +02:00
Christoph M. Becker
6154aa652d
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #80663: Recursive SplFixedArray::setSize() may cause double-free
2021-09-28 15:52:58 +02:00
Christoph M. Becker
2d6684091f
Fix #80663: Recursive SplFixedArray::setSize() may cause double-free
We address the `::setSize(0)` case by setting `array->element = NULL`
and `array->size = 0` before we destroy the elements.

Co-authored-by: Tyson Andre <tyson.andre@uwaterloo.ca>

Closes GH-7503.
2021-09-28 15:48:53 +02:00
Nikita Popov
4448934820 Don't mark SplFixedArray as REUSE_GET_ITERATOR
This flag only has an effect (or use) for Iterators, not for
IteratorAggregates. Removing the confusing flag.
2021-09-24 12:40:46 +02:00
Tyson Andre
27976d7dc7 Merge branch 'PHP-8.0' into PHP-8.1 2021-09-13 21:18:56 -04:00
Tyson Andre
753645a6f8 Merge remote-tracking branch 'origin/PHP-7.4' into PHP-8.0 2021-09-13 21:00:53 -04:00
Tyson Andre
b053192a03
Fix #81429: Handle resizing in SplFixedArray::offsetSet (#7487)
offsetSet did not account for the fact that the array may no longer exist after
the field is overwritten. This fixes that.

Add test of resizing both to the empty array and a smaller array - there should
be no valgrind warnings with a proper fix.

Alternate approach to #7486 (described in https://bugs.php.net/bug.php?id=81429)
2021-09-13 20:59:06 -04:00
Nikita Popov
5b2ddf5a17 Export zend_use_resource_as_offset()
Use a common implementation to generate this error message, as
we do so in quite a few places dealing with array keys.
2021-08-31 10:58:01 +02:00
Nikita Popov
6d505d4445 Add RETURN/RETVAL_COPY_DEREF() macros
These were missing from the set...

I think quite a few of these usages don't actually need the DEREF,
but I've just kept things as is for now.
2021-07-22 09:44:19 +02:00
Nikita Popov
b65380286a Avoid null pointer arithmetic in SplFixedArray
Fixes bug62904.phpt under clang ubsan.
2021-07-02 15:39:22 +02:00
George Peter Banyard
e9e06279c1
Refactor SplFixedArray (#7168)
* Move spl_offset_convert_to_long() to spl_fixedarray.c

It is only used there, which explains its weird offset semantics

* Refactor SplFixedArray offset handling
- Implement warning for resource type
- Throw a proper TypeError instead of a RuntimeException

* Use a proper Error to signal that [] cannot be used with SplFixedArray

* Refactor SplFixedArray has_dimension helper

* Drop some ZPP tests
2021-06-18 15:22:52 +01:00
Nikita Popov
805471e86b Fix bug #81112: Implement JsonSerializable for SplFixedArray
This returns an array for SplFixedArray JSON encoding, which
is more appropriate than an object with integer string keys.

Closes GH-7117.
2021-06-14 10:07:45 +02:00
Nikita Popov
9d2a466c4b Remove explicit assignments of zend_objects_destroy_object
This is the default handler, no need to set it explicitly. This
makes it easier to see which objects really have a custom dtor_obj.
2021-06-09 11:29:50 +02:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
Máté Kocsis
4f4c031f62
Generate ext/spl class entries from stubs
Closes GH-6709
2021-02-18 13:01:51 +01: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
aa51785889 Remove SEPARATE_ARG_IF_REF macro
The name doesn't correspond to what it does at all, and all the
existing usages appear to be unnecessary.

Usage of this macro can be replaced by ZVAL_DEREF + Z_TRY_ADDREF_P.
2021-01-14 10:53:56 +01:00
Tyson Andre
a25886d163 Optimize SplFixedArray when magic methods aren't overridden
This decreases the memory usage of SplFixedArrays by 32 bytes per object
on 64-bit systems (use 1 null pointer instead of 5 null pointers)
If allocating a lot of arrays of size 1, memory usage was 19.44MiB before this
change, and 16.24MiB after the change.

Existing tests continue to pass.

Subclassing SplFixedArray is already inefficient and rarely done.
It checks for the existence of 5 methods every time a subclass is instantiated.
(and has to switch back from C to the php vm to call those methods)

Closes GH-6552
2021-01-04 09:44:08 -05:00
Levi Morrison
3b34d74a45 Clean up spl_fixedarray.c
Remove inline.
Remove old folding blocks.
Convert an int usage to bool.

Convert some uses of int and size_t into zend_long. This is
incomplete because get_gc requires `int *n`, which should probably
become zend_long or size_t eventually.

Adds spl_fixedarray_empty to help enforce invariants.
Adds spl_fixedarray_default_ctor.
Documents some functions.

Reworks spl_fixedarray_copy into two functions:
  - spl_fixedarray_copy_ctor
  - spl_fixedarray_copy_range

I'm hoping to eventually export SplFixedArray for extensions to
use directly, which is the motivation here.
2020-09-27 12:25:02 -06:00
Alex Dowad
4222ae16e7 SplFixedArray is Aggregate, not Iterable
One strange feature of SplFixedArray was that it could not be used in nested foreach
loops. If one did so, the inner loop would overwrite the iteration state of the outer
loop.

To illustrate:

    $spl = SplFixedArray::fromArray([0, 1]);
    foreach ($spl as $a) {
      foreach ($spl as $b) {
        echo "$a $b";
      }
    }

Would only print two lines:

    0 0
    0 1

Use the new InternalIterator feature which was introduced in ff19ec2df3 to convert
SplFixedArray to an Aggregate rather than Iterable. As a bonus, we get to trim down
some ugly code! Yay!
2020-09-23 08:33:24 +02:00
George Peter Banyard
063fdd9422 Use ValueError instead of exceptions in SPL extension 2020-09-15 12:49:59 +02:00
George Peter Banyard
9affbef0e6 Use normal error in SPL for 'An iterator cannot be used with foreach by reference' 2020-09-15 12:49:59 +02:00
George Peter Banyard
61c299fe9c Error promotions in SPL
Warning to Error promotion and a Notice to Warning promotion to align
with the behaviour specified in the Reclassify Engine Warnings RFC.

Closes GH-6072
2020-09-03 19:27:02 +02:00
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +02:00
Nikita Popov
312201dce4 Add get_gc handle for object iterators
Optional handler with the same semantics as the object handler.
2020-07-01 15:17:22 +02:00
Nikita Popov
15846ff115 Add ZVAL_OBJ_COPY macro
For the common ZVAL_OBJ + GC_ADDREF pattern.
This mirrors the existing ZVAL_STR_COPY API.
2020-06-17 16:36:56 +02:00
Máté Kocsis
d7f7080bb5
Generate methods entries from stubs for ext/spl
Closes GH-5458
2020-04-25 23:54:56 +02:00
Alex Dowad
03ad54af96 Remove unused 'ce_get_iterator' field from spl_fixedarray_object 2020-04-23 10:05:08 +02:00
Christoph M. Becker
bdb63a3068 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #79393: Null coalescing operator failing with SplFixedArray
2020-03-23 13:59:22 +01:00
Christoph M. Becker
4576da0aa7 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #79393: Null coalescing operator failing with SplFixedArray
2020-03-23 13:31:25 +01:00
Christoph M. Becker
47c745555c Fix #79393: Null coalescing operator failing with SplFixedArray
We favor the KISS principle over optimization[1] – SPL is already
special enough.

[1] <352f3d4476 (r112498098)>ff
2020-03-23 13:29:25 +01:00