@@ -214,18 +214,9 @@ ZEND_API zend_result zend_get_attribute_value(zval *ret, zend_attribute *attr, u
214
214
return SUCCESS ;
215
215
}
216
216
217
- static zend_result call_attribute_constructor (
218
- zend_attribute * attr , zend_class_entry * ce , zend_object * obj ,
219
- zval * args , uint32_t argc , HashTable * named_params , zend_string * filename )
217
+ ZEND_API zend_result zend_get_attribute_object (zval * obj , zend_class_entry * attribute_ce , zend_attribute * attribute_data , zend_class_entry * scope , zend_string * filename )
220
218
{
221
- zend_function * ctor = ce -> constructor ;
222
219
zend_execute_data * call = NULL ;
223
- ZEND_ASSERT (ctor != NULL );
224
-
225
- if (!(ctor -> common .fn_flags & ZEND_ACC_PUBLIC )) {
226
- zend_throw_error (NULL , "Attribute constructor of class %s must be public" , ZSTR_VAL (ce -> name ));
227
- return FAILURE ;
228
- }
229
220
230
221
if (filename ) {
231
222
/* Set up dummy call frame that makes it look like the attribute was invoked
@@ -244,7 +235,7 @@ static zend_result call_attribute_constructor(
244
235
opline = (zend_op * )(call + 1 );
245
236
memset (opline , 0 , sizeof (zend_op ));
246
237
opline -> opcode = ZEND_DO_FCALL ;
247
- opline -> lineno = attr -> lineno ;
238
+ opline -> lineno = attribute_data -> lineno ;
248
239
249
240
call -> opline = opline ;
250
241
call -> call = NULL ;
@@ -255,57 +246,17 @@ static zend_result call_attribute_constructor(
255
246
memset (call -> func , 0 , sizeof (zend_function ));
256
247
call -> func -> type = ZEND_USER_FUNCTION ;
257
248
call -> func -> op_array .fn_flags =
258
- attr -> flags & ZEND_ATTRIBUTE_STRICT_TYPES ? ZEND_ACC_STRICT_TYPES : 0 ;
249
+ attribute_data -> flags & ZEND_ATTRIBUTE_STRICT_TYPES ? ZEND_ACC_STRICT_TYPES : 0 ;
259
250
call -> func -> op_array .fn_flags |= ZEND_ACC_CALL_VIA_TRAMPOLINE ;
260
251
call -> func -> op_array .filename = filename ;
261
252
262
253
EG (current_execute_data ) = call ;
263
254
}
264
255
265
- zend_call_known_function (ctor , obj , obj -> ce , NULL , argc , args , named_params );
266
-
267
- if (filename ) {
268
- EG (current_execute_data ) = call -> prev_execute_data ;
269
- zend_vm_stack_free_call_frame (call );
270
- }
271
-
272
- if (EG (exception )) {
273
- zend_object_store_ctor_failed (obj );
274
- return FAILURE ;
275
- }
276
-
277
- return SUCCESS ;
278
- }
279
-
280
- static void attribute_ctor_cleanup (zval * obj , zval * args , uint32_t argc , HashTable * named_params )
281
- {
282
- if (obj ) {
283
- zval_ptr_dtor (obj );
284
- }
285
-
286
- if (args ) {
287
- uint32_t i ;
288
-
289
- for (i = 0 ; i < argc ; i ++ ) {
290
- zval_ptr_dtor (& args [i ]);
291
- }
292
-
293
- efree (args );
294
- }
295
-
296
- if (named_params ) {
297
- zend_array_destroy (named_params );
298
- }
299
- }
300
-
301
- ZEND_API zend_result zend_get_attribute_object (zval * obj , zend_class_entry * attribute_ce , zend_attribute * attribute_data , zend_class_entry * scope , zend_string * filename )
302
- {
303
256
zval * args = NULL ;
304
257
HashTable * named_params = NULL ;
305
258
306
- if (SUCCESS != object_init_ex (obj , attribute_ce )) {
307
- return FAILURE ;
308
- }
259
+ zend_result result = FAILURE ;
309
260
310
261
uint32_t argc = 0 ;
311
262
if (attribute_data -> argc ) {
@@ -314,8 +265,8 @@ ZEND_API zend_result zend_get_attribute_object(zval *obj, zend_class_entry *attr
314
265
for (uint32_t i = 0 ; i < attribute_data -> argc ; i ++ ) {
315
266
zval val ;
316
267
if (FAILURE == zend_get_attribute_value (& val , attribute_data , i , scope )) {
317
- attribute_ctor_cleanup ( obj , args , argc , named_params ) ;
318
- return FAILURE ;
268
+ result = FAILURE ;
269
+ goto out ;
319
270
}
320
271
if (attribute_data -> args [i ].name ) {
321
272
if (!named_params ) {
@@ -329,20 +280,25 @@ ZEND_API zend_result zend_get_attribute_object(zval *obj, zend_class_entry *attr
329
280
}
330
281
}
331
282
332
- if (attribute_ce -> constructor ) {
333
- if (FAILURE == call_attribute_constructor (attribute_data , attribute_ce , Z_OBJ_P (obj ), args , argc , named_params , filename )) {
334
- attribute_ctor_cleanup (obj , args , argc , named_params );
335
- return FAILURE ;
336
- }
337
- } else if (argc || named_params ) {
338
- attribute_ctor_cleanup (obj , args , argc , named_params );
339
- zend_throw_error (NULL , "Attribute class %s does not have a constructor, cannot pass arguments" , ZSTR_VAL (attribute_ce -> name ));
340
- return FAILURE ;
283
+ result = object_init_with_constructor (obj , attribute_ce , argc , args , named_params );
284
+
285
+ out :
286
+ for (uint32_t i = 0 ; i < argc ; i ++ ) {
287
+ zval_ptr_dtor (& args [i ]);
341
288
}
342
289
343
- attribute_ctor_cleanup ( NULL , args , argc , named_params );
290
+ efree ( args );
344
291
345
- return SUCCESS ;
292
+ if (named_params ) {
293
+ zend_array_destroy (named_params );
294
+ }
295
+
296
+ if (filename ) {
297
+ EG (current_execute_data ) = call -> prev_execute_data ;
298
+ zend_vm_stack_free_call_frame (call );
299
+ }
300
+
301
+ return result ;
346
302
}
347
303
348
304
static const char * target_names [] = {
0 commit comments