@@ -127,16 +127,11 @@ static void zend_destroy_property_info_internal(zval *zv) /* {{{ */
127127}
128128/* }}} */
129129
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 ) /* {{{ */
131131{
132- zend_string * result ;
133- char char_pos_buf [32 ];
134- size_t char_pos_len = sprintf (char_pos_buf , "%p" , lex_pos );
135132 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 )++ );
140135 return zend_new_interned_string (result );
141136}
142137/* }}} */
@@ -5924,8 +5919,11 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
59245919 return ;
59255920 }
59265921
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+ }
59295927
59305928 if (op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
59315929 opline = zend_emit_op_tmp (result , ZEND_DECLARE_LAMBDA_FUNCTION , NULL , NULL );
@@ -6347,16 +6345,11 @@ void zend_compile_implements(zend_ast *ast) /* {{{ */
63476345}
63486346/* }}} */
63496347
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 ) /* {{{ */
63516349{
6352- zend_string * result ;
6353- char char_pos_buf [32 ];
6354- size_t char_pos_len = sprintf (char_pos_buf , "%p" , lex_pos );
63556350 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 )++ );
63606353 return zend_new_interned_string (result );
63616354}
63626355/* }}} */
@@ -6396,7 +6389,7 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
63966389
63976390 zend_register_seen_symbol (lcname , ZEND_SYMBOL_CLASS );
63986391 } else {
6399- name = zend_generate_anon_class_name (decl -> lex_pos );
6392+ name = zend_generate_anon_class_name (decl -> start_lineno );
64006393 lcname = zend_string_tolower (name );
64016394 }
64026395 lcname = zend_new_interned_string (lcname );
@@ -6553,20 +6546,19 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
65536546 opline -> extended_value = zend_alloc_cache_slot ();
65546547 opline -> result_type = IS_VAR ;
65556548 opline -> result .var = get_temporary_variable ();
6556-
65576549 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 ));
65636552 }
65646553 } 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 );
65666555
65676556 /* RTD key is placed after lcname literal in op1 */
65686557 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+ }
65706562
65716563 opline -> opcode = ZEND_DECLARE_CLASS ;
65726564 if (extends_ast && toplevel
0 commit comments