Skip to content

Commit 4bfa1b6

Browse files
authored
ext/spl: add const qualifiers when dealing with CEs (php#21512)
1 parent 7d40bae commit 4bfa1b6

7 files changed

Lines changed: 20 additions & 22 deletions

File tree

ext/spl/php_spl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static zend_class_entry * spl_find_ce_by_name(zend_string *name, bool autoload)
6464
PHP_FUNCTION(class_parents)
6565
{
6666
zval *obj;
67-
zend_class_entry *parent_class, *ce;
67+
zend_class_entry *ce;
6868
bool autoload = true;
6969

7070
/* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */
@@ -86,7 +86,7 @@ PHP_FUNCTION(class_parents)
8686
}
8787

8888
array_init(return_value);
89-
parent_class = ce->parent;
89+
const zend_class_entry *parent_class = ce->parent;
9090
while (parent_class) {
9191
spl_add_class_name(return_value, parent_class, 0, 0);
9292
parent_class = parent_class->parent;
@@ -99,7 +99,7 @@ PHP_FUNCTION(class_implements)
9999
{
100100
zval *obj;
101101
bool autoload = true;
102-
zend_class_entry *ce;
102+
const zend_class_entry *ce;
103103

104104
/* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */
105105
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {
@@ -128,7 +128,7 @@ PHP_FUNCTION(class_uses)
128128
{
129129
zval *obj;
130130
bool autoload = true;
131-
zend_class_entry *ce;
131+
const zend_class_entry *ce;
132132

133133
/* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */
134134
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {

ext/spl/spl_array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void spl_array_object_free_storage(zend_object *object)
157157
static zend_object *spl_array_object_new_ex(zend_class_entry *class_type, zend_object *orig, int clone_orig)
158158
{
159159
spl_array_object *intern;
160-
zend_class_entry *parent = class_type;
160+
const zend_class_entry *parent = class_type;
161161
int inherited = 0;
162162

163163
intern = zend_object_alloc(sizeof(spl_array_object), parent);

ext/spl/spl_dllist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static void spl_dllist_object_free_storage(zend_object *object) /* {{{ */
304304
static zend_object *spl_dllist_object_new_ex(zend_class_entry *class_type, zend_object *orig, int clone_orig) /* {{{ */
305305
{
306306
spl_dllist_object *intern;
307-
zend_class_entry *parent = class_type;
307+
const zend_class_entry *parent = class_type;
308308
int inherited = 0;
309309

310310
intern = zend_object_alloc(sizeof(spl_dllist_object), parent);
@@ -316,7 +316,7 @@ static zend_object *spl_dllist_object_new_ex(zend_class_entry *class_type, zend_
316316
intern->traverse_position = 0;
317317

318318
if (orig) {
319-
spl_dllist_object *other = spl_dllist_from_obj(orig);
319+
const spl_dllist_object *other = spl_dllist_from_obj(orig);
320320

321321
if (clone_orig) {
322322
intern->llist = spl_ptr_llist_init();

ext/spl/spl_functions.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
#include "php.h"
2222

2323
/* {{{ spl_add_class_name */
24-
void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_flags)
24+
void spl_add_class_name(zval *list, const zend_class_entry *pce, int allow, int ce_flags)
2525
{
2626
if (!allow || (allow > 0 && (pce->ce_flags & ce_flags)) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
27-
zval *tmp;
27+
const zval *tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name);
2828

29-
if ((tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name)) == NULL) {
29+
if (tmp == NULL) {
3030
zval t;
3131
ZVAL_STR_COPY(&t, pce->name);
3232
zend_hash_add(Z_ARRVAL_P(list), pce->name, &t);
@@ -36,7 +36,7 @@ void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_fla
3636
/* }}} */
3737

3838
/* {{{ spl_add_interfaces */
39-
void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags)
39+
void spl_add_interfaces(zval *list, const zend_class_entry *pce, int allow, int ce_flags)
4040
{
4141
if (pce->num_interfaces) {
4242
ZEND_ASSERT(pce->ce_flags & ZEND_ACC_LINKED);
@@ -48,12 +48,10 @@ void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_fl
4848
/* }}} */
4949

5050
/* {{{ spl_add_traits */
51-
void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
51+
void spl_add_traits(zval *list, const zend_class_entry *pce, int allow, int ce_flags)
5252
{
53-
zend_class_entry *trait;
54-
5553
for (uint32_t num_traits = 0; num_traits < pce->num_traits; num_traits++) {
56-
trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name,
54+
const zend_class_entry *trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name,
5755
pce->trait_names[num_traits].lc_name, ZEND_FETCH_CLASS_TRAIT);
5856
ZEND_ASSERT(trait);
5957
spl_add_class_name(list, trait, allow, ce_flags);
@@ -63,7 +61,7 @@ void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
6361

6462

6563
/* {{{ spl_add_classes */
66-
void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags)
64+
void spl_add_classes(const zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags)
6765
{
6866
ZEND_ASSERT(pce);
6967
spl_add_class_name(list, pce, allow, ce_flags);

ext/spl/spl_functions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
allow > 0: allow all that match and mask ce_flags
2525
allow < 0: disallow all that match and mask ce_flags
2626
*/
27-
void spl_add_class_name(zval * list, zend_class_entry * pce, int allow, int ce_flags);
28-
void spl_add_interfaces(zval * list, zend_class_entry * pce, int allow, int ce_flags);
29-
void spl_add_traits(zval * list, zend_class_entry * pce, int allow, int ce_flags);
30-
void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags);
27+
void spl_add_class_name(zval * list, const zend_class_entry *pce, int allow, int ce_flags);
28+
void spl_add_interfaces(zval * list, const zend_class_entry *pce, int allow, int ce_flags);
29+
void spl_add_traits(zval * list, const zend_class_entry *pce, int allow, int ce_flags);
30+
void spl_add_classes(const zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags);
3131

3232
void spl_set_private_debug_info_property(const zend_class_entry *ce, const char *property, size_t property_len, HashTable *debug_info, zval *value);
3333

ext/spl/spl_heap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static void spl_heap_object_free_storage(zend_object *object) /* {{{ */
412412
static zend_object *spl_heap_object_new_ex(zend_class_entry *class_type, zend_object *orig, int clone_orig) /* {{{ */
413413
{
414414
spl_heap_object *intern;
415-
zend_class_entry *parent = class_type;
415+
const zend_class_entry *parent = class_type;
416416
int inherited = 0;
417417

418418
intern = zend_object_alloc(sizeof(spl_heap_object), parent);

ext/spl/spl_observer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static void spl_object_storage_addall(spl_SplObjectStorage *intern, spl_SplObjec
257257
static zend_object *spl_object_storage_new_ex(zend_class_entry *class_type, zend_object *orig) /* {{{ */
258258
{
259259
spl_SplObjectStorage *intern;
260-
zend_class_entry *parent = class_type;
260+
const zend_class_entry *parent = class_type;
261261

262262
intern = zend_object_alloc(sizeof(spl_SplObjectStorage), parent);
263263
intern->pos = 0;

0 commit comments

Comments
 (0)