@@ -132,16 +132,11 @@ static void zend_destroy_property_info_internal(zval *zv) /* {{{ */
132
132
}
133
133
/* }}} */
134
134
135
- static zend_string * zend_build_runtime_definition_key (zend_string * name , unsigned char * lex_pos ) /* {{{ */
135
+ static zend_string * zend_build_runtime_definition_key (zend_string * name , uint32_t start_lineno ) /* {{{ */
136
136
{
137
- zend_string * result ;
138
- char char_pos_buf [32 ];
139
- size_t char_pos_len = sprintf (char_pos_buf , "%p" , lex_pos );
140
137
zend_string * filename = CG (active_op_array )-> filename ;
141
-
142
- /* NULL, name length, filename length, last accepting char position length */
143
- result = zend_string_alloc (1 + ZSTR_LEN (name ) + ZSTR_LEN (filename ) + char_pos_len , 0 );
144
- sprintf (ZSTR_VAL (result ), "%c%s%s%s" , '\0' , ZSTR_VAL (name ), ZSTR_VAL (filename ), char_pos_buf );
138
+ zend_string * result = zend_strpprintf (0 , "%c%s%s:%" PRIu32 "$%" PRIx32 ,
139
+ '\0' , ZSTR_VAL (name ), ZSTR_VAL (filename ), start_lineno , CG (rtd_key_counter )++ );
145
140
return zend_new_interned_string (result );
146
141
}
147
142
/* }}} */
@@ -6124,8 +6119,11 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
6124
6119
return ;
6125
6120
}
6126
6121
6127
- key = zend_build_runtime_definition_key (lcname , decl -> lex_pos );
6128
- zend_hash_update_ptr (CG (function_table ), key , op_array );
6122
+ key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
6123
+ if (!zend_hash_add_ptr (CG (function_table ), key , op_array )) {
6124
+ zend_error_noreturn (E_ERROR ,
6125
+ "Runtime definition key collision for function %s. This is a bug" , ZSTR_VAL (name ));
6126
+ }
6129
6127
6130
6128
if (op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
6131
6129
opline = zend_emit_op_tmp (result , ZEND_DECLARE_LAMBDA_FUNCTION , NULL , NULL );
@@ -6529,16 +6527,11 @@ void zend_compile_implements(zend_ast *ast) /* {{{ */
6529
6527
}
6530
6528
/* }}} */
6531
6529
6532
- static zend_string * zend_generate_anon_class_name (unsigned char * lex_pos ) /* {{{ */
6530
+ static zend_string * zend_generate_anon_class_name (uint32_t start_lineno ) /* {{{ */
6533
6531
{
6534
- zend_string * result ;
6535
- char char_pos_buf [32 ];
6536
- size_t char_pos_len = sprintf (char_pos_buf , "%p" , lex_pos );
6537
6532
zend_string * filename = CG (active_op_array )-> filename ;
6538
-
6539
- /* NULL, name length, filename length, last accepting char position length */
6540
- result = zend_string_alloc (sizeof ("class@anonymous" ) + ZSTR_LEN (filename ) + char_pos_len , 0 );
6541
- sprintf (ZSTR_VAL (result ), "class@anonymous%c%s%s" , '\0' , ZSTR_VAL (filename ), char_pos_buf );
6533
+ zend_string * result = zend_strpprintf (0 , "class@anonymous%c%s:%" PRIu32 "$%" PRIx32 ,
6534
+ '\0' , ZSTR_VAL (filename ), start_lineno , CG (rtd_key_counter )++ );
6542
6535
return zend_new_interned_string (result );
6543
6536
}
6544
6537
/* }}} */
@@ -6578,7 +6571,7 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6578
6571
6579
6572
zend_register_seen_symbol (lcname , ZEND_SYMBOL_CLASS );
6580
6573
} else {
6581
- name = zend_generate_anon_class_name (decl -> lex_pos );
6574
+ name = zend_generate_anon_class_name (decl -> start_lineno );
6582
6575
lcname = zend_string_tolower (name );
6583
6576
}
6584
6577
lcname = zend_new_interned_string (lcname );
@@ -6728,20 +6721,19 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6728
6721
opline -> extended_value = zend_alloc_cache_slot ();
6729
6722
opline -> result_type = IS_VAR ;
6730
6723
opline -> result .var = get_temporary_variable ();
6731
-
6732
6724
if (!zend_hash_add_ptr (CG (class_table ), lcname , ce )) {
6733
- /* this anonymous class has been included */
6734
- zval zv ;
6735
- ZVAL_PTR (& zv , ce );
6736
- destroy_zend_class (& zv );
6737
- return opline ;
6725
+ zend_error_noreturn (E_ERROR ,
6726
+ "Runtime definition key collision for %s. This is a bug" , ZSTR_VAL (name ));
6738
6727
}
6739
6728
} else {
6740
- zend_string * key = zend_build_runtime_definition_key (lcname , decl -> lex_pos );
6729
+ zend_string * key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
6741
6730
6742
6731
/* RTD key is placed after lcname literal in op1 */
6743
6732
zend_add_literal_string (& key );
6744
- zend_hash_update_ptr (CG (class_table ), key , ce );
6733
+ if (!zend_hash_add_ptr (CG (class_table ), key , ce )) {
6734
+ zend_error_noreturn (E_ERROR ,
6735
+ "Runtime definition key collision for class %s. This is a bug" , ZSTR_VAL (name ));
6736
+ }
6745
6737
6746
6738
opline -> opcode = ZEND_DECLARE_CLASS ;
6747
6739
if (extends_ast && toplevel
0 commit comments