cvs: /php4/ext/wddx wddx.c

From: Date: Thu, 17 Feb 2000 23:08:17 +0000
Subject: cvs: /php4/ext/wddx wddx.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-10419@lists.php.net to get a copy of this message
andrei Thu Feb 17 15:08:17 2000 EDT Modified files: /php4/ext/wddx wddx.c Log: Updated to use Zend's internal doubly-linked list instead of dlist.[ch] implementation. Also fixed serialization to always output objects as struct. In the past, if the object did not have any member variables initialized it would've been output as array of length 0. Index: php4/ext/wddx/wddx.c diff -u php4/ext/wddx/wddx.c:1.23 php4/ext/wddx/wddx.c:1.24 --- php4/ext/wddx/wddx.c:1.23 Wed Feb 2 13:53:27 2000 +++ php4/ext/wddx/wddx.c Thu Feb 17 15:07:47 2000 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: wddx.c,v 1.23 2000/02/02 21:53:27 andrei Exp $ */ +/* $Id: wddx.c,v 1.24 2000/02/17 23:07:47 andrei Exp $ */ #include "php.h" #include "php_wddx.h" @@ -68,7 +68,7 @@ static int le_wddx; struct _wddx_packet { - DLIST *packet_head; + zend_llist *packet_head; int packet_length; }; @@ -199,10 +199,11 @@ /* {{{ _php_free_packet_chunk */ -static void _php_free_packet_chunk(char **chunk_ptr) +static void _php_free_packet_chunk(void *data) { - if ((*chunk_ptr)) - efree((*chunk_ptr)); + char **chunk_ptr = (char **)data; + if (*chunk_ptr) + efree(*chunk_ptr); } /* }}} */ @@ -210,7 +211,8 @@ /* {{{ php_wddx_destructor */ void php_wddx_destructor(wddx_packet *packet) { - dlst_kill(packet->packet_head, (void (*)(void *))_php_free_packet_chunk); + zend_llist_destroy(packet->packet_head); + efree(packet->packet_head); efree(packet); } /* }}} */ @@ -229,12 +231,13 @@ /* {{{ php_wddx_add_chunk */ void php_wddx_add_chunk(wddx_packet *packet, char *str) { - char **chunk_ptr; - - chunk_ptr = (char**)dlst_newnode(sizeof(char *)); - (*chunk_ptr) = estrdup(str); - dlst_insertafter(packet->packet_head, chunk_ptr, PHP_DLST_TAIL(packet->packet_head)); - packet->packet_length += strlen(str); + char *chunk; + int len; + + len = strlen(str); + chunk = estrndup(str, len); + zend_llist_add_element(packet->packet_head, &chunk); + packet->packet_length += len; } /* }}} */ @@ -242,15 +245,15 @@ /* {{{ php_wddx_gather */ char* php_wddx_gather(wddx_packet *packet) { - char **chunk; + char **chunk_ptr; char *buf; buf = (char *)emalloc(packet->packet_length+1); buf[0] = '\0'; - for(chunk=dlst_first(packet->packet_head); - chunk!=NULL; - chunk = dlst_next(chunk)) { - strcat(buf, *chunk); + for(chunk_ptr = zend_llist_get_first(packet->packet_head); + chunk_ptr != NULL; + chunk_ptr = zend_llist_get_next(packet->packet_head)) { + strcat(buf, *chunk_ptr); } return buf; @@ -372,29 +375,29 @@ target_hash = HASH_OF(var); - zend_hash_internal_pointer_reset(target_hash); - - hash_type = zend_hash_get_current_key(target_hash, &key, &idx); - - if (hash_type == HASH_KEY_IS_STRING) { + /* If variable is an object, always use struct and serialize its classname */ + if (var->type == IS_OBJECT) { php_wddx_add_chunk(packet, WDDX_STRUCT_S); - efree(key); - } else { - sprintf(tmp_buf, WDDX_ARRAY_S, zend_hash_num_elements(target_hash)); - php_wddx_add_chunk(packet, tmp_buf); - } - - /* If variable is an object, serialize its classname */ - if (var->type == IS_OBJECT) - { sprintf(tmp_buf, WDDX_VAR_S, PHP_CLASS_NAME_VAR); php_wddx_add_chunk(packet, tmp_buf); php_wddx_add_chunk(packet, WDDX_STRING_S); php_wddx_add_chunk(packet, var->value.obj.ce->name); php_wddx_add_chunk(packet, WDDX_STRING_E); php_wddx_add_chunk(packet, WDDX_VAR_E); + } else { + zend_hash_internal_pointer_reset(target_hash); + + hash_type = zend_hash_get_current_key(target_hash, &key, &idx); + + if (hash_type == HASH_KEY_IS_STRING) { + php_wddx_add_chunk(packet, WDDX_STRUCT_S); + efree(key); + } else { + sprintf(tmp_buf, WDDX_ARRAY_S, zend_hash_num_elements(target_hash)); + php_wddx_add_chunk(packet, tmp_buf); + } } - + while(zend_hash_get_current_data(target_hash, (void**)&ent) == SUCCESS) { if (hash_type == HASH_KEY_IS_STRING) { ent_type = zend_hash_get_current_key(target_hash, &key, &idx); @@ -412,7 +415,7 @@ zend_hash_move_forward(target_hash); } - if (hash_type == HASH_KEY_IS_STRING) + if (var->type == IS_OBJECT || hash_type == HASH_KEY_IS_STRING) php_wddx_add_chunk(packet, WDDX_STRUCT_E); else php_wddx_add_chunk(packet, WDDX_ARRAY_E); @@ -828,7 +831,9 @@ packet = emalloc(sizeof(wddx_packet)); if(!packet) return NULL; - packet->packet_head = dlst_init(); + packet->packet_head = (zend_llist *)emalloc(sizeof(zend_llist)); + zend_llist_init(packet->packet_head, sizeof(char *), + _php_free_packet_chunk, 0); packet->packet_length = 0; return packet;

« previous php.version4 (#10419) next »