Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

This adds a debug handler to DOM objects. #8

Closed
wants to merge 1 commit into from

3 participants

@tml

No description provided.

@cataphract

This seems a to be a lot code that could be replaced with just returning the prop_handler table. Why do you have it this way? Does the implementation of read_property called by zend_read_property do some magic I'm unaware for?

Also, it seems that here you're ignoring the dynamic properties that might exist in the object property hash table.

@tml

In fact, the dynamic properties are what I'm trying to give value to by using zend_read_property. If we only return the prop_handler table, we get "&UNKNOWN:0" as the value for each property. By using zend_read_property, we can actually provide meaningful values for these.

@tml

I should note that this is just an attempt to get some movement on a debug handler for DOM - I would certainly not object to someone wanting to write a better implementation; for example, I just blatantly ignore anything that's not a string, bool, long, double, or array because my attempts to handle objects like 'parentNode->firstChild->parentNode->firstChild->...' quickly became a mess.

@dsp
Owner

this was obviously commited as d046827

@dsp dsp closed this
@dstogov dstogov referenced this pull request from a commit
@dstogov dstogov Added GC checks and improvements 276080e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2012
  1. @tml

    Added DOM Debug handler

    tml authored
This page is out of date. Refresh to see the latest.
Showing with 64 additions and 0 deletions.
  1. +64 −0 ext/dom/php_dom.c
View
64 ext/dom/php_dom.c
@@ -466,6 +466,69 @@ static int dom_property_exists(zval *object, zval *member, int check_empty, cons
}
/* }}} */
+static HashTable* dom_get_debug_info_helper(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
+{
+ dom_object *obj = (dom_object *)zend_object_store_get_object(object TSRMLS_CC);
+ HashTable *debug_info, *props;
+ HashPosition pos;
+ dom_prop_handler *entry;
+
+ *is_temp = 1;
+
+ ALLOC_HASHTABLE(debug_info);
+ if (! obj->prop_handler) {
+ return debug_info;
+ }
+
+ props = obj->prop_handler;
+ ZEND_INIT_SYMTABLE_EX(debug_info, zend_hash_num_elements(props) + 1, 0);
+
+ zend_hash_internal_pointer_reset_ex(props, &pos);
+ while (zend_hash_get_current_data_ex(props, (void **)&entry, &pos) == SUCCESS) {
+ zval member;
+ zval *value;
+
+ char *string_key=NULL;
+ uint string_length=0;
+ ulong num_key;
+
+ zend_hash_get_current_key_ex(props, &string_key, &string_length, &num_key, 0, &pos);
+
+ INIT_ZVAL(member);
+ ZVAL_STRINGL(&member, string_key, string_length, 0);
+ value = zend_read_property(Z_OBJCE_P(object), object, Z_STRVAL(member), Z_STRLEN(member)-1, 1 TSRMLS_CC);
+ if (value != EG(uninitialized_zval_ptr)) {
+ switch(Z_TYPE_P(value)) {
+ case IS_STRING:
+ case IS_BOOL:
+ case IS_LONG:
+ case IS_DOUBLE:
+ case IS_ARRAY:
+ zend_hash_add(debug_info, string_key, string_length, &value, sizeof(zval *), NULL);
+ break;
+
+ default:
+ ZVAL_NULL(value);
+ zend_hash_add(debug_info, string_key, string_length, &value, sizeof(zval *), NULL);
+ break;
+ }
+ } else {
+ ZVAL_NULL(value);
+ zend_hash_add(debug_info, string_key, string_length, &value, sizeof(zval *), NULL);
+ }
+ zend_hash_move_forward_ex(props, &pos);
+ }
+
+ return debug_info;
+}
+/* }}} */
+
+static HashTable* dom_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
+{
+ return dom_get_debug_info_helper(object, is_temp);
+}
+/* }}} */
+
void *php_dom_export_node(zval *object TSRMLS_DC) /* {{{ */
{
php_libxml_node_object *intern;
@@ -585,6 +648,7 @@ PHP_MINIT_FUNCTION(dom)
dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
dom_object_handlers.clone_obj = dom_objects_store_clone_obj;
dom_object_handlers.has_property = dom_property_exists;
+ dom_object_handlers.get_debug_info = dom_get_debug_info;
zend_hash_init(&classes, 0, NULL, NULL, 1);
Something went wrong with that request. Please try again.