2222#include "zend_enum_arginfo.h"
2323#include "zend_interfaces.h"
2424#include "zend_enum.h"
25- #include "zend_exceptions.h"
2625
2726#define ZEND_ENUM_DISALLOW_MAGIC_METHOD (propertyName , methodName ) \
2827 do { \
@@ -185,16 +184,14 @@ void zend_enum_add_interfaces(zend_class_entry *ce)
185184 }
186185}
187186
188- void zend_enum_build_backed_enum_table (zend_class_entry * ce )
187+ zend_result zend_enum_build_backed_enum_table (zend_class_entry * ce )
189188{
190189 ZEND_ASSERT (ce -> ce_flags & ZEND_ACC_ENUM );
191190 ZEND_ASSERT (ce -> type == ZEND_USER_CLASS );
192191
193192 uint32_t backing_type = ce -> enum_backing_type ;
194193 ZEND_ASSERT (backing_type != IS_UNDEF );
195194
196- ZEND_ASSERT (ce -> ce_flags & ZEND_ACC_CONSTANTS_UPDATED );
197-
198195 ce -> backed_enum_table = emalloc (sizeof (HashTable ));
199196 zend_hash_init (ce -> backed_enum_table , 0 , NULL , ZVAL_PTR_DTOR , 0 );
200197
@@ -213,34 +210,44 @@ void zend_enum_build_backed_enum_table(zend_class_entry *ce)
213210 zval * case_value = zend_enum_fetch_case_value (Z_OBJ_P (c_value ));
214211
215212 if (ce -> enum_backing_type != Z_TYPE_P (case_value )) {
216- zend_error_noreturn ( E_COMPILE_ERROR , "Enum case type %s does not match enum backing type %s" ,
213+ zend_throw_error ( NULL , "Enum case type %s does not match enum backing type %s" ,
217214 zend_get_type_by_const (Z_TYPE_P (case_value )),
218215 zend_get_type_by_const (ce -> enum_backing_type ));
216+ goto failure ;
219217 }
220218
221219 if (ce -> enum_backing_type == IS_LONG ) {
222220 zend_long long_key = Z_LVAL_P (case_value );
223221 zval * existing_case_name = zend_hash_index_find (ce -> backed_enum_table , long_key );
224222 if (existing_case_name ) {
225- zend_error_noreturn ( E_COMPILE_ERROR , "Duplicate value in enum %s for cases %s and %s" ,
223+ zend_throw_error ( NULL , "Duplicate value in enum %s for cases %s and %s" ,
226224 ZSTR_VAL (enum_class_name ),
227225 Z_STRVAL_P (existing_case_name ),
228226 ZSTR_VAL (name ));
227+ goto failure ;
229228 }
230229 zend_hash_index_add_new (ce -> backed_enum_table , long_key , case_name );
231230 } else {
232231 ZEND_ASSERT (ce -> enum_backing_type == IS_STRING );
233232 zend_string * string_key = Z_STR_P (case_value );
234233 zval * existing_case_name = zend_hash_find (ce -> backed_enum_table , string_key );
235234 if (existing_case_name != NULL ) {
236- zend_error_noreturn ( E_COMPILE_ERROR , "Duplicate value in enum %s for cases %s and %s" ,
235+ zend_throw_error ( NULL , "Duplicate value in enum %s for cases %s and %s" ,
237236 ZSTR_VAL (enum_class_name ),
238237 Z_STRVAL_P (existing_case_name ),
239238 ZSTR_VAL (name ));
239+ goto failure ;
240240 }
241241 zend_hash_add_new (ce -> backed_enum_table , string_key , case_name );
242242 }
243243 } ZEND_HASH_FOREACH_END ();
244+
245+ return SUCCESS ;
246+
247+ failure :
248+ zend_hash_release (ce -> backed_enum_table );
249+ ce -> backed_enum_table = NULL ;
250+ return FAILURE ;
244251}
245252
246253static ZEND_NAMED_FUNCTION (zend_enum_cases_func )
@@ -270,7 +277,9 @@ static ZEND_NAMED_FUNCTION(zend_enum_cases_func)
270277ZEND_API zend_result zend_enum_get_case_by_value (zend_object * * result , zend_class_entry * ce , zend_long long_key , zend_string * string_key , bool try )
271278{
272279 if (ce -> type == ZEND_USER_CLASS && !(ce -> ce_flags & ZEND_ACC_CONSTANTS_UPDATED )) {
273- zend_update_class_constants (ce );
280+ if (zend_update_class_constants (ce ) == FAILURE ) {
281+ return FAILURE ;
282+ }
274283 }
275284
276285 zval * case_name_zv ;
0 commit comments