Commit Graph

394 Commits

Author SHA1 Message Date
Stanislav Malyshev
4cc0286f2f Fix #73832 - leave the table in a safe state if the size is too big. 2017-01-02 20:14:05 -08:00
Sammy Kaye Powers
9e29f841ce Update copyright headers to 2017 2017-01-02 09:30:12 -06:00
Nikita Popov
a1fd1053f5 Merge branch 'PHP-7.1' 2016-12-21 21:19:28 +01:00
Nikita Popov
9afc61c214 Merge branch 'PHP-7.0' into PHP-7.1 2016-12-21 21:19:10 +01:00
David Walker
5733fd1caf Fix #73753 - Unpacked Arrays and Duplication 2016-12-21 21:18:20 +01:00
Andrea Faulds
a0502b89a6 Convert numeric keys in object/array casts
RFC: https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts

This converts key types as appropriate in object to array and array to object
casts, as well as in get_object_vars().
2016-11-14 18:20:45 +00:00
Dmitry Stogov
d6c332eb51 Turn IS_TYPE_COLLECTABLE zval flag into GC_COLLECTABLE zend_refcounted flag.
This simplifies checks and allows reset this flag for "acyclic" arrays and objects.
2016-10-21 17:47:30 +03:00
Dmitry Stogov
65ea250022 Merge branch 'PHP-7.1'
* PHP-7.1:
  Introduced HT_IS_PACKED() and HT_IS_WITHOUT_HOLES() macros. (Benjamin Coutu)
2016-10-19 23:12:17 +03:00
Dmitry Stogov
9ded1b4edb Introduced HT_IS_PACKED() and HT_IS_WITHOUT_HOLES() macros. (Benjamin Coutu) 2016-10-19 23:10:42 +03:00
Nikita Popov
2083007813 Merge branch 'PHP-7.1' 2016-09-27 19:49:01 +02:00
Nikita Popov
21f0be4792 Merge branch 'PHP-7.0' into PHP-7.1 2016-09-27 19:48:50 +02:00
Nikita Popov
b7cbaa7f43 Fix bug #73181 2016-09-27 19:47:48 +02:00
Dmitry Stogov
42db69058a Removed impossible condition 2016-09-22 17:58:45 +03:00
Xinchen Hui
01701912c7 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fixed bug #72936 (Zend API's zend_symtable_str_update() asserts key should end with '\0')
2016-08-29 00:10:57 +08:00
Xinchen Hui
986d0f87ec Fixed bug #72936 (Zend API's zend_symtable_str_update() asserts key should end with '\0') 2016-08-29 00:10:31 +08:00
Dmitry Stogov
1616038698 Added ZEND_ATTRIBUTE_FORMAT to some middind functions.
"%p" replaced by ZEND_LONG_FMT to avoid compilation warnings.
Fixed most incorrect use cases of format specifiers.
2016-06-21 16:00:37 +03:00
Dmitry Stogov
4042f543c4 HANDLE_BLOCK/UNBLOCK_INTERRUPTIONS() protection on inter-process data is completely useless now.
Historicaly, these macros were introduced as a protection from execution timeout handling, but we don't need them anymore after "safe execution timeout" implementation.
These macros are still useful to protect from termination during inner process data modification, because of OS signals (e.g. SIGTERM during OPcache SHM update).
2016-06-20 15:50:41 +03:00
Nikita Popov
e6d4a9e2d2 Don't HT_ASSERT rc=1 in zend_hash_apply functions
These are not necessarily used to modify the hash. Move the assert
into the APPLY_REMOVE branch only.
2016-05-10 12:14:08 +02:00
Dmitry Stogov
b91197c8a3 Inlined fast path 2016-05-04 17:33:35 +03:00
Dmitry Stogov
2578d08033 Fixed compilation warnings 2016-04-29 14:44:56 +03:00
Xinchen Hui
d26ca89402 array_dup should not copy the nApplyCount 2016-03-21 19:19:05 +08:00
Dmitry Stogov
b6bbe33f05 Better fix for IS_INDIRECT support in zend_hash_merge() 2016-03-02 15:09:04 +03:00
Xinchen Hui
186844be92 Fixed bug #71695 (Global variables are reserved before execution).
Instead of slow down hash_merge, we may also check the array(whether it
contains INDIRECT) outside of the loop, however, consisdering hash_merge
is not widly used, I prefer fix this in the current way to keep the
codes simple
2016-03-01 19:19:07 +08:00
Xinchen Hui
97a9470d97 bump year which is missed in rev 49493a2 2016-01-02 17:56:11 +08:00
Dmitry Stogov
0402f05ba3 Fixed possible crash on Zend/tests/bug71154.phpt 2015-12-21 15:57:53 +03:00
Nikita Popov
6a4c02e107 Fixed bug #71154 2015-12-17 22:20:29 +01:00
Dmitry Stogov
59424bb7bd Fixed bug #71006 (symbol referencing errors on Sparc/Solaris) 2015-12-03 13:28:41 +03:00
Xinchen Hui
6313e16a04 Improved fix for bug (count on symbol table) 2015-11-23 06:12:03 -08:00
Xinchen Hui
82f503f587 Re-Fixed bug #70249 (Segmentation fault while running PHPUnit tests on phpBB 3.2-dev)
Let's fixed this in the root instead
2015-11-11 12:32:46 +08:00
Xinchen Hui
2f2653aa77 Fixed bug #70805 (Segmentation faults whilst running Drupal 8 test suite) 2015-11-03 17:53:56 -08:00
Dmitry Stogov
37f0c6b5cb Add myself into list of authors of the most refactored files. 2015-08-31 11:38:16 +03:00
Nikita Popov
7f2261d24a Fix HT_ASSERT ht->nInternalPointer checks
The & was on the wrong side...
2015-08-28 18:59:46 +02:00
Dmitry Stogov
25f9e25526 Fixed bug #70187 (Notice: unserialize(): Unexpected end of serialized data) 2015-08-26 03:27:05 +03:00
Dmitry Stogov
f9f568aa1e In 95% cases we initialize "empty" array (with 8 hash slots). 2015-08-24 22:07:28 +03:00
Xinchen Hui
66866fb838 Simplify the macro (HT_DATA_SIZE/HT_HASH_SIZE is not used outside Zend) 2015-08-13 23:38:39 +08:00
Xinchen Hui
cf12da4f33 Fixed similar issues(segfault on OOM) 2015-08-13 23:02:51 +08:00
Xinchen Hui
ded3a44cfd Fixed segfault while OOM in pack_to_hash 2015-08-13 22:42:18 +08:00
Xinchen Hui
adf0e49912 zend_hash_resize seems useless, use zend_hash_extend 2015-08-13 12:19:35 +08:00
Xinchen Hui
a089ce0cc6 Fixed bug #70258 and #70253 2015-08-13 12:08:57 +08:00
Xinchen Hui
0f68f12d95 Use the same error msg with resize 2015-08-12 16:46:57 +08:00
Xinchen Hui
d75228e201 We should not silently go on if the required size can not be met 2015-08-12 16:44:51 +08:00
Xinchen Hui
60b75eb9ed Revert "We should not silently go on if the required size can not be met."
This reverts commit d2bcdec980.
2015-08-12 16:44:18 +08:00
Xinchen Hui
d2bcdec980 We should not silently go on if the required size can not be met. 2015-08-12 16:40:59 +08:00
Xinchen Hui
16f2ce8537 Hmm, we should also take care of uninitialized hashTable 2015-08-10 17:58:24 +08:00
Xinchen Hui
be54eb7db1 Fixed bug #70211 (php 7 ZEND_HASH_IF_FULL_DO_RESIZE use after free) 2015-08-10 17:02:16 +08:00
Xinchen Hui
72b0627315 Fixed bug #69521 (Segfault in gc_collect_cycles()). 2015-07-02 18:43:06 +08:00
Xinchen Hui
ab0771c60a Merge branch 'amortize-hash-compaction' of https://github.com/kaja47/php-src 2015-06-30 21:26:07 +08:00
Dmitry Stogov
7aa7627172 Use ZSTR_ API to access zend_string elements (this is just renaming without semantick changes). 2015-06-30 13:59:27 +03:00
Dmitry Stogov
4bd22cf1c1 Improved zend_string API (Francois Laupretre)
Squashed commit of the following:

commit d96eab8d79
Author: Francois Laupretre <francois@tekwire.net>
Date:   Fri Jun 26 01:23:31 2015 +0200

    Use the new 'ZSTR' macros in the rest of the code.

    Does not change anything to the generated code (thanks to compat macros) but cleaner.

commit b352643910
Author: Francois Laupretre <francois@tekwire.net>
Date:   Thu Jun 25 13:45:06 2015 +0200

    Improve zend_string API

    Add missing methods
2015-06-29 16:44:54 +03:00
Bob Weinand
70e86b8766 Also try __has_builtin() where builtins are used 2015-06-22 13:24:39 +02:00
Nikita Popov
23e1e1295f Clean up zend_hash_compare implementation
Split off zend_hash_compare_impl into separate function that does
not bother with recursion protection. We had two cases where
UNPROTECT_RECURSION was missing.
2015-06-20 17:35:16 +02:00
Nikita Popov
e8217a2727 Fix bug #69891 2015-06-20 17:23:58 +02:00
Nikita Popov
5bf7a3aac7 Fixed bug #69893 2015-06-20 17:14:48 +02:00
Nikita Popov
9589d26ef3 Merge branch 'PHP-5.6'
Conflicts:
	Zend/zend_hash.c
2015-06-20 16:50:37 +02:00
Nikita Popov
e09d3155a1 Merge branch 'PHP-5.5' into PHP-5.6 2015-06-20 16:40:53 +02:00
Nikita Popov
5fe078abba Fixed bug #69892 2015-06-20 16:40:14 +02:00
Dmitry Stogov
3186f913eb Fixed incorrect ZEND_FILE_LINE_CC usage 2015-06-05 13:54:10 +03:00
Xinchen Hui
0655abef1a Improve the fix for bug #69756 2015-06-05 18:42:21 +08:00
Dmitry Stogov
ed5fbf5e49 Fixed bug #69756 (Fatal error: Nesting level too deep - recursive dependency? with ===) 2015-06-05 10:04:58 +03:00
Xinchen Hui
497f9f2cda Fixed bug #69758 (Item added to array not being removed by array_pop/shift) 2015-06-05 11:54:22 +08:00
Stanislav Malyshev
60e92a3b84 set initialized flag after actual initialization happened 2015-05-31 19:37:56 -07:00
olshevskiy87
8bdec7a248 fix typos
Signed-off-by: olshevskiy87 <olshevskiy87@bk.ru>
2015-05-13 22:28:35 +04:00
Dmitry Stogov
0182eb4717 Eliminate useless checks 2015-04-27 15:54:41 +03:00
Dmitry Stogov
b250f46703 Optimized HashTable copy and cleanup function for cases without holes. 2015-04-24 22:43:50 +03:00
Dmitry Stogov
ef36d8a91e Optimized zend_hash_rehash(), added some exoectations to generate better code 2015-04-24 13:00:56 +03:00
Dmitry Stogov
6265687768 Added HashTable flag HASH_FLAG_STATIC_KEYS that is maintaned to be set if all hash table keys are numbers or interned strings.
Take this flag into account when copy or destroy HashTable to avoud useless checks for each key.
2015-04-24 09:34:50 +03:00
Dmitry Stogov
770cb1da71 Keep realpath and PCRE caches in consistency with opcache SHM. 2015-04-22 02:29:06 +03:00
Dmitry Stogov
c9da004a18 Slight zend_hash_find() optimization. 2015-04-21 23:27:44 +03:00
matason
52145ef8c6 Fix zend_hash_find documentation. 2015-04-07 22:26:16 +01:00
Dmitry Stogov
55cdde3dd6 Fixed bug #69376 (Wrong ref counting). 2015-04-07 02:35:52 +03:00
Xinchen Hui
ceb77b6472 Revert "Better to taverse reversely"
This reverts commit 51451ab84a.
2015-03-31 16:52:30 +08:00
Xinchen Hui
51451ab84a Better to taverse reversely 2015-03-30 15:26:59 +08:00
K
b3962ab940 zend_hash_do_resize: amortizing the cost of compaction
New implementation of hashtables introduced a compaction step which is
triggered when a hashtable is full but it contains at least one deleted
bucket. Therefore there is a possibility that a cleverly crafted code can
trigger this compaction step (which takes time proportional to the size of
hashtabe) by executing constatnt number of operations. When the hashtable
is full, deletion and subsequent addition or single element triggers a
table compaction and these two steps can be repeated ad infinitum. This
might be avenue for a DOS attack.

This patch allows compaction to be performed only if the hashtable contains
at least 1/32 deleted elements, otherwise the hashtable is doubled in size.
Linear amount of work caused by compaction is amortized over multiple
malicious additions and deletions.
2015-03-26 19:05:38 +01:00
Dmitry Stogov
87cec4ccc9 Fixed mess in names 2015-03-18 00:13:39 +03:00
Dmitry Stogov
55da1fb008 Fixed zend_hash_del() 2015-03-17 23:13:39 +03:00
Dmitry Stogov
db10b72523 Use fastcall calling convention for most critical ZE subsystems. 2015-03-13 21:10:09 +03:00
Dmitry Stogov
2b42d71908 Changed HashTable layout:
Removed HashTable->arHash (reduced memory consumption). Now hash slots may be accessed using HT_HASH() macro.
Hash slotas are allocated together with Buckets (before them) and lay in reverse order from HashTable->arData base address (see comments in Zend/zend_types.h)
Indexes in hash table and conflict resolution chains (Z_NEXT) may be stored as indeces or offsets in bytes, depending on system (32 or 64-bit).
HashTable data filelds are reordered to keep the most useful for zend_hash_find() data in the same CPU cache line.
2015-03-13 17:13:19 +03:00
Xinchen Hui
1ebdbdfd78 Unused var 2015-03-05 23:09:58 +08:00
Dmitry Stogov
bb91bf83f9 Minimize copying of HashTable realocation 2015-03-05 17:22:10 +03:00
Dmitry Stogov
8ec8648c91 Improved code for class property inheritance 2015-03-04 17:41:01 +03:00
Dmitry Stogov
a64e12e2a1 pefree() -> efree() 2015-03-03 09:09:28 +03:00
Dmitry Stogov
0ef5a6b409 Avoid unnecassary check 2015-02-24 19:21:21 +03:00
Dmitry Stogov
e97ae4fee8 Make zend_array_destroy() to free the corresponding zend_array 2015-02-24 18:34:37 +03:00
Dmitry Stogov
e10e151e9b Merged zend_array and HashTable into the single data structure.
Now each HashTable is also zend_array, so it's refcounted and may be a subject for Copy on Write
zend_array_dup() was changed to allocate and return HashTable, instead of taking preallocated HashTable as argument.
2015-02-13 22:20:39 +03:00
Xinchen Hui
2766dbaf6d Unused vars 2015-02-13 10:53:40 +08:00
Dmitry Stogov
12abac8bb7 Limit HashTable size to avoid integer overflow checks 2015-02-13 02:12:42 +03:00
Dmitry Stogov
97fe15db43 Fix "forech" statemt behaviour according to https://wiki.php.net/rfc/php7_foreach
Squashed commit of the following:

commit 1e41295097
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Sat Jan 31 07:28:58 2015 +0300

    Generalize HashTableIterator API to allows its usage without involvement of HashTable.nInternalPonter

commit 5406f21b11
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Fri Jan 30 18:08:43 2015 +0300

    Reduced alghorithms complexity

commit b37f1d58d2
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Fri Jan 30 18:08:30 2015 +0300

    Fixed test name

commit fb2d079645
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Fri Jan 30 18:08:05 2015 +0300

    API cleanup

commit 08302c0d6d
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Fri Jan 30 14:20:46 2015 +0300

    Make array_splice() to preserve foreach hash position

commit cc4b7be41e
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Fri Jan 30 12:24:31 2015 +0300

    Make internal function, operation on array passed by reference, to preserve foreach hash position

commit 5aa9712b0a
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Fri Jan 30 09:49:35 2015 +0300

    Implement consistent behavior for foreach by value over plain object

commit 4c5b385ff5
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Fri Jan 30 07:56:37 2015 +0300

    More careful iterators update.

commit 721fc9e80d
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Thu Jan 29 21:43:28 2015 +0300

    Added new test

commit 15a23b1218
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Thu Jan 29 21:05:02 2015 +0300

    Reimplement iteration magic with HashTableIterators (see https://wiki.php.net/rfc/php7_foreach#implementation_details)

commit 10a3260b1f
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Thu Jan 29 21:04:44 2015 +0300

    New test

commit eef80c5837
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jan 28 16:52:21 2015 +0300

    Fixed foreach by reference iteration over constant array

commit 61e7391873
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jan 28 14:59:54 2015 +0300

    Fixed temporary variable re-allocation pass

commit 92e90c09f0
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jan 28 12:44:57 2015 +0300

    Fixed operand destruction in case of exceptions in iterator

commit dd2a36a207
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jan 28 10:02:34 2015 +0300

    Use GET_OP1_ZVAL_PTR_DEREF() (IS_TMP_VAR and IS_CONST can't be IS_REFERENCE)

commit 4638f7b914
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jan 28 07:43:28 2015 +0300

    Change "foreach" statement behavior (this is just a PoC yet)

    - "foreach by value" don't relay on internal array/object pointer and doesnt perform array duplication. It just locks it incrementing reference counter. If the original array is modified by some code, the copy on write is performed and "foreach" still work with the old copy.

    - it makes no difference if array given to "foreach by value" is reference itself

    - "foreach by reference" still use internal array/object pointer and should work similar to PHP-5. (This id not completely implemented)
2015-02-12 13:57:12 +03:00
Xinchen Hui
7062465be0 Merge branch 'PHP-5.5' into PHP-5.6 2015-02-12 10:59:59 +08:00
Xinchen Hui
f2940b7120 Fixed bug #69017 (Fail to push to the empty array with the constant value defined in class scope) 2015-02-12 10:59:28 +08:00
Xinchen Hui
fc33f52d8c bump year 2015-01-15 23:27:30 +08:00
Xinchen Hui
0579e8278d bump year 2015-01-15 23:26:37 +08:00
Xinchen Hui
73c1be2653 Bump year 2015-01-15 23:26:03 +08:00
Dmitry Stogov
34723d1b75 Fixed malloc/emalloc mess 2015-01-15 18:05:58 +03:00
Dmitry Stogov
989daeb5bb Initialize ht->nTableMask 2015-01-15 15:21:38 +03:00
Xinchen Hui
8a0bc38535 Merge branch 'zend_sort' of https://github.com/laruence/php-src 2015-01-14 22:15:41 -05:00
Anatol Belski
8e3764e287 fixed zend_hash_init() when the lzcnt instruction isn't supported 2015-01-14 12:32:23 +01:00
Xinchen Hui
2193de0d18 Faster sorting algo 2015-01-14 18:02:41 +08:00
Stanislav Malyshev
b7a7b1a624 trailing whitespace removal 2015-01-10 15:07:38 -08:00
Dmitry Stogov
37466b0368 Use special flag (HASH_FLAG_INITIALIZED) instead of (nTableMask == 0) to indicate that HashTable is allocated.
Make nTableMask to be 0 for packed arrays.
Remove checks fo HASH_FLAG_PACKED in zend_hash_find/zend_hash_del and family (string keys are resolved through uninitialized_bucket).
Change HashTable layout for better locality.
2014-12-27 11:07:12 +03:00
Nikita Popov
2d212b426a Drop duplicate arg from hash_get_current_key_ex 2014-12-26 21:06:18 +01:00