What engine are you working with 1 or 2? -brad --- "Tim Daly, Jr." <[EMAIL PROTECTED]> wrote: > > Hi everybody. I'm working on an extension that creates classes, and I > want to add class variables to the classes. It looks like, > internally, class variables are stored in the > zend_class_entry.default_properties hash. Manipulating this hash has > the effect desired, however I seem to have misunderstood the memory > management issues somehow; the code below causes leaks and crashes. > > Is there an official way to add class variables to a class from C? Is > there anything obviously wrong with the code below? > > Thanks!! > -Tim > > static zend_class_entry *class_name_class_entry; > static zend_class_entry tmp_class_entry; > > int add_default_property_null(zend_class_entry *class_entry, > const char *name) > { > zval *property; > int ret; > > MAKE_STD_ZVAL(property); > ZVAL_NULL(property); > return zend_hash_update(&class_entry->default_properties, name, > strlen(name)+1, (void *)&property, sizeof(zval > *), NULL); > } > > > > int add_default_property_zval(zend_class_entry *class_entry, > const char *name, > zval **value) > { > zval *aval; > > MAKE_STD_ZVAL(aval); > *aval = **value; > zval_add_ref(&aval); > zval_copy_ctor(aval); > return zend_hash_update(&class_entry->default_properties, name, > strlen(name)+1, (void *)&aval, sizeof(zval *), > NULL); > } > > > void define_a_class() > { > /* make a class with two properties, one of which is an array */ > zval *wrapper; > zval *array; > > INIT_CLASS_ENTRY(tmp_class_entry, "class_name", class_name_functions); > class_name_class_entry = zend_register_internal_class(&tmp_class_entry); > > add_default_property_null(class_name_class_entry, "prop_name"); > > MAKE_STD_ZVAL(array); > array_init(array); > add_next_index_string(array, "foo", 1); > add_default_property_zval(class_name_class_entry, "prop_name1", &array); > > } > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, visit: http://www.php.net/unsub.php >
__________________________________________________ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos & More http://faith.yahoo.com -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php