@@ -300,13 +300,13 @@ static int php_memc_do_result_callback(zval *memc_obj, zend_fcall_info *fci, zen
300
300
static memcached_return php_memc_do_serverlist_callback (const memcached_st * ptr , memcached_server_instance_st instance , void * in_context );
301
301
static memcached_return php_memc_do_stats_callback (const memcached_st * ptr , memcached_server_instance_st instance , void * in_context );
302
302
static memcached_return php_memc_do_version_callback (const memcached_st * ptr , memcached_server_instance_st instance , void * in_context );
303
-
303
+ static void php_memc_destroy ( struct memc_obj * m_obj , zend_bool persistent TSRMLS_DC );
304
304
305
305
/****************************************
306
306
Method implementations
307
307
****************************************/
308
308
309
- static void php_memcached_on_new_callback (zval * object , zend_fcall_info * fci , zend_fcall_info_cache * fci_cache , char * persistent_id , int persistent_id_len )
309
+ static zend_bool php_memcached_on_new_callback (zval * object , zend_fcall_info * fci , zend_fcall_info_cache * fci_cache , char * persistent_id , int persistent_id_len )
310
310
{
311
311
zval * retval_ptr , * pid_z ;
312
312
zval * * params [2 ];
@@ -330,12 +330,14 @@ static void php_memcached_on_new_callback(zval *object, zend_fcall_info *fci, ze
330
330
331
331
if (zend_call_function (fci , fci_cache TSRMLS_CC ) == FAILURE ) {
332
332
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Failed to invoke 'on_new' callback %s()" , Z_STRVAL_P (fci -> function_name ));
333
+ return 0 ;
333
334
}
334
335
zval_ptr_dtor (& pid_z );
335
336
336
337
if (retval_ptr ) {
337
338
zval_ptr_dtor (& retval_ptr );
338
339
}
340
+ return 1 ;
339
341
}
340
342
341
343
/* {{{ Memcached::__construct([string persistent_id[, callback on_new]]))
@@ -374,7 +376,7 @@ static PHP_METHOD(Memcached, __construct)
374
376
375
377
if (plist_key == NULL ) {
376
378
efree (plist_key );
377
- php_error_docref (NULL TSRMLS_CC , E_ERROR , "out of memory: cannot allocate peristent list handler" );
379
+ php_error_docref (NULL TSRMLS_CC , E_ERROR , "out of memory: cannot allocate persistent list handler" );
378
380
/* not reached */
379
381
}
380
382
@@ -383,8 +385,11 @@ static PHP_METHOD(Memcached, __construct)
383
385
m_obj = (struct memc_obj * ) le -> ptr ;
384
386
}
385
387
}
388
+ i_obj -> obj = m_obj ;
386
389
}
387
-
390
+
391
+ i_obj -> is_persistent = is_persistent ;
392
+
388
393
if (!m_obj ) {
389
394
m_obj = pecalloc (1 , sizeof (* m_obj ), is_persistent );
390
395
if (m_obj == NULL ) {
@@ -403,8 +408,21 @@ static PHP_METHOD(Memcached, __construct)
403
408
m_obj -> serializer = MEMC_G (serializer );
404
409
m_obj -> compression_type = MEMC_G (compression_type_real );
405
410
m_obj -> compression = 1 ;
411
+
412
+ i_obj -> obj = m_obj ;
406
413
i_obj -> is_pristine = 1 ;
407
414
415
+ if (ZEND_NUM_ARGS () >= 2 ) {
416
+ if (!php_memcached_on_new_callback (object , & fci , & fci_cache , persistent_id , persistent_id_len ) || EG (exception )) {
417
+ /* error calling or exception thrown from callback */
418
+ if (plist_key != NULL ) {
419
+ efree (plist_key );
420
+ }
421
+ php_memc_destroy (m_obj , is_persistent TSRMLS_CC );
422
+ return ;
423
+ }
424
+ }
425
+
408
426
if (is_persistent ) {
409
427
zend_rsrc_list_entry le ;
410
428
@@ -417,19 +435,10 @@ static PHP_METHOD(Memcached, __construct)
417
435
/* not reached */
418
436
}
419
437
}
420
- invoke_callback = 1 ;
421
438
}
422
-
423
- i_obj -> is_persistent = is_persistent ;
424
- i_obj -> obj = m_obj ;
425
-
426
439
if (plist_key != NULL ) {
427
440
efree (plist_key );
428
441
}
429
-
430
- if (ZEND_NUM_ARGS () >= 2 && invoke_callback ) {
431
- php_memcached_on_new_callback (object , & fci , & fci_cache , persistent_id , persistent_id_len );
432
- }
433
442
}
434
443
/* }}} */
435
444
0 commit comments