@@ -127,16 +127,11 @@ static void zend_destroy_property_info_internal(zval *zv) /* {{{ */
127
127
}
128
128
/* }}} */
129
129
130
- static zend_string * zend_build_runtime_definition_key (zend_string * name , unsigned char * lex_pos ) /* {{{ */
130
+ static zend_string * zend_build_runtime_definition_key (zend_string * name , uint32_t start_lineno ) /* {{{ */
131
131
{
132
- zend_string * result ;
133
- char char_pos_buf [32 ];
134
- size_t char_pos_len = sprintf (char_pos_buf , "%p" , lex_pos );
135
132
zend_string * filename = CG (active_op_array )-> filename ;
136
-
137
- /* NULL, name length, filename length, last accepting char position length */
138
- result = zend_string_alloc (1 + ZSTR_LEN (name ) + ZSTR_LEN (filename ) + char_pos_len , 0 );
139
- sprintf (ZSTR_VAL (result ), "%c%s%s%s" , '\0' , ZSTR_VAL (name ), ZSTR_VAL (filename ), char_pos_buf );
133
+ zend_string * result = zend_strpprintf (0 , "%c%s%s:%" PRIu32 "$%" PRIx32 ,
134
+ '\0' , ZSTR_VAL (name ), ZSTR_VAL (filename ), start_lineno , CG (rtd_key_counter )++ );
140
135
return zend_new_interned_string (result );
141
136
}
142
137
/* }}} */
@@ -5924,8 +5919,11 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
5924
5919
return ;
5925
5920
}
5926
5921
5927
- key = zend_build_runtime_definition_key (lcname , decl -> lex_pos );
5928
- zend_hash_update_ptr (CG (function_table ), key , op_array );
5922
+ key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
5923
+ if (!zend_hash_add_ptr (CG (function_table ), key , op_array )) {
5924
+ zend_error_noreturn (E_ERROR ,
5925
+ "Runtime definition key collision for function %s. This is a bug" , ZSTR_VAL (name ));
5926
+ }
5929
5927
5930
5928
if (op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
5931
5929
opline = zend_emit_op_tmp (result , ZEND_DECLARE_LAMBDA_FUNCTION , NULL , NULL );
@@ -6347,16 +6345,11 @@ void zend_compile_implements(zend_ast *ast) /* {{{ */
6347
6345
}
6348
6346
/* }}} */
6349
6347
6350
- static zend_string * zend_generate_anon_class_name (unsigned char * lex_pos ) /* {{{ */
6348
+ static zend_string * zend_generate_anon_class_name (uint32_t start_lineno ) /* {{{ */
6351
6349
{
6352
- zend_string * result ;
6353
- char char_pos_buf [32 ];
6354
- size_t char_pos_len = sprintf (char_pos_buf , "%p" , lex_pos );
6355
6350
zend_string * filename = CG (active_op_array )-> filename ;
6356
-
6357
- /* NULL, name length, filename length, last accepting char position length */
6358
- result = zend_string_alloc (sizeof ("class@anonymous" ) + ZSTR_LEN (filename ) + char_pos_len , 0 );
6359
- sprintf (ZSTR_VAL (result ), "class@anonymous%c%s%s" , '\0' , ZSTR_VAL (filename ), char_pos_buf );
6351
+ zend_string * result = zend_strpprintf (0 , "class@anonymous%c%s:%" PRIu32 "$%" PRIx32 ,
6352
+ '\0' , ZSTR_VAL (filename ), start_lineno , CG (rtd_key_counter )++ );
6360
6353
return zend_new_interned_string (result );
6361
6354
}
6362
6355
/* }}} */
@@ -6396,7 +6389,7 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6396
6389
6397
6390
zend_register_seen_symbol (lcname , ZEND_SYMBOL_CLASS );
6398
6391
} else {
6399
- name = zend_generate_anon_class_name (decl -> lex_pos );
6392
+ name = zend_generate_anon_class_name (decl -> start_lineno );
6400
6393
lcname = zend_string_tolower (name );
6401
6394
}
6402
6395
lcname = zend_new_interned_string (lcname );
@@ -6553,20 +6546,19 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6553
6546
opline -> extended_value = zend_alloc_cache_slot ();
6554
6547
opline -> result_type = IS_VAR ;
6555
6548
opline -> result .var = get_temporary_variable ();
6556
-
6557
6549
if (!zend_hash_add_ptr (CG (class_table ), lcname , ce )) {
6558
- /* this anonymous class has been included */
6559
- zval zv ;
6560
- ZVAL_PTR (& zv , ce );
6561
- destroy_zend_class (& zv );
6562
- return opline ;
6550
+ zend_error_noreturn (E_ERROR ,
6551
+ "Runtime definition key collision for %s. This is a bug" , ZSTR_VAL (name ));
6563
6552
}
6564
6553
} else {
6565
- zend_string * key = zend_build_runtime_definition_key (lcname , decl -> lex_pos );
6554
+ zend_string * key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
6566
6555
6567
6556
/* RTD key is placed after lcname literal in op1 */
6568
6557
zend_add_literal_string (& key );
6569
- zend_hash_update_ptr (CG (class_table ), key , ce );
6558
+ if (!zend_hash_add_ptr (CG (class_table ), key , ce )) {
6559
+ zend_error_noreturn (E_ERROR ,
6560
+ "Runtime definition key collision for class %s. This is a bug" , ZSTR_VAL (name ));
6561
+ }
6570
6562
6571
6563
opline -> opcode = ZEND_DECLARE_CLASS ;
6572
6564
if (extends_ast && toplevel
0 commit comments