~clint-fewbar/ubuntu/precise/php5/php5-5.4-merge

« back to all changes in this revision

Viewing changes to ext/spl/spl_observer.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-02-22 09:46:37 UTC
  • mfrom: (1.1.20) (0.3.18 sid)
  • Revision ID: package-import@ubuntu.com-20110222094637-nlu2tvb7oqgaarl0
Tags: 5.3.5-1ubuntu1
* Merge from debian/unstable. Remaining changes:
 - debian/control:
    * Dropped firebird2.1-dev, libc-client-dev, libmcrypt-dev as it is in universe.
    * Dropped libmysqlclient15-dev, build against mysql 5.1.
    * Dropped libcurl-dev not in the archive.
    * Suggest php5-suhosin rather than recommends.
    * Dropped php5-imap, php5-interbase, php5-mcrypt since we have versions 
      already in universe.
    * Dropped libonig-dev and libqgdbm since its in universe. (will be re-added in lucid+1)
    * Dropped locales-all.
  - modulelist: Drop imap, interbase, sybase, and mcrypt.
  - debian/rules:
    * Dropped building of mcrypt, imap, and interbase.
    * Install apport hook for php5.
    * stop mysql instance on clean just in case we failed in tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
   +----------------------------------------------------------------------+
18
18
 */
19
19
 
20
 
/* $Id: spl_observer.c 300843 2010-06-29 00:58:31Z stas $ */
 
20
/* $Id: spl_observer.c 305335 2010-11-14 18:40:08Z felipe $ */
21
21
 
22
22
#ifdef HAVE_CONFIG_H
23
23
# include "config.h"
166
166
#endif
167
167
} /* }}} */
168
168
 
169
 
void spl_object_storage_detach(spl_SplObjectStorage *intern, zval *obj TSRMLS_DC) /* {{{ */
 
169
int spl_object_storage_detach(spl_SplObjectStorage *intern, zval *obj TSRMLS_DC) /* {{{ */
170
170
{
171
171
#if HAVE_PACKED_OBJECT_VALUE
172
 
        zend_hash_del(&intern->storage, (char*)&Z_OBJVAL_P(obj), sizeof(zend_object_value));
 
172
        return zend_hash_del(&intern->storage, (char*)&Z_OBJVAL_P(obj), sizeof(zend_object_value));
173
173
#else
174
174
        {
175
175
                zend_object_value zvalue;
176
176
                memset(&zvalue, 0, sizeof(zend_object_value));
177
177
                zvalue.handle = Z_OBJ_HANDLE_P(obj);
178
178
                zvalue.handlers = Z_OBJ_HT_P(obj);
179
 
                zend_hash_del(&intern->storage, (char*)&zvalue, sizeof(zend_object_value));
 
179
                return zend_hash_del(&intern->storage, (char*)&zvalue, sizeof(zend_object_value));
180
180
        }
181
181
#endif
182
182
} /* }}}*/
255
255
        *is_temp = 0;
256
256
 
257
257
        props = Z_OBJPROP_P(obj);
 
258
        zend_hash_del(props, "\x00gcdata", sizeof("\x00gcdata"));
 
259
 
258
260
        if (intern->debug_info == NULL) {
259
261
                ALLOC_HASHTABLE(intern->debug_info);
260
262
                ZEND_INIT_SYMTABLE_EX(intern->debug_info, zend_hash_num_elements(props) + 1, 0);
269
271
                zend_hash_internal_pointer_reset_ex(&intern->storage, &pos);
270
272
                while (zend_hash_get_current_data_ex(&intern->storage, (void **)&element, &pos) == SUCCESS) {
271
273
                                php_spl_object_hash(element->obj, md5str TSRMLS_CC);
272
 
                                Z_ADDREF_P(element->obj);
273
 
                                Z_ADDREF_P(element->inf);
274
274
                                MAKE_STD_ZVAL(tmp);
275
275
                                array_init(tmp);
 
276
                                /* Incrementing the refcount of obj and inf would confuse the garbage collector.
 
277
                                 * Prefer to null the destructor */
 
278
                                Z_ARRVAL_P(tmp)->pDestructor = NULL;
276
279
                                add_assoc_zval_ex(tmp, "obj", sizeof("obj"), element->obj);
277
280
                                add_assoc_zval_ex(tmp, "inf", sizeof("inf"), element->inf);
278
281
                                add_assoc_zval_ex(storage, md5str, 33, tmp);
288
291
}
289
292
/* }}} */
290
293
 
 
294
/* overriden for garbage collection
 
295
 * This is very hacky, but unfortunately the garbage collector can only query objects for
 
296
 * dependencies through get_properties */
 
297
static HashTable *spl_object_storage_get_properties(zval *obj TSRMLS_DC) /* {{{ */
 
298
{
 
299
        spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(obj TSRMLS_CC);
 
300
        spl_SplObjectStorageElement *element;
 
301
        HashTable *props;
 
302
        HashPosition pos;
 
303
        zval *gcdata_arr = NULL,
 
304
                 **gcdata_arr_pp;
 
305
 
 
306
        props = std_object_handlers.get_properties(obj TSRMLS_CC);
 
307
        
 
308
        if (!GC_G(gc_active)) {
 
309
                zend_hash_del(props, "\x00gcdata", sizeof("\x00gcdata"));
 
310
                return props;
 
311
        }
 
312
 
 
313
        if (props->nApplyCount > 0) {
 
314
                return props;
 
315
        }
 
316
 
 
317
        /* clean \x00gcdata, as it may be out of date */
 
318
        if (zend_hash_find(props, "\x00gcdata", sizeof("\x00gcdata"), (void**) &gcdata_arr_pp) == SUCCESS) {
 
319
                gcdata_arr = *gcdata_arr_pp;
 
320
                zend_hash_clean(Z_ARRVAL_P(gcdata_arr));
 
321
        }
 
322
 
 
323
        if (gcdata_arr == NULL) {
 
324
                MAKE_STD_ZVAL(gcdata_arr);
 
325
                array_init(gcdata_arr);
 
326
                /* don't decrease refcount of members when destroying */
 
327
                Z_ARRVAL_P(gcdata_arr)->pDestructor = NULL;
 
328
 
 
329
                /* name starts with \x00 to make tampering in user-land more difficult */
 
330
                zend_hash_add(props, "\x00gcdata", sizeof("\x00gcdata"), &gcdata_arr, sizeof(gcdata_arr), NULL);
 
331
        }
 
332
 
 
333
        zend_hash_internal_pointer_reset_ex(&intern->storage, &pos);
 
334
        while (zend_hash_get_current_data_ex(&intern->storage, (void **)&element, &pos) == SUCCESS) {
 
335
                add_next_index_zval(gcdata_arr, element->obj);
 
336
                add_next_index_zval(gcdata_arr, element->inf);
 
337
                zend_hash_move_forward_ex(&intern->storage, &pos);
 
338
        }
 
339
 
 
340
        return props;
 
341
}
 
342
/* }}} */
 
343
 
291
344
static int spl_object_storage_compare_info(spl_SplObjectStorageElement *e1, spl_SplObjectStorageElement *e2 TSRMLS_DC) /* {{{ */
292
345
{
293
346
        zval result;
412
465
        spl_SplObjectStorage *intern = (spl_SplObjectStorage *)zend_object_store_get_object(getThis() TSRMLS_CC);
413
466
        spl_SplObjectStorage *other;
414
467
        spl_SplObjectStorageElement *element;
415
 
        HashPosition pos;
416
468
 
417
469
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &obj, spl_ce_SplObjectStorage) == FAILURE) {
418
470
                return;
420
472
 
421
473
        other = (spl_SplObjectStorage *)zend_object_store_get_object(obj TSRMLS_CC);
422
474
 
423
 
        zend_hash_internal_pointer_reset_ex(&other->storage, &pos);
424
 
        while (zend_hash_get_current_data_ex(&other->storage, (void **)&element, &pos) == SUCCESS) {
425
 
                spl_object_storage_detach(intern, element->obj TSRMLS_CC);
426
 
                zend_hash_move_forward_ex(&other->storage, &pos);
 
475
        zend_hash_internal_pointer_reset(&other->storage);
 
476
        while (zend_hash_get_current_data(&other->storage, (void **)&element) == SUCCESS) {
 
477
                if (spl_object_storage_detach(intern, element->obj TSRMLS_CC) == FAILURE) {
 
478
                        zend_hash_move_forward(&other->storage);
 
479
                }
427
480
        }
428
481
 
429
482
        zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos);
451
504
{
452
505
        spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
453
506
        
 
507
        if (zend_parse_parameters_none() == FAILURE) {
 
508
                return;
 
509
        }
 
510
        
454
511
        RETURN_LONG(zend_hash_num_elements(&intern->storage));
455
512
} /* }}} */
456
513
 
460
517
{
461
518
        spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
462
519
        
 
520
        if (zend_parse_parameters_none() == FAILURE) {
 
521
                return;
 
522
        }
 
523
        
463
524
        zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos);
464
525
        intern->index = 0;
465
526
} /* }}} */
470
531
{
471
532
        spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
472
533
        
 
534
        if (zend_parse_parameters_none() == FAILURE) {
 
535
                return;
 
536
        }
 
537
        
473
538
        RETURN_BOOL(zend_hash_has_more_elements_ex(&intern->storage, &intern->pos) == SUCCESS);
474
539
} /* }}} */
475
540
 
479
544
{
480
545
        spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
481
546
        
 
547
        if (zend_parse_parameters_none() == FAILURE) {
 
548
                return;
 
549
        }
 
550
        
482
551
        RETURN_LONG(intern->index);
483
552
} /* }}} */
484
553
 
489
558
        spl_SplObjectStorageElement *element;
490
559
        spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
491
560
        
 
561
        if (zend_parse_parameters_none() == FAILURE) {
 
562
                return;
 
563
        }
 
564
        
492
565
        if (zend_hash_get_current_data_ex(&intern->storage, (void**)&element, &intern->pos) == FAILURE) {
493
566
                return;
494
567
        }
501
574
{
502
575
        spl_SplObjectStorageElement *element;
503
576
        spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
577
 
 
578
        if (zend_parse_parameters_none() == FAILURE) {
 
579
                return;
 
580
        }
504
581
        
505
582
        if (zend_hash_get_current_data_ex(&intern->storage, (void**)&element, &intern->pos) == FAILURE) {
506
583
                return;
534
611
{
535
612
        spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
536
613
        
 
614
        if (zend_parse_parameters_none() == FAILURE) {
 
615
                return;
 
616
        }
 
617
        
537
618
        zend_hash_move_forward_ex(&intern->storage, &intern->pos);
538
619
        intern->index++;
539
620
} /* }}} */
550
631
        php_serialize_data_t var_hash;
551
632
        smart_str buf = {0};
552
633
 
 
634
        if (zend_parse_parameters_none() == FAILURE) {
 
635
                return;
 
636
        }
 
637
 
553
638
        PHP_VAR_SERIALIZE_INIT(var_hash);
554
 
 
 
639
        
555
640
        /* storage */
556
641
        smart_str_appendl(&buf, "x:i:", 4);
557
642
        smart_str_append_long(&buf, zend_hash_num_elements(&intern->storage));
799
884
SPL_METHOD(MultipleIterator, getFlags)
800
885
{
801
886
        spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
887
        
 
888
        if (zend_parse_parameters_none() == FAILURE) {
 
889
                return;
 
890
        }
802
891
        RETURN_LONG(intern->flags);
803
892
}
804
893
/* }}} */
862
951
        zval                        *it;
863
952
 
864
953
        intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
954
        
 
955
        if (zend_parse_parameters_none() == FAILURE) {
 
956
                return;
 
957
        }
865
958
 
866
959
        zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos);
867
960
        while (zend_hash_get_current_data_ex(&intern->storage, (void**)&element, &intern->pos) == SUCCESS && !EG(exception)) {
881
974
        zval                        *it;
882
975
 
883
976
        intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
977
        
 
978
        if (zend_parse_parameters_none() == FAILURE) {
 
979
                return;
 
980
        }
884
981
 
885
982
        zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos);
886
983
        while (zend_hash_get_current_data_ex(&intern->storage, (void**)&element, &intern->pos) == SUCCESS && !EG(exception)) {
901
998
        long                         expect, valid;
902
999
 
903
1000
        intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
1001
        
 
1002
        if (zend_parse_parameters_none() == FAILURE) {
 
1003
                return;
 
1004
        }
904
1005
 
905
1006
        if (!zend_hash_num_elements(&intern->storage)) {
906
1007
                RETURN_FALSE;
1005
1106
{
1006
1107
        spl_SplObjectStorage        *intern;
1007
1108
        intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
1109
        
 
1110
        if (zend_parse_parameters_none() == FAILURE) {
 
1111
                return;
 
1112
        }
1008
1113
 
1009
1114
        spl_multiple_iterator_get_all(intern, SPL_MULTIPLE_ITERATOR_GET_ALL_CURRENT, return_value TSRMLS_CC);
1010
1115
}
1016
1121
{
1017
1122
        spl_SplObjectStorage        *intern;
1018
1123
        intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
1124
        
 
1125
        if (zend_parse_parameters_none() == FAILURE) {
 
1126
                return;
 
1127
        }
1019
1128
 
1020
1129
        spl_multiple_iterator_get_all(intern, SPL_MULTIPLE_ITERATOR_GET_ALL_KEY, return_value TSRMLS_CC);
1021
1130
}
1064
1173
        REGISTER_SPL_STD_CLASS_EX(SplObjectStorage, spl_SplObjectStorage_new, spl_funcs_SplObjectStorage);
1065
1174
        memcpy(&spl_handler_SplObjectStorage, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1066
1175
 
 
1176
        spl_handler_SplObjectStorage.get_properties  = spl_object_storage_get_properties;
1067
1177
        spl_handler_SplObjectStorage.get_debug_info  = spl_object_storage_debug_info;
1068
1178
        spl_handler_SplObjectStorage.compare_objects = spl_object_storage_compare_objects;
1069
1179
        spl_handler_SplObjectStorage.clone_obj       = spl_object_storage_clone;