cvs: ZendEngine2 / zend.h zend_compile.c zend_interfaces.c zend_interfaces.h

From: Date: Mon, 07 Mar 2005 22:23:14 +0000
Subject: cvs: ZendEngine2 / zend.h zend_compile.c zend_interfaces.c zend_interfaces.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-3462@lists.php.net to get a copy of this message
helly Mon Mar 7 17:23:14 2005 EDT Modified files: /ZendEngine2 zend.h zend_compile.c zend_interfaces.c zend_interfaces.h Log: - New Interface Serializeable - Change signature of unserialize() callback to ease inheritance and support code reuse of handlers http://cvs.php.net/diff.php/ZendEngine2/zend.h?r1=1.273&r2=1.274&ty=u Index: ZendEngine2/zend.h diff -u ZendEngine2/zend.h:1.273 ZendEngine2/zend.h:1.274 --- ZendEngine2/zend.h:1.273 Wed Feb 23 06:15:51 2005 +++ ZendEngine2/zend.h Mon Mar 7 17:23:13 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend.h,v 1.273 2005/02/23 11:15:51 stas Exp $ */ +/* $Id: zend.h,v 1.274 2005/03/07 22:23:13 helly Exp $ */ #ifndef ZEND_H #define ZEND_H @@ -331,6 +331,8 @@ union _zend_function *__get; union _zend_function *__set; union _zend_function *__call; + union _zend_function *serialize_func; + union _zend_function *unserialize_func; zend_class_iterator_funcs iterator_funcs; @@ -341,7 +343,7 @@ /* serializer callbacks */ int (*serialize)(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC); - int (*unserialize)(zval **object, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC); + int (*unserialize)(zval **object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC); zend_class_entry **interfaces; zend_uint num_interfaces; http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.614&r2=1.615&ty=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.614 ZendEngine2/zend_compile.c:1.615 --- ZendEngine2/zend_compile.c:1.614 Sun Mar 6 11:22:02 2005 +++ ZendEngine2/zend_compile.c Mon Mar 7 17:23:13 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.614 2005/03/06 16:22:02 sniper Exp $ */ +/* $Id: zend_compile.c,v 1.615 2005/03/07 22:23:13 helly Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -3848,6 +3848,8 @@ ce->module = NULL; ce->serialize = NULL; ce->unserialize = NULL; + ce->serialize_func = NULL; + ce->unserialize_func = NULL; } } http://cvs.php.net/diff.php/ZendEngine2/zend_interfaces.c?r1=1.27&r2=1.28&ty=u Index: ZendEngine2/zend_interfaces.c diff -u ZendEngine2/zend_interfaces.c:1.27 ZendEngine2/zend_interfaces.c:1.28 --- ZendEngine2/zend_interfaces.c:1.27 Tue Mar 1 18:41:49 2005 +++ ZendEngine2/zend_interfaces.c Mon Mar 7 17:23:13 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_interfaces.c,v 1.27 2005/03/01 23:41:49 helly Exp $ */ +/* $Id: zend_interfaces.c,v 1.28 2005/03/07 22:23:13 helly Exp $ */ #include "zend.h" #include "zend_API.h" @@ -27,6 +27,7 @@ ZEND_API zend_class_entry *zend_ce_aggregate; ZEND_API zend_class_entry *zend_ce_iterator; ZEND_API zend_class_entry *zend_ce_arrayaccess; +ZEND_API zend_class_entry *zend_ce_serializeable; /* {{{ zend_call_method Only returns the returned zval if retval_ptr != NULL */ @@ -392,6 +393,79 @@ } /* }}}*/ +/* {{{ zend_user_serialize */ +int zend_user_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC) +{ + zend_class_entry * ce = Z_OBJCE_P(object); + zval *retval; + int result; + + zend_call_method_with_0_params(&object, ce, &ce->serialize_func, "serialize", &retval); + + + if (!retval || EG(exception)) { + result = FAILURE; + } else { + switch(Z_TYPE_P(retval)) { + case IS_NULL: + /* we could also make this '*buf_len = 0' but this allows to skip variables */ + result = FAILURE; + break; + case IS_STRING: + *buffer = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + *buf_len = Z_STRLEN_P(retval); + result = SUCCESS; + break; + default: /* failure */ + result = FAILURE; + break; + } + zval_ptr_dtor(&retval); + } + + if (result == FAILURE) { + zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "%s::serialize() must return a string or NULL", ce->name); + } + return result; +} +/* }}} */ + +/* {{{ zend_user_unserialize */ +int zend_user_unserialize(zval **object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC) +{ + zval * zdata; + + object_init_ex(*object, ce); + + MAKE_STD_ZVAL(zdata); + ZVAL_STRINGL(zdata, (char*)buf, buf_len, 1); + + zend_call_method_with_1_params(object, ce, &ce->unserialize_func, "unserialize", NULL, zdata); + + zval_ptr_dtor(&zdata); + + if (EG(exception)) { + return FAILURE; + } else { + return SUCCESS; + } +} +/* }}} */ + +/* {{{ zend_implement_serializeable */ +static int zend_implement_serializeable(zend_class_entry *interface, zend_class_entry *class_type TSRMLS_DC) +{ + if ((class_type->serialize && class_type->serialize != zend_user_serialize) + || (class_type->unserialize && class_type->unserialize != zend_user_unserialize) + ) { + return FAILURE; + } + class_type->serialize = zend_user_serialize; + class_type->unserialize = zend_user_unserialize; + return SUCCESS; +} +/* }}}*/ + /* {{{ function tables */ zend_function_entry zend_funcs_aggregate[] = { ZEND_ABSTRACT_ME(iterator, getIterator, NULL) @@ -428,6 +502,16 @@ {NULL, NULL, NULL} }; +static +ZEND_BEGIN_ARG_INFO(arginfo_serializeable_serialize, 0) + ZEND_ARG_INFO(0, serialized) +ZEND_END_ARG_INFO(); + +zend_function_entry zend_funcs_serializeable[] = { + ZEND_ABSTRACT_ME(serializeable, serialize, NULL) + ZEND_FENTRY(unserialize, NULL, arginfo_serializeable_serialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT|ZEND_ACC_CTOR) + {NULL, NULL, NULL} +}; /* }}} */ #define REGISTER_ITERATOR_INTERFACE(class_name, class_name_str) \ @@ -453,6 +537,8 @@ REGISTER_ITERATOR_IMPLEMENT(iterator, traversable); REGISTER_ITERATOR_INTERFACE(arrayaccess, ArrayAccess); + + REGISTER_ITERATOR_INTERFACE(serializeable, Serializeable) } /* }}} */ http://cvs.php.net/diff.php/ZendEngine2/zend_interfaces.h?r1=1.8&r2=1.9&ty=u Index: ZendEngine2/zend_interfaces.h diff -u ZendEngine2/zend_interfaces.h:1.8 ZendEngine2/zend_interfaces.h:1.9 --- ZendEngine2/zend_interfaces.h:1.8 Tue Apr 27 11:38:07 2004 +++ ZendEngine2/zend_interfaces.h Mon Mar 7 17:23:14 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_interfaces.h,v 1.8 2004/04/27 15:38:07 helly Exp $ */ +/* $Id: zend_interfaces.h,v 1.9 2005/03/07 22:23:14 helly Exp $ */ #ifndef ZEND_INTERFACES_H #define ZEND_INTERFACES_H @@ -30,6 +30,7 @@ extern ZEND_API zend_class_entry *zend_ce_aggregate; extern ZEND_API zend_class_entry *zend_ce_iterator; extern ZEND_API zend_class_entry *zend_ce_arrayaccess; +extern ZEND_API zend_class_entry *zend_ce_serializeable; typedef struct _zend_user_iterator { zend_object_iterator it;

« previous php.zend-engine.cvs (#3462) next »