Commit Graph

142 Commits

Author SHA1 Message Date
Niels Dossche
1ca574f84a Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix memory leak in error path of zend_register_list_destructors_ex
2023-10-29 21:47:23 +01:00
Niels Dossche
3bf5d89efb Fix memory leak in error path of zend_register_list_destructors_ex 2023-10-29 21:47:07 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Nikita Popov
14f599ea7d Use zend_long for resource ID
Currently, resource IDs are limited to 32-bits. As resource IDs
are not reused, this means that resource ID overflow for
long-running processes is very possible.

This patch switches resource IDs to use zend_long instead, which
means that on 64-bit systems, 64-bit resource IDs will be used.
This makes resource ID overflow practically impossible.

The tradeoff is an 8 byte increase in zend_resource size.

Closes GH-7436.
2021-08-31 14:58:59 +02:00
Nikita Popov
65428d8768 Merge branch 'PHP-8.0'
* PHP-8.0:
  Error on resource ID space overflow
2021-08-31 10:42:59 +02:00
Nikita Popov
1d506250bf Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Error on resource ID space overflow
2021-08-31 10:42:52 +02:00
Nikita Popov
501f1a45f5 Error on resource ID space overflow
When more than INT_MAX resource are created, throw a fatal error,
rather than reusing already allocated IDs, which will result in
assertion failures or crashes down the line.

This doesn't fix the fundamental problem, but makes the failure
more graceful with an obvious cause.

Inspired by https://bugs.php.net/bug.php?id=81399.

Closes GH-7428.
2021-08-31 10:41:57 +02:00
Nikita Popov
2ff496e871 Handle resource table reallocation during shutdown
New resources may be created while closing resources during
shutdown. This may result in a reallocation of arData and use
after free.

This problem was exposed by 7f7a90b2bc,
which creates one resources less, and thus moved the reallocation
to shutdown for a number of existing tests. However, the general
problem already existed previously.

We don't try to also close the newly added resources -- we will
later perform a graceful reverse destroy of the table, which will
catch any remaining cases.
2021-08-20 15:37:46 +02:00
Nikita Popov
d085a7439f Assert on unknown list entry type 2020-09-21 14:58:23 +02: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
1b2ec73c1d Drop various unused macros/APIs
Also convert_libmagic_pattern() to return a zend_string*

Closes GH-6029
2020-08-26 12:59:43 +02:00
Nikita Popov
9043563775 Make zend_list_free return void
And assert that the refcount is zero. This function should only
be used internally as the resource destructor.
2020-04-15 11:01:12 +02:00
Nikita Popov
a1479fbbd9 Merge branch 'PHP-7.4' 2019-06-25 14:30:24 +02:00
Nikita Popov
c7962207d7 Fix stream leak in phar cache_list 2019-06-25 14:28:58 +02:00
Nikita Popov
1df8175b61 Convert fetch_resource warnings into TypeErrors
More type checks that are not part of zpp and should generate a
TypeError in PHP 8.
2019-06-03 09:17:12 +02:00
Dmitry Stogov
87bfafe8bf Fixed resoure numbering 2019-02-12 12:28:23 +03:00
Peter Kokot
92ac598aab Remove local variables
This patch removes the so called local variables defined per
file basis for certain editors to properly show tab width, and
similar settings. These are mainly used by Vim and Emacs editors
yet with recent changes the once working definitions don't work
anymore in Vim without custom plugins or additional configuration.
Neither are these settings synced across the PHP code base.

A simpler and better approach is EditorConfig and fixing code
using some code style fixing tools in the future instead.

This patch also removes the so called modelines for Vim. Modelines
allow Vim editor specifically to set some editor configuration such as
syntax highlighting, indentation style and tab width to be set in the
first line or the last 5 lines per file basis. Since the php test
files have syntax highlighting already set in most editors properly and
EditorConfig takes care of the indentation settings, this patch removes
these as well for the Vim 6.0 and newer versions.

With the removal of local variables for certain editors such as
Emacs and Vim, the footer is also probably not needed anymore when
creating extensions using ext_skel.php script.

Additionally, Vim modelines for setting php syntax and some editor
settings has been removed from some *.phpt files.  All these are
mostly not relevant for phpt files neither work properly in the
middle of the file.
2019-02-03 21:03:00 +01:00
Zeev Suraski
a81202ac49 Adios, yearly copyright ranges 2019-01-30 11:48:28 +01:00
Dmitry Stogov
cec091176c Replace zend_hash_apply... with ZEND_HASH_FOREACH... 2018-12-19 02:49:56 +03:00
Gabriel Caruso
cdd8368d6f Clean up unnecessary ternary expressions and simplify some returns
- Simplify conditions
- Use ZEND_HASH_APPLY_* instead of hard-coded booleans
- Use ZEND_NORMALIZE_BOOL
- Drop sign in favor of ZEND_NORMALIZE_BOOL
2018-12-03 01:22:14 +01:00
Zeev Suraski
54dc07f3dc Update email addresses. We're still @Zend, but future proofing it... 2018-11-01 17:20:07 +02:00
Peter Kokot
8d3f8ca12a Remove unused Git attributes ident
The $Id$ keywords were used in Subversion where they can be substituted
with filename, last revision number change, last changed date, and last
user who changed it.

In Git this functionality is different and can be done with Git attribute
ident. These need to be defined manually for each file in the
.gitattributes file and are afterwards replaced with 40-character
hexadecimal blob object name which is based only on the particular file
contents.

This patch simplifies handling of $Id$ keywords by removing them since
they are not used anymore.
2018-07-25 00:53:25 +02:00
Dmitry Stogov
0b90cf85a6 Removed "dead" code (zend_hash_update() never fails) 2018-06-01 11:58:57 +03:00
Dmitry Stogov
5eb1f92f31 Use zend_string_release_ex() instread of zend_string_release() in places, where we sure about string persistence. 2018-05-28 16:27:12 +03:00
Xinchen Hui
a6519d0514 year++ 2018-01-02 12:57:58 +08:00
Dmitry Stogov
175e461369 Use fastcall calling convention for objects and resources API 2017-12-14 13:50:39 +03:00
Dmitry Stogov
468fd78bff Fixed memory leaks 2017-11-02 03:04:27 +03:00
Dmitry Stogov
67d5f39a47 Persistent resources are "thread-local".
Register persistent resources through new functions zend_register_persistent_resource()/zend_register_persistent_resource_ex().
2017-11-01 15:19:31 +03:00
Dmitry Stogov
49ea143bbd Encapsulate reference-counting primitives.
Prohibit direct update of GC_REFCOUNT(), GC_SET_REFCOUNT(), GC_ADDREF() and GC_DELREF() shoukf be instead.
Added mactros to validate reference-counting (disabled for now).
These macros are going to be used to eliminate race-condintions during reference-counting on data shared between threads.
2017-10-27 01:28:58 +03:00
Anatol Belski
bc5811f361 further sync for vim mode lines 2017-07-04 18:12:45 +02:00
Sammy Kaye Powers
9e29f841ce Update copyright headers to 2017 2017-01-02 09:30:12 -06:00
Xinchen Hui
97a9470d97 bump year which is missed in rev 49493a2 2016-01-02 17:56:11 +08:00
Bob Weinand
ac58d21aa3 Fix refcount reaching 2^32 - 1 for resources
Happens e.g. in proc_close() when nothing is referencing the file handles, e.g. they have refcount 0 when passed to zend_list_close() and then zend_list_delete() which decrements it to (uint32_t) -1
2015-10-25 18:47:50 +01:00
Rasmus Lerdorf
611ff0c846 One less comparison 2015-07-13 19:44:51 -07:00
Rasmus Lerdorf
1ce4e8c45e Fix potential segfault 2015-07-13 19:38:55 -07:00
Xinchen Hui
d66045fe73 Fixed bug #69485 (Double free on zend_list_dtor). 2015-04-20 11:48:21 +08:00
Xinchen Hui
e98caf27ea found type is unnecessary 2015-02-02 14:45:19 +08:00
Xinchen Hui
942809909e Cleanup resource handling APIs 2015-02-02 13:23:16 +08:00
Xinchen Hui
fc33f52d8c bump year 2015-01-15 23:27:30 +08:00
Stanislav Malyshev
b7a7b1a624 trailing whitespace removal 2015-01-10 15:07:38 -08:00
Anatol Belski
95e04fed24 cleanup redundand macros 2014-12-31 16:25:42 +01:00
Anatol Belski
bdeb220f48 first shot remove TSRMLS_* things 2014-12-13 23:06:14 +01:00
Anatol Belski
c00424e427 bring back all the TSRMLS_FETCH() stuff
for better comparability with the mainstream
2014-10-15 09:37:55 +02:00
Anatol Belski
06d0230a0f cleanup TSRMLS_FETCH 2014-09-26 09:58:19 +02:00
Dmitry Stogov
b1f53ca415 Use efree_size() instead of efree() where posible 2014-08-27 20:49:56 +04:00
Dmitry Stogov
e34a6e9211 Use new zend_hash API 2014-05-27 00:38:58 +04:00
Xinchen Hui
922285ec55 Don't use cast (compiler friendly) 2014-05-26 11:05:04 +08:00
Xinchen Hui
0175d994c0 Fixed apply_func_arg_t, and it's better not using cast (compiler friendly) 2014-05-25 19:56:51 +08:00
Dmitry Stogov
281663f75d Removed support for old-style resource destructors (only ext/soap used it) 2014-05-15 10:57:03 +04:00
Dmitry Stogov
fa7008bb24 Fixed resource destruction 2014-05-08 02:48:31 +04:00