[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pecl-cvs
Subject:    [PECL-CVS] cvs: pecl /newt newt.c php_newt.h
From:       "Michael Spector" <michael () php ! net>
Date:       2004-12-27 17:57:12
Message-ID: cvsmichael1104170232 () cvsserver
[Download RAW message or body]

michael		Mon Dec 27 12:57:12 2004 EDT

  Modified files:              
    /pecl/newt	newt.c php_newt.h 
  Log:
  - changed way of passing zvals to newt functions (pass keys of zvals stored in \
                hash, instead of serialized string value)
  - fixed old bugs, added new ones :)
  
  


["michael-20041227125712.txt" (text/plain)]

http://cvs.php.net/diff.php/pecl/newt/newt.c?r1=1.37&r2=1.38&ty=u
Index: pecl/newt/newt.c
diff -u pecl/newt/newt.c:1.37 pecl/newt/newt.c:1.38
--- pecl/newt/newt.c:1.37	Sun Dec 19 18:30:54 2004
+++ pecl/newt/newt.c	Mon Dec 27 12:57:10 2004
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: newt.c,v 1.37 2004/12/19 23:30:54 michael Exp $ */
+/* $Id: newt.c,v 1.38 2004/12/27 17:57:10 michael Exp $ */
 
 #include <newt.h>
 
@@ -26,7 +26,6 @@
 
 #include "php.h"
 #include "php_ini.h"
-#include "ext/standard/php_var.h"
 #include "ext/standard/info.h"
 #include "php_newt.h"
 #include "newt_vcall.h"
@@ -205,16 +204,51 @@
 
 /* {{{ php_newt_init_globals
  */
-static void php_newt_init_globals (zend_newt_globals *newt_globals)
+void php_newt_init_globals (zend_newt_globals *newt_globals TSRMLS_DC)
 {
-	newt_globals->z_newt_help_callback = NULL;
 	newt_globals->newt_has_inited = 0;
+
+	newt_globals->php_newt_help_cb_key = emalloc(sizeof("php_newt_help_cb_key"));
+	strcpy (newt_globals->php_newt_help_cb_key, "php_newt_help_cb_key");
+
+	zend_hash_init(&newt_globals->callbacks, 0, NULL, (void (*)(void *)) \
php_newt_free_cb, 0); +	zend_hash_init(&newt_globals->data, 0, NULL, ZVAL_PTR_DTOR, \
0); +}
+/* }}} */
+
+/* {{{ php_newt_destroy_globals
+ */
+void php_newt_destroy_globals(zend_newt_globals *newt_globals TSRMLS_DC)
+{
+	if (newt_globals->newt_has_inited) {
+	  newtFinished();
+	}
+	efree (newt_globals->php_newt_help_cb_key);
+	newt_globals->php_newt_help_cb_key = NULL;
+
+	zend_hash_clean (&newt_globals->callbacks);
+	zend_hash_clean (&newt_globals->data);
+}
+/* }}} */
+
+/* {{{ php_newt_free_cb
+ */
+void php_newt_free_cb (php_newt_cb **cb_ptr)
+{
+	php_newt_cb *cb = *cb_ptr;
+	if(cb) {
+		if(cb->key) efree (cb->key);
+		if(cb->func_name) efree (cb->func_name);
+		zval_ptr_dtor (&cb->callback);
+		zval_ptr_dtor (&cb->data);
+		efree (cb);
+	}
 }
 /* }}} */
 
-/* {{{ get_resource_by_data
+/* {{{ php_newt_fetch_resource (zval *rsrc, void *data, int le_type)
  */
-static int get_resource_by_data (zval * rsrc, void * data, int le_type)
+int php_newt_fetch_resource (zval *rsrc, void *data, int le_type)
 {
 	zend_rsrc_list_entry *le;
 	char *key = NULL;
@@ -242,233 +276,54 @@
 }
 /* }}} */
 
-/* {{{ newt_comp_callback_wrapper
- */
-static void newt_comp_callback_wrapper (newtComponent component, newt_data_st *cb)
-{
-	zval *z_func_name;
-	zval *args[2];
-	zval retval;
-	php_unserialize_data_t var_hash;
-	const char *p;
-	char *func_name_str = NULL;
-
-	TSRMLS_FETCH();
-
-	if (!cb) {
-		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Null data has been passed to the newt \
                callback wrapper");
-		return;
-	}
-
-	/* First argument is component resource */
-	MAKE_STD_ZVAL (args[0]);
-	if (get_resource_by_data (args[0], component, le_newt_comp) == FAILURE) {
-		zval_dtor (args[0]);
-		FREE_ZVAL (args[0]);
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find component in the \
                global list of resources");
-		return;
-	}
-
-	PHP_VAR_UNSERIALIZE_INIT (var_hash);
-
-	/* Extract function name */
-	p = cb->func_name;
-	MAKE_STD_ZVAL (z_func_name);
-	php_var_unserialize(&z_func_name, &p, p + strlen(p), &var_hash TSRMLS_CC);
-
-	/* Second argument is mixed data */
-	p = cb->data;
-	MAKE_STD_ZVAL (args[1]);
-	php_var_unserialize(&args[1], &p, p + strlen(p), &var_hash TSRMLS_CC);
-
-	PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
-
-	if (!zend_is_callable (z_func_name, 0, &func_name_str)
-			|| call_user_function(EG(function_table), NULL, z_func_name, &retval, 2, args \
                TSRMLS_CC) == FAILURE ) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call user function: \
                %s(component, data)", func_name_str);
-	} else {
-		zval_dtor(&retval);
-	}
-	if (func_name_str) efree (func_name_str);
-	zval_dtor (z_func_name);
-	FREE_ZVAL (z_func_name);
-	zval_dtor (args[0]);
-	FREE_ZVAL (args[0]);
-	zval_dtor (args[1]);
-	FREE_ZVAL (args[1]);
-}
-/* }}} */
-
-/* {{{
- * proto newt_entry_filter_callback_wrapper (newtComponent entry, void * data, int \
                ch, int cursor)
- */
-static int newt_entry_filter_callback_wrapper (newtComponent entry, newt_data_st * \
                cb, int ch, int cursor)
-{
-	zval *z_func_name;
-	zval *args[4];
-	zval retval;
-	php_unserialize_data_t var_hash;
-	const char *p;
-	char *func_name_str = NULL;
-
-	TSRMLS_FETCH();
-
-	if (!cb) {
-		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Null data has been passed to the newt \
                callback wrapper");
-		return;
-	}
-
-	/* First argument is component resource */
-	MAKE_STD_ZVAL (args[0]);
-	if (get_resource_by_data (args[0], entry, le_newt_comp) == FAILURE) {
-		zval_dtor (args[0]);
-		FREE_ZVAL (args[0]);
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find component in the \
                global list of resources");
-		return ch;
-	}
-
-	PHP_VAR_UNSERIALIZE_INIT (var_hash);
-
-	/* Extract function name */
-	p = cb->func_name;
-	MAKE_STD_ZVAL (z_func_name);
-	php_var_unserialize(&z_func_name, &p, p + strlen(p), &var_hash TSRMLS_CC);
-
-	/* Second argument is mixed data */
-	p = cb->data;
-	MAKE_STD_ZVAL (args[1]);
-	php_var_unserialize(&args[1], &p, p + strlen(p), &var_hash TSRMLS_CC);
-
-	PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
-
-	/* Third parameter is single character */
-	MAKE_STD_ZVAL (args[2]);
-	ZVAL_STRING (args[2], (char *)&ch, 1);
-
-	/* Fourth parameter is integer  */
-	MAKE_STD_ZVAL (args[3]);
-	ZVAL_LONG (args[3], cursor);
-
-	if (!zend_is_callable(z_func_name, 0, &func_name_str)
-	  || call_user_function(EG(function_table), NULL, z_func_name, &retval, 4, args \
                TSRMLS_CC) == FAILURE ) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, 
-				"Unable to call user function: %s(component, data, ch, cursor)", func_name_str);
-	} else {
-		if (Z_TYPE (retval) == IS_STRING) {
-			ch = *Z_STRVAL (retval);
-		} else if (Z_TYPE (retval) == IS_LONG) {
-			ch = Z_LVAL (retval);
-		}
-		zval_dtor (&retval);
-	}
-	if (func_name_str) efree (func_name_str);
-	zval_dtor (z_func_name); FREE_ZVAL (z_func_name);
-	zval_dtor (args[0]); FREE_ZVAL (args[0]);
-	zval_dtor (args[1]); FREE_ZVAL (args[1]);
-	zval_dtor (args[2]); FREE_ZVAL (args[2]);
-	zval_dtor (args[3]); FREE_ZVAL (args[3]);
-
-	return ch;
-}
-/* }}} */
-
-/* {{{
- * proto newt_suspend_callback_wrapper (void * data)
- */
-static void newt_suspend_callback_wrapper (newt_data_st * cb)
-{
-	zval *z_func_name;
-	zval *args[1];
-	zval retval;
-	php_unserialize_data_t var_hash;
-	const char *p;
-	
-	TSRMLS_FETCH();
-
-	if (!cb) {
-		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Null data has been passed to the newt \
                callback wrapper");
-		return;
-	}
-
-	PHP_VAR_UNSERIALIZE_INIT (var_hash);
-
-	/* Extract function name */
-	p = cb->func_name;
-	MAKE_STD_ZVAL (z_func_name);
-	php_var_unserialize(&z_func_name, &p, p + strlen(p), &var_hash TSRMLS_CC);
-
-	/* First argument is mixed data */
-	p = cb->data;
-	MAKE_STD_ZVAL (args[0]);
-	php_var_unserialize(&args[0], &p, p + strlen(p), &var_hash TSRMLS_CC);
-
-	PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
-
-	if (call_user_function(EG(function_table), NULL, z_func_name, &retval, 1, args \
                TSRMLS_CC) == SUCCESS ) {
-		zval_dtor(&retval);
-	} else {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call user function: \
                %s(data)", cb->func_name);
-	}
-	zval_dtor (z_func_name); FREE_ZVAL (z_func_name);
-	zval_dtor (args[0]); FREE_ZVAL (args[0]);
-}
-/* }}} */
-
-/* {{{
- * proto newt_help_callback_wrapper (newtComponent form, char *help)
- */
-static void newt_help_callback_wrapper (newtComponent form, char *help)
-{
-	zval *args[2];
-	zval retval;
-	char *func_name_str = NULL;
-
-	TSRMLS_FETCH ();
-
-	/* First argument is component resource */
-	MAKE_STD_ZVAL (args[0]);
-	if (get_resource_by_data (args[0], form, le_newt_comp) == FAILURE) {
-		zval_dtor (args[0]);
-		FREE_ZVAL (args[0]);
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find component in the \
                global list of resources");
-		return;
-	}
-
-	/* Second argument is string */
-	MAKE_STD_ZVAL (args[1]);
-	ZVAL_STRING (args[1], help, 1);
-
-	if (!zend_is_callable(NEWT_G(z_newt_help_callback), 0, &func_name_str)
-			|| call_user_function(EG(function_table), NULL, NEWT_G(z_newt_help_callback), \
                &retval, 2, args TSRMLS_CC) == FAILURE ) {
-	  php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call user function: \
                %s(form, help)", func_name_str);
-	} else {
-	  zval_dtor(&retval);
-	}
-	
-	if (func_name_str) efree (func_name_str);
-
-	zval_dtor (args[0]); FREE_ZVAL (args[0]);
-	zval_dtor (args[1]); FREE_ZVAL (args[1]);
-}
-/* }}} */
-
-/* {{{
- * proto newt_call_php_function
- */
-static void newt_call_php_function (INTERNAL_FUNCTION_PARAMETERS, char *func_name, \
                zval **ret_val, int argc, zval ***args)
-{
-	zval *z_func_name;
-
-	MAKE_STD_ZVAL(z_func_name);
-	ZVAL_STRING(z_func_name, func_name, 1);
-
-	if (call_user_function_ex(EG(function_table), NULL, z_func_name, ret_val, argc, \
                args, 0, NULL TSRMLS_CC) == FAILURE) {
-		php_error_docref(NULL TSRMLS_CC, E_ERROR, "An error was occurred while calling to \
                function '%s'", func_name);
-		return;
-	}
-	zval_dtor(z_func_name); FREE_ZVAL (z_func_name);
-}
-/* }}} */
+#define PHP_NEWT_STORE_DATA(z_data, key) \
+	do { \
+		if (!key) { \
+			key = emalloc (PHP_NEWT_RK_SIZE+1); \
+			snprintf (key, PHP_NEWT_RK_SIZE, "%x", zend_hash_num_elements(&NEWT_G(data))); \
+		} \
+		zend_hash_update (&NEWT_G(data), key, strlen(key)+1, (void *)&z_data, sizeof(zval \
*), NULL); \ +	} while (0)
+
+#define PHP_NEWT_FETCH_DATA(key, z_data) \
+	do { \
+		zval **z_data##z_data = NULL; \
+		zend_hash_find (&NEWT_G(data), key, strlen(key)+1, (void **)&z_data##z_data); \
+		z_data = *z_data##z_data; \
+	} while (0)
+
+#define PHP_NEWT_FETCH_KEY(z_data, key) \
+	do { \
+		zval *z_data##z_data = NULL, z_data##res; \
+		key = NULL; \
+		zend_hash_internal_pointer_reset (&NEWT_G(data)); \
+		while (zend_hash_get_current_data (&NEWT_G(data), (void **)&z_data##z_data) == \
SUCCESS) { \ +			ulong z_data##id; \
+			uint z_data##key_len; \
+			is_identical_function (&z_data##res, z_data##z_data, z_data); \
+			if(zval_is_true (&z_data##res)) { \
+				zend_hash_get_current_key_ex(&NEWT_G(data), &key, &z_data##key_len, &z_data##id, \
0, NULL); \ +				break; \
+			} \
+			zend_hash_move_forward(&NEWT_G(data)); \
+		} \
+	} while (0) 
+
+#define PHP_NEWT_STORE_CALLBACK(cb) \
+	do { \
+		if (!cb->key) { \
+		  cb->key = emalloc (PHP_NEWT_RK_SIZE+1); \
+		  snprintf (cb->key, PHP_NEWT_RK_SIZE, "%x", cb); \
+		} \
+		zend_hash_update(&NEWT_G(callbacks), cb->key, strlen(cb->key)+1, (void *)&cb, \
sizeof(php_newt_cb *), NULL); \ +	} while (0)
+
+#define PHP_NEWT_FETCH_CALLBACK(key, cb) \
+	do { \
+		php_newt_cb **cb##cb = NULL; \
+		zend_hash_find (&NEWT_G(callbacks), (char *)key, strlen(key)+1, (void **)&cb##cb); \
\ +		cb = *cb##cb; \
+	} while (0)
 
 /* {{{ PHP_MINIT_FUNCTION
  */
@@ -477,7 +332,7 @@
 	le_newt_comp = zend_register_list_destructors_ex(NULL, NULL, le_newt_comp_name, \
module_number);  le_newt_grid = zend_register_list_destructors_ex(NULL, NULL, \
le_newt_grid_name, module_number);  
-	ZEND_INIT_MODULE_GLOBALS (newt, php_newt_init_globals, NULL);
+	ZEND_INIT_MODULE_GLOBALS (newt, php_newt_init_globals, php_newt_destroy_globals);
 
 	/* Colorsets */
 	REGISTER_NEWT_CONSTANT(NEWT_COLORSET_ROOT);
@@ -610,13 +465,9 @@
  */
 PHP_MSHUTDOWN_FUNCTION(newt)
 {
-	if (NEWT_G(z_newt_help_callback)) {
-		zval_ptr_dtor (&NEWT_G(z_newt_help_callback));
-		NEWT_G(z_newt_help_callback) = NULL;
-	}
-	if (NEWT_G(newt_has_inited)) {
-		newtFinished();
-	}
+//#ifndef ZTS
+//	php_newt_destroy_globals (&newt_globals TSRMLS_CC);
+//#endif
 
 	return SUCCESS;
 }
@@ -632,6 +483,153 @@
 }
 /* }}} */
 
+/* {{{ newt_comp_callback_wrapper
+ */
+static void newt_comp_callback_wrapper (newtComponent component, void *cb_key)
+{
+	zval *args[2];
+	zval retval;
+	php_newt_cb *cb = NULL;
+
+	TSRMLS_FETCH();
+
+	PHP_NEWT_FETCH_CALLBACK (cb_key, cb);
+
+	/* First argument is component resource */
+	MAKE_STD_ZVAL (args[0]);
+	php_newt_fetch_resource (args[0], component, le_newt_comp);
+
+	if (call_user_function(EG(function_table), NULL, cb->callback, &retval, 2, args \
TSRMLS_CC) == SUCCESS) { +		zval_dtor(&retval);
+	} else {
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call user function: \
%s(component, data)", cb->func_name); +	}
+	zval_ptr_dtor (&args[0]);
+	zval_ptr_dtor (&args[1]);
+}
+/* }}} */
+
+/* {{{
+ * proto newt_entry_filter_callback_wrapper (newtComponent entry, void *data, int \
ch, int cursor) + */
+static int newt_entry_filter_callback_wrapper (newtComponent entry, void *cb_key, \
int ch, int cursor) +{
+	zval *args[4];
+	zval retval;
+	php_newt_cb *cb = NULL;
+	
+	TSRMLS_FETCH();
+
+	PHP_NEWT_FETCH_CALLBACK (cb_key, cb);
+
+	/* First argument is component resource */
+	MAKE_STD_ZVAL (args[0]);
+	php_newt_fetch_resource (args[0], entry, le_newt_comp);
+
+	/* Second argument is mixed data */
+	args[1] = cb->data;
+
+	/* Third parameter is single character */
+	MAKE_STD_ZVAL (args[2]);
+	ZVAL_STRING (args[2], (char *)&ch, 1);
+
+	/* Fourth parameter is integer  */
+	MAKE_STD_ZVAL (args[3]);
+	ZVAL_LONG (args[3], cursor);
+
+	if (call_user_function(EG(function_table), NULL, cb->callback, &retval, 4, args \
TSRMLS_CC) == FAILURE ) { +		php_error_docref(NULL TSRMLS_CC, E_WARNING, 
+				"Unable to call user function: %s(component, data, ch, cursor)", cb->func_name);
+	} else {
+		if (Z_TYPE (retval) == IS_STRING) {
+			ch = *Z_STRVAL (retval);
+		} else if (Z_TYPE (retval) == IS_LONG) {
+			ch = Z_LVAL (retval);
+		}
+		zval_dtor (&retval);
+	}
+	zval_ptr_dtor (&args[0]);
+	zval_ptr_dtor (&args[2]);
+	zval_ptr_dtor (&args[3]);
+
+	return ch;
+}
+/* }}} */
+
+/* {{{
+ * proto newt_suspend_callback_wrapper (void *data)
+ */
+static void newt_suspend_callback_wrapper (void *cb_key)
+{
+	zval *args[1];
+	zval retval;
+	php_newt_cb *cb = NULL;
+	
+	TSRMLS_FETCH();
+
+	PHP_NEWT_FETCH_CALLBACK (cb_key, cb);
+
+	/* First argument is mixed data */
+	args[0] = cb->data;
+
+	if (call_user_function(EG(function_table), NULL, cb->callback, &retval, 1, args \
TSRMLS_CC) == SUCCESS) { +		zval_dtor(&retval);
+	} else {
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call user function: \
%s(data)", cb->func_name); +	}
+}
+/* }}} */
+
+/* {{{
+ * proto newt_help_callback_wrapper (newtComponent form, char *help)
+ */
+static void newt_help_callback_wrapper (newtComponent form, char *help)
+{
+	zval *args[2];
+	zval retval;
+	php_newt_cb *cb = NULL;
+	
+	TSRMLS_FETCH();
+
+	PHP_NEWT_FETCH_CALLBACK (NEWT_G(php_newt_help_cb_key), cb);
+
+	/* First argument is component resource */
+	MAKE_STD_ZVAL (args[0]);
+	php_newt_fetch_resource (args[0], form, le_newt_comp);
+
+	/* Second argument is string */
+	MAKE_STD_ZVAL (args[1]);
+	ZVAL_STRING (args[1], help, 1);
+
+	if (call_user_function(EG(function_table), NULL, cb->callback, &retval, 2, args \
TSRMLS_CC) == SUCCESS) { +	  php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to \
call user function: %s(form, help)", cb->func_name); +	} else {
+	  zval_dtor(&retval);
+	}
+	
+	zval_ptr_dtor (&args[0]);
+	zval_ptr_dtor (&args[1]);
+}
+/* }}} */
+
+/* {{{
+ * proto newt_call_php_function
+ */
+static void newt_call_php_function (INTERNAL_FUNCTION_PARAMETERS, char *func_name, \
zval **ret_val, int argc, zval ***args) +{
+	zval *z_func_name;
+
+	MAKE_STD_ZVAL(z_func_name);
+	ZVAL_STRING(z_func_name, func_name, 1);
+
+	if (call_user_function_ex(EG(function_table), NULL, z_func_name, ret_val, argc, \
args, 0, NULL TSRMLS_CC) == FAILURE) { +		php_error_docref(NULL TSRMLS_CC, E_ERROR, \
"An error was occurred while calling to function '%s'", func_name); +		return;
+	}
+	zval_ptr_dtor(&z_func_name);
+}
+/* }}} */
+
 /* {{{
  * proto newt_init()
  */
@@ -725,7 +723,7 @@
 	int top;
    	int width;
    	int height;
-	char * title = NULL;
+	char *title = NULL;
 	int title_len;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "llll|s", &left, &top, \
&width, &height, &title, &title_len) == FAILURE) { @@ -743,7 +741,7 @@
 {
    	int width;
    	int height;
-	char * title = NULL;
+	char *title = NULL;
 	int title_len;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "ll|s", &width, &height, \
&title, &title_len) == FAILURE) { @@ -796,41 +794,38 @@
  */
 PHP_FUNCTION(newt_set_suspend_callback)
 {
-	zval *z_func_name, *z_data;
-	newt_data_st * cb;
-	php_serialize_data_t var_hash;
-	smart_str data_buf = {0}, func_buf = {0};
-	char *func_name_str = NULL;
+	zval *z_callback, *z_data;
+	php_newt_cb *cb = NULL;
 
-	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz", &z_func_name, &z_data) \
== FAILURE) { +	cb = emalloc(sizeof(php_newt_cb));
+	memset (cb, 0, sizeof(php_newt_cb));
+	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz", &z_callback, &z_data) \
== FAILURE) { +		efree (cb);
 		return;
 	}
 
-	if (Z_TYPE_P(z_func_name) != IS_STRING && Z_TYPE_P(z_func_name) != IS_ARRAY) {
-		SEPARATE_ZVAL (&z_func_name);
-		convert_to_string_ex (&z_func_name);
+	if (Z_TYPE_P(z_callback) != IS_STRING && Z_TYPE_P(z_callback) != IS_ARRAY) {
+		SEPARATE_ZVAL (&z_callback);
+		convert_to_string_ex (&z_callback);
 	}
 
-	/* Fill callback struct */
-	cb = emalloc (sizeof(newt_data_st));
-	memset (cb, 0, sizeof(newt_data_st));
-
-	if (!zend_is_callable(z_func_name, 0, &func_name_str)) {
+	if (!zend_is_callable(z_callback, 0, &cb->func_name)) {
+		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument is expected to be a \
valid callback", cb->func_name); +		efree (cb->func_name);
 		efree (cb);
-		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument is expected to be a \
                valid callback", func_name_str);
-		efree (func_name_str);
 		return;
 	}
-	if(func_name_str) efree (func_name_str);
 
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&data_buf, &z_data, &var_hash TSRMLS_CC);
-	cb->data = (char *) estrdup (data_buf.c);
-	php_var_serialize(&func_buf, &z_func_name, &var_hash TSRMLS_CC);
-	cb->func_name = (char *) estrdup (func_buf.c);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	MAKE_STD_ZVAL(cb->callback);
+	*cb->callback = *z_callback;
+	zval_copy_ctor(cb->callback);
+
+	MAKE_STD_ZVAL(cb->data);
+	*cb->data = *z_data;
+	zval_copy_ctor(cb->data);
 
-	newtSetSuspendCallback ((newtSuspendCallback) newt_suspend_callback_wrapper, cb);
+	PHP_NEWT_STORE_CALLBACK (cb);
+	newtSetSuspendCallback ((newtSuspendCallback) newt_suspend_callback_wrapper, \
cb->key);  }
 /* }}} */
 
@@ -839,35 +834,34 @@
  */
 PHP_FUNCTION(newt_set_help_callback)
 {
-	zval *z_func_name;
-	char *func_name_str = NULL;
+	zval *z_callback;
+	php_newt_cb *cb = NULL;
 
-	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_func_name) == \
FAILURE) { +	cb = emalloc(sizeof(php_newt_cb));
+	memset (cb, 0, sizeof(php_newt_cb));
+	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_callback) == FAILURE) \
{  return;
 	}
 
-	if (Z_TYPE_P(z_func_name) != IS_STRING && Z_TYPE_P(z_func_name) != IS_ARRAY) {
-		SEPARATE_ZVAL (&z_func_name);
-		convert_to_string_ex (&z_func_name);
+	if (Z_TYPE_P(z_callback) != IS_STRING && Z_TYPE_P(z_callback) != IS_ARRAY) {
+		SEPARATE_ZVAL (&z_callback);
+		convert_to_string_ex (&z_callback);
 	}
 
-	if (!zend_is_callable(z_func_name, 0, &func_name_str)) {
-		php_error_docref(NULL TSRMLS_CC, E_ERROR, "First argument is expected to be a \
valid callback", func_name_str); +	if (!zend_is_callable(z_callback, 0, \
&cb->func_name)) { +		php_error_docref(NULL TSRMLS_CC, E_ERROR, "First argument is \
expected to be a valid callback", cb->func_name); +		efree (cb->func_name);
+		efree (cb);
 		return;
 	}
 
-	if(func_name_str) efree(func_name_str);
+	MAKE_STD_ZVAL(cb->callback);
+	*cb->callback = *z_callback;
+	zval_copy_ctor(cb->callback);
 
+	cb->key = NEWT_G(php_newt_help_cb_key);
+	PHP_NEWT_STORE_CALLBACK (cb);
 	newtSetHelpCallback ((newtCallback) newt_help_callback_wrapper);
-
-	if(NEWT_G(z_newt_help_callback)) {
-		zval_dtor(NEWT_G(z_newt_help_callback));
-	} else {
-		MAKE_STD_ZVAL (NEWT_G(z_newt_help_callback));
-	}
-	*NEWT_G(z_newt_help_callback) = *z_func_name;
-	zval_copy_ctor (NEWT_G(z_newt_help_callback));
-	zval_add_ref (&NEWT_G(z_newt_help_callback));
 }
 /* }}} */
 
@@ -886,7 +880,7 @@
  */
 PHP_FUNCTION(newt_push_help_line)
 {
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &text, &text_len) == \
FAILURE) { @@ -924,7 +918,7 @@
 {
    	int left;
    	int top;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 	
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "lls", &left, &top, &text, \
&text_len) == FAILURE) { @@ -971,7 +965,7 @@
 {
    	int left;
    	int top;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 	newtComponent button;
 	
@@ -992,7 +986,7 @@
 {
    	int left;
    	int top;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 	newtComponent button;
 	
@@ -1013,11 +1007,11 @@
 {
 	int left;
 	int top;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
-	char * def_val = NULL;
+	char *def_val = NULL;
 	int def_val_len = 0;
-	char * seq = NULL;
+	char *seq = NULL;
 	int seq_len;
 	newtComponent checkbox;
 
@@ -1043,7 +1037,7 @@
  */
 PHP_FUNCTION(newt_checkbox_get_value)
 {
-	zval * z_checkbox;
+	zval *z_checkbox;
 	newtComponent checkbox;
 	char ret_value[2];
 
@@ -1064,9 +1058,9 @@
  */
 PHP_FUNCTION(newt_checkbox_set_value)
 {
-	zval * z_checkbox;
+	zval *z_checkbox;
 	newtComponent checkbox;
-	char * value = NULL;
+	char *value = NULL;
 	int value_len;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zs", &z_checkbox, &value, \
&value_len) == FAILURE) { @@ -1088,7 +1082,7 @@
  */
 PHP_FUNCTION(newt_checkbox_set_flags)
 {
-	zval * z_checkbox;
+	zval *z_checkbox;
 	newtComponent checkbox;
 	int flags;
 	int sense;
@@ -1109,10 +1103,10 @@
 {
 	int left;
 	int top;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 	int is_default;
-	zval * z_prev_button = NULL;
+	zval *z_prev_button = NULL;
 	newtComponent prev_button = NULL;
 	newtComponent radiobutton;
 
@@ -1137,7 +1131,7 @@
  */
 PHP_FUNCTION(newt_radio_get_current)
 {
-	zval * z_set_member;
+	zval *z_set_member;
 	newtComponent set_member;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_set_member) == \
FAILURE) { @@ -1145,7 +1139,7 @@
 	}
 
 	ZEND_FETCH_RESOURCE(set_member, newtComponent, &z_set_member, -1, \
                le_newt_comp_name, le_newt_comp);
-	get_resource_by_data (return_value, newtRadioGetCurrent(set_member), le_newt_comp);
+	php_newt_fetch_resource (return_value, newtRadioGetCurrent(set_member), \
le_newt_comp);  }
 /* }}} */
 
@@ -1157,15 +1151,14 @@
 {
    	int left;
    	int top;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 	int is_default;
-	zval * z_prev_item;
+	zval *z_prev_item;
 	newtComponent item, prev_item;
-	zval * z_data;
+	zval *z_data;
 	int flags = 0;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	char *key = NULL;
 	
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "llsbzz|l", &left, &top, \
&text, &text_len,   &is_default, &z_prev_item, &z_data, &flags) == FAILURE) {
@@ -1174,11 +1167,9 @@
 
 	ZEND_FETCH_RESOURCE(prev_item, newtComponent, &z_prev_item, -1, le_newt_comp_name, \
le_newt_comp);  
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_data, key);
 
-	item = newtListitem (left, top, text, is_default, prev_item, buf.c, flags);
+	item = newtListitem (left, top, text, is_default, prev_item, key, flags);
 	newtComponentAddCallback (item, NULL, NULL);
 
 	ZEND_REGISTER_RESOURCE (return_value, item, le_newt_comp);
@@ -1192,9 +1183,9 @@
  */
 PHP_FUNCTION(newt_listitem_set)
 {
-	zval * z_item;
+	zval *z_item;
 	newtComponent item;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zs", &z_item, &text, \
&text_len) == FAILURE) { @@ -1213,10 +1204,9 @@
  */
 PHP_FUNCTION(newt_listitem_get_data)
 {
-	zval * z_item;
+	zval *z_item;
 	newtComponent item;
-	php_unserialize_data_t var_hash;
-	const char *data;
+	char *data = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_item) == FAILURE) {
 		return;
@@ -1225,11 +1215,8 @@
 	ZEND_FETCH_RESOURCE(item, newtComponent, &z_item, -1, le_newt_comp_name, \
le_newt_comp);  
 	data = newtListitemGetData (item);
-
 	if (data) {
-		PHP_VAR_UNSERIALIZE_INIT (var_hash);
-		php_var_unserialize(&return_value, &data, data + strlen(data), &var_hash \
                TSRMLS_CC);
-		PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
+		PHP_NEWT_FETCH_DATA (data, return_value);
 	}
 }
 /* }}} */
@@ -1267,7 +1254,7 @@
 {
    	int left;
    	int top;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 	newtComponent label;
 	
@@ -1286,9 +1273,9 @@
  */
 PHP_FUNCTION(newt_label_set_text)
 {
-	zval * z_label;
+	zval *z_label;
 	newtComponent label;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zs", &z_label, &text, \
&text_len) == FAILURE) { @@ -1327,7 +1314,7 @@
  */
 PHP_FUNCTION(newt_scrollbar_set)
 {
-	zval * z_scrollbar;
+	zval *z_scrollbar;
 	int where, total;
 	newtComponent scrollbar;
 
@@ -1364,7 +1351,7 @@
  */
 PHP_FUNCTION(newt_listbox_get_current)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_listbox) == FAILURE) \
{ @@ -1382,7 +1369,7 @@
  */
 PHP_FUNCTION(newt_listbox_set_current)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 	int num;
 
@@ -1400,22 +1387,19 @@
  */
 PHP_FUNCTION(newt_listbox_set_current_by_key)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
-	zval * z_key;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	zval *z_key;
+	char *key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz!", &z_listbox, &z_key) == \
FAILURE) {  return;
 	}
 
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_key, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_FETCH_KEY (z_key, key);
 
 	ZEND_FETCH_RESOURCE(listbox, newtComponent, &z_listbox, -1, le_newt_comp_name, \
                le_newt_comp);
-	newtListboxSetCurrentByKey (listbox, buf.c);
+	newtListboxSetCurrentByKey (listbox, key);
 }
 /* }}} */
 
@@ -1424,7 +1408,7 @@
  */
 PHP_FUNCTION(newt_listbox_set_entry)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 	int num;
 	char *text = NULL;
@@ -1444,7 +1428,7 @@
  */
 PHP_FUNCTION(newt_listbox_set_width)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 	int width;
 
@@ -1463,23 +1447,20 @@
  */
 PHP_FUNCTION(newt_listbox_set_data)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 	int num;
-	zval * z_data;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	zval *z_data;
+	char *key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zlz!", &z_listbox, &num, \
&z_data) == FAILURE) {  return;
 	}
 	
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_data, key);
 
 	ZEND_FETCH_RESOURCE(listbox, newtComponent, &z_listbox, -1, le_newt_comp_name, \
                le_newt_comp);
-	newtListboxSetData (listbox, num, buf.c);
+	newtListboxSetData (listbox, num, key);
 }
 /* }}} */
 
@@ -1488,24 +1469,21 @@
  */
 PHP_FUNCTION(newt_listbox_append_entry)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 	char *text = NULL;
 	int text_len;
-	zval * z_data;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	zval *z_data;
+	char *key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zsz!", &z_listbox, &text, \
&text_len, &z_data) == FAILURE) {  return;
 	}
 	
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_data, key);
 
 	ZEND_FETCH_RESOURCE(listbox, newtComponent, &z_listbox, -1, le_newt_comp_name, \
                le_newt_comp);
-	newtListboxAppendEntry (listbox, text, buf.c);
+	newtListboxAppendEntry (listbox, text, key);
 }
 /* }}} */
 
@@ -1514,25 +1492,22 @@
  */
 PHP_FUNCTION(newt_listbox_insert_entry)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 	char *text = NULL;
 	int text_len;
-	zval * z_data, * z_key;
-	php_serialize_data_t var_hash;
-	smart_str data_buf = {0}, key_buf = {0};
+	zval *z_data, *z_key;
+	char *data_key = NULL, *key_key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zsz!z!", &z_listbox, &text, \
&text_len, &z_data, &z_key) == FAILURE) {  return;
 	}
 	
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&data_buf, &z_data, &var_hash TSRMLS_CC);
-	php_var_serialize(&key_buf, &z_key, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_data, data_key);
+	PHP_NEWT_STORE_DATA (z_key, key_key);
 
 	ZEND_FETCH_RESOURCE(listbox, newtComponent, &z_listbox, -1, le_newt_comp_name, \
                le_newt_comp);
-	newtListboxInsertEntry (listbox, text, data_buf.c, key_buf.c);
+	newtListboxInsertEntry (listbox, text, data_key, key_key);
 }
 /* }}} */
 
@@ -1541,22 +1516,19 @@
  */
 PHP_FUNCTION(newt_listbox_delete_entry)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
-	zval * z_key;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	zval *z_key;
+	char *key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz!", &z_listbox, &z_key) == \
FAILURE) {  return;
 	}
 	
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_key, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_key, key);
 
 	ZEND_FETCH_RESOURCE(listbox, newtComponent, &z_listbox, -1, le_newt_comp_name, \
                le_newt_comp);
-	newtListboxDeleteEntry (listbox, buf.c);
+	newtListboxDeleteEntry (listbox, key);
 }
 /* }}} */
 
@@ -1565,7 +1537,7 @@
  */
 PHP_FUNCTION(newt_listbox_clear)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_listbox) == FAILURE) \
{ @@ -1582,21 +1554,20 @@
  */
 PHP_FUNCTION(newt_listbox_get_entry)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 	int num;
-	zval * z_text = NULL, * z_data = NULL;
-	char * text = NULL, * data = NULL;
-	const char *p;
-	php_unserialize_data_t var_hash;
+	zval *z_text = NULL, *z_data = NULL;
+	char *text = NULL, *key = NULL;
 
-	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zl|z/!z/!", &z_listbox, \
&num, &z_text, &z_data) == FAILURE) { +	if (zend_parse_parameters
+			(ZEND_NUM_ARGS() TSRMLS_CC, "zl|z/!z/!", &z_listbox, &num, &z_text, &z_data) == \
FAILURE) {  return;
 	}
 	
 	ZEND_FETCH_RESOURCE(listbox, newtComponent, &z_listbox, -1, le_newt_comp_name, \
le_newt_comp);  
-	newtListboxGetEntry (listbox, num, &text, (void *)&data);
+	newtListboxGetEntry (listbox, num, &text, (void **)&key);
 	if (z_text) {
 		zval_dtor (z_text);
 		if (text) {
@@ -1605,11 +1576,8 @@
 	}
 	if (z_data) {
 		zval_dtor (z_data);
-		if (data) {
-			PHP_VAR_UNSERIALIZE_INIT (var_hash);
-			p = data;
-			php_var_unserialize(&z_data, &p, p + strlen(p), &var_hash TSRMLS_CC);
-			PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
+		if (key) {
+			PHP_NEWT_FETCH_DATA (key, z_data);
 		}
 	}
 }
@@ -1620,14 +1588,12 @@
  */
 PHP_FUNCTION(newt_listbox_get_selection)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 	char **retval;
-	zval * z_val;
+	zval *z_val;
 	int num_items;
-	php_unserialize_data_t var_hash;
 	int i;
-	const char *p;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_listbox) == FAILURE) \
{  return;
@@ -1640,15 +1606,12 @@
 	MAKE_STD_ZVAL (z_val);
 
 	if (retval) {
-		PHP_VAR_UNSERIALIZE_INIT (var_hash);
 		for (i=0; i < num_items; i++ ) {
-			p = retval[i];
-			php_var_unserialize(&z_val, &p, p + strlen(p), &var_hash TSRMLS_CC);
+			PHP_NEWT_FETCH_DATA (retval[i], z_val);
 			zval_add_ref (&z_val);
 			zend_hash_next_index_insert (Z_ARRVAL_P(return_value), &z_val, sizeof(zval *), \
NULL);  SEPARATE_ZVAL (&z_val);
 		}
-		PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
 		free (retval);
 	}
 }
@@ -1659,7 +1622,7 @@
  */
 PHP_FUNCTION(newt_listbox_clear_selection)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_listbox) == FAILURE) \
{ @@ -1676,23 +1639,20 @@
  */
 PHP_FUNCTION(newt_listbox_select_item)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
-	zval * z_key;
+	zval *z_key;
 	int sense;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	char *key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz!l", &z_listbox, &z_key, \
&sense) == FAILURE) {  return;
 	}
 	
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_key, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_key, key);
 
 	ZEND_FETCH_RESOURCE(listbox, newtComponent, &z_listbox, -1, le_newt_comp_name, \
                le_newt_comp);
-	newtListboxSelectItem (listbox, buf.c, sense);
+	newtListboxSelectItem (listbox, key, sense);
 }
 /* }}} */
 
@@ -1702,7 +1662,7 @@
  */
 PHP_FUNCTION(newt_listbox_item_count)
 {
-	zval * z_listbox;
+	zval *z_listbox;
 	newtComponent listbox;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_listbox) == FAILURE) \
{ @@ -1746,7 +1706,7 @@
 	int left;
 	int top;
 	int height;
-	char * seq = NULL;
+	char *seq = NULL;
 	int seq_len;
 	int flags = 0;
 
@@ -1766,14 +1726,12 @@
  */
 PHP_FUNCTION(newt_checkbox_tree_get_selection)
 {
-	zval * z_checkboxtree;
+	zval *z_checkboxtree;
 	newtComponent checkboxtree;
 	char **retval;
-	zval * z_val;
+	zval *z_val;
 	int num_items;
-	php_unserialize_data_t var_hash;
 	int i;
-	const char *p;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_checkboxtree) == \
FAILURE) {  return;
@@ -1786,15 +1744,12 @@
 	MAKE_STD_ZVAL (z_val);
 
 	if (retval) {
-		PHP_VAR_UNSERIALIZE_INIT (var_hash);
 		for (i=0; i < num_items; i++ ) {
-			p = retval[i];
-			php_var_unserialize(&z_val, &p, p + strlen(p), &var_hash TSRMLS_CC);
+			PHP_NEWT_FETCH_DATA (retval[i], z_val);
 			zval_add_ref (&z_val);
 			zend_hash_next_index_insert (Z_ARRVAL_P(return_value), &z_val, sizeof(zval *), \
NULL);  SEPARATE_ZVAL (&z_val);
 		}
-		PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
 		free (retval);
 	}
 }
@@ -1805,10 +1760,9 @@
  */
 PHP_FUNCTION(newt_checkbox_tree_get_current)
 {
-	zval * z_checkboxtree;
+	zval *z_checkboxtree;
 	newtComponent checkboxtree;
-	php_unserialize_data_t var_hash;
-	const char *current;
+	char *current;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_checkboxtree) == \
FAILURE) {  return;
@@ -1818,9 +1772,7 @@
 	current = (char *)newtCheckboxTreeGetCurrent (checkboxtree);
 
 	if (current) {
-		PHP_VAR_UNSERIALIZE_INIT (var_hash);
-		php_var_unserialize(&return_value, &current, current + strlen(current), &var_hash \
                TSRMLS_CC);
-		PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
+		PHP_NEWT_FETCH_DATA (current, return_value);
 	}
 }
 /* }}} */
@@ -1830,11 +1782,9 @@
  */
 PHP_FUNCTION(newt_checkbox_tree_set_current)
 {
-	zval * z_checkboxtree, * z_data;
+	zval *z_checkboxtree, *z_data;
 	newtComponent checkboxtree;
-	char * data = NULL;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	char *key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz", &z_checkboxtree, \
&z_data) == FAILURE) {  return;
@@ -1842,11 +1792,8 @@
 	
 	ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, \
le_newt_comp_name, le_newt_comp);  
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
-
-	newtCheckboxTreeSetCurrent (checkboxtree, buf.c);
+	PHP_NEWT_STORE_DATA (z_data, key);
+	newtCheckboxTreeSetCurrent (checkboxtree, key);
 }
 /* }}} */
 
@@ -1855,15 +1802,13 @@
  */
 PHP_FUNCTION(newt_checkbox_tree_get_multi_selection)
 {
-	zval * z_checkboxtree;
+	zval *z_checkboxtree;
 	newtComponent checkboxtree;
 	char **retval;
-	zval * z_val;
+	zval *z_val;
 	int num_items;
-	php_unserialize_data_t var_hash;
 	int i;
-	const char *p;
-	char * seqnum = NULL;
+	char *seqnum = NULL;
 	int seqnum_len;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zs!", &z_checkboxtree, \
&seqnum, &seqnum_len) == FAILURE) { @@ -1882,15 +1827,12 @@
 	MAKE_STD_ZVAL (z_val);
 
 	if (retval) {
-		PHP_VAR_UNSERIALIZE_INIT (var_hash);
 		for (i=0; i < num_items; i++ ) {
-			p = retval[i];
-			php_var_unserialize(&z_val, &p, p + strlen(p), &var_hash TSRMLS_CC);
+			PHP_NEWT_FETCH_DATA (retval[i], z_val);
 			zval_add_ref (&z_val);
 			zend_hash_next_index_insert (Z_ARRVAL_P(return_value), &z_val, sizeof(zval *), \
NULL);  SEPARATE_ZVAL (&z_val);
 		}
-		PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
 		free (retval);
 	}
 }
@@ -1903,11 +1845,10 @@
 {
 	zval *z_checkboxtree, *z_data, ***args;
 	newtComponent checkboxtree;
-	char * text;
+	char *text;
 	int text_len, flags, i;
 	void **newt_args = NULL;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	char *key = NULL;
 
 	int argc = ZEND_NUM_ARGS();
 	if (argc < 5) { WRONG_PARAM_COUNT; }
@@ -1923,14 +1864,12 @@
 
 	ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, \
le_newt_comp_name, le_newt_comp);  
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_data, key);
 
 	newt_args = (void **) emalloc (sizeof(void *) * argc);
 	newt_args[0] = (void *)checkboxtree;
 	newt_args[1] = (void *)text;
-	newt_args[2] = (void *)buf.c;
+	newt_args[2] = (void *)key;
 	newt_args[3] = (void *)flags;
 	
 	for (i=4; i<argc; i++) {
@@ -1957,11 +1896,10 @@
 {
 	zval *z_checkboxtree, *z_data, *z_indexes, *z_index;
 	newtComponent checkboxtree;
-	char * text;
+	char *text;
 	int text_len, flags, *indexes, indexes_num, i;
 	void **newt_args = NULL;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	char *key = NULL;
 
 	if (5 != ZEND_NUM_ARGS()) { WRONG_PARAM_COUNT; }
 	if (zend_parse_parameters (5 TSRMLS_CC, "zszla", &z_checkboxtree, &text, &text_len, \
&z_data, &flags, &z_indexes) == FAILURE) { @@ -1970,9 +1908,7 @@
 	
 	ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, \
le_newt_comp_name, le_newt_comp);  
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_data, key);
 
 	indexes_num = zend_hash_num_elements (Z_ARRVAL_P(z_indexes));
 	indexes = (int *) emalloc (sizeof(int) * (indexes_num+1));
@@ -1995,7 +1931,7 @@
 	newt_args = (void **) emalloc (sizeof(void *) * 5);
 	newt_args[0] = (void *)checkboxtree;
 	newt_args[1] = (void *)text;
-	newt_args[2] = (void *)buf.c;
+	newt_args[2] = (void *)key;
 	newt_args[3] = (void *)flags;
 	newt_args[4] = (void *)indexes;
 	
@@ -2014,8 +1950,7 @@
 	zval *z_checkboxtree, *z_data, *z_val;
 	newtComponent checkboxtree;
 	int *path, i;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	char *key = NULL;
 
 	if (2 != ZEND_NUM_ARGS()) { WRONG_PARAM_COUNT; }
 	if (zend_parse_parameters (2 TSRMLS_CC, "zz", &z_checkboxtree, &z_data) != FAILURE) \
{ @@ -2024,11 +1959,8 @@
 
 	ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, \
le_newt_comp_name, le_newt_comp);  
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
-
-	path = newtCheckboxTreeFindItem (checkboxtree, buf.c);
+	PHP_NEWT_STORE_DATA (z_data, key);
+	path = newtCheckboxTreeFindItem (checkboxtree, key);
 
 	array_init (return_value);
 	if (path) {
@@ -2050,13 +1982,12 @@
  */
 PHP_FUNCTION(newt_checkbox_tree_set_entry)
 {
-	zval * z_checkbox_tree;
+	zval *z_checkbox_tree;
 	newtComponent checkbox_tree;
-	zval * z_data;
-	char * text = NULL;
+	zval *z_data;
+	char *text = NULL;
 	int text_len;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	char *key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zzs", &z_checkbox_tree, \
&z_data, &text, &text_len) == FAILURE) {  return;
@@ -2064,11 +1995,8 @@
 	
 	ZEND_FETCH_RESOURCE(checkbox_tree, newtComponent, &z_checkbox_tree, -1, \
le_newt_comp_name, le_newt_comp);  
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
-
-	newtCheckboxTreeSetEntry (checkbox_tree, buf.c, text);
+	PHP_NEWT_STORE_DATA (z_data, key);
+	newtCheckboxTreeSetEntry (checkbox_tree, key, text);
 }
 /* }}} */
 
@@ -2077,7 +2005,7 @@
  */
 PHP_FUNCTION(newt_checkbox_tree_set_width)
 {
-	zval * z_checkbox_tree;
+	zval *z_checkbox_tree;
 	newtComponent checkbox_tree;
 	int width;
 
@@ -2096,23 +2024,19 @@
  */
 PHP_FUNCTION(newt_checkbox_tree_get_entry_value)
 {
-	zval * z_checkboxtree;
+	zval *z_checkboxtree, *z_data;
 	newtComponent checkboxtree;
-	zval * z_data;
 	char ret_value[2];
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	char *key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz!", &z_checkboxtree, \
&z_data) == FAILURE) {  return;
 	}
 	
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_data, key);
 
 	ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, \
                le_newt_comp_name, le_newt_comp);
-	ret_value[0] = newtCheckboxTreeGetEntryValue (checkboxtree, buf.c);
+	ret_value[0] = newtCheckboxTreeGetEntryValue (checkboxtree, key);
 	ret_value[1] = '\0';
 	
 	RETURN_STRING (ret_value, 1);
@@ -2124,13 +2048,11 @@
  */
 PHP_FUNCTION(newt_checkbox_tree_set_entry_value)
 {
-	zval * z_checkboxtree;
+	zval *z_checkboxtree, *z_data;
 	newtComponent checkboxtree;
-	zval * z_data;
-	char * value;
+	char *value;
 	int value_len;
-	php_serialize_data_t var_hash;
-	smart_str buf = {0};
+	char *key = NULL;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz!s", &z_checkboxtree, \
&z_data, &value, &value_len) == FAILURE) {  return;
@@ -2141,23 +2063,21 @@
 		return;
 	}
 	
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	PHP_NEWT_STORE_DATA (z_data, key);
 
 	ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, \
                le_newt_comp_name, le_newt_comp);
-	newtCheckboxTreeSetEntryValue (checkboxtree, buf.c, *value);
+	newtCheckboxTreeSetEntryValue (checkboxtree, key, *value);
 }
 /* }}} */
 
 /* {{{
- * proto resource newt_textbox_reflowed (int left, int top, char * text, int width, \
int flex_down, int flex_up [, int flags]) + * proto resource newt_textbox_reflowed \
                (int left, int top, char *text, int width, int flex_down, int flex_up \
                [, int flags])
  */
 PHP_FUNCTION(newt_textbox_reflowed)
 {
 	int left;
 	int top;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 	int width;
 	int flex_down;
@@ -2205,9 +2125,9 @@
  */
 PHP_FUNCTION(newt_textbox_set_text)
 {
-	zval * z_textbox;
+	zval *z_textbox;
 	newtComponent textbox;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zs", &z_textbox, &text, \
&text_len) == FAILURE) { @@ -2224,7 +2144,7 @@
  */
 PHP_FUNCTION(newt_textbox_set_height)
 {
-	zval * z_textbox;
+	zval *z_textbox;
 	newtComponent textbox;
 	int height;
 
@@ -2242,7 +2162,7 @@
  */
 PHP_FUNCTION(newt_textbox_get_num_lines)
 {
-	zval * z_textbox;
+	zval *z_textbox;
 	newtComponent textbox;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_textbox) == FAILURE) \
{ @@ -2261,7 +2181,7 @@
 {
 	zval *z_actual_width = NULL, *z_actual_height = NULL;
 	int actual_width, actual_height;
-	char * text = NULL;
+	char *text = NULL;
 	int text_len;
 	int width;
 	int flex_down, flex_up;
@@ -2291,8 +2211,8 @@
  */
 PHP_FUNCTION(newt_form)
 {
-   zval * z_vert_bar = NULL;
-   char * help = NULL;
+   zval *z_vert_bar = NULL;
+   char *help = NULL;
    int help_len;
    int flags = 0;
    newtComponent vert_bar = NULL;
@@ -2317,7 +2237,7 @@
  */
 PHP_FUNCTION(newt_form_set_timer)
 {
-	zval * z_form;
+	zval *z_form;
 	newtComponent form;
 	int milliseconds;
 
@@ -2335,9 +2255,8 @@
  */
 PHP_FUNCTION(newt_form_watch_fd)
 {
-	zval * z_form;
+	zval *z_form, *z_stream;
 	newtComponent form;
-	zval * z_stream;
 	php_stream * stream;
 	int fd;
 	int flags = 0;
@@ -2364,7 +2283,7 @@
  */
 PHP_FUNCTION(newt_form_set_size)
 {
-	zval * z_form;
+	zval *z_form;
 	newtComponent form;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_form) == FAILURE) {
@@ -2381,7 +2300,7 @@
  */
 PHP_FUNCTION(newt_form_get_current)
 {
-	zval * z_form;
+	zval *z_form;
 	newtComponent form;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_form) == FAILURE) {
@@ -2389,7 +2308,7 @@
 	}
 
 	ZEND_FETCH_RESOURCE(form, newtComponent, &z_form, -1, le_newt_comp_name, \
                le_newt_comp);
-	get_resource_by_data (return_value, newtFormGetCurrent(form), le_newt_comp);
+	php_newt_fetch_resource (return_value, newtFormGetCurrent(form), le_newt_comp);
 }
 /* }}} */
 
@@ -2398,7 +2317,7 @@
  */
 PHP_FUNCTION(newt_form_set_background)
 {
-	zval * z_form;
+	zval *z_form;
 	newtComponent form;
 	int background;
 
@@ -2417,9 +2336,8 @@
  */
 PHP_FUNCTION(newt_form_set_current)
 {
-	zval * z_form;
+	zval *z_form, *z_current;
 	newtComponent form;
-	zval * z_current;
 	newtComponent current;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz", &z_form, &z_current) == \
FAILURE) { @@ -2438,8 +2356,7 @@
  */
 PHP_FUNCTION(newt_form_add_component)
 {
-	zval * z_form;
-	zval * z_component;
+	zval *z_form, *z_component;
 	newtComponent form;
 	newtComponent component;
 
@@ -2459,8 +2376,7 @@
  */
 PHP_FUNCTION(newt_form_add_components)
 {
-	zval * z_form;
-	zval * z_components;
+	zval *z_form, *z_components;
 	zval ** z_component;
 	newtComponent form;
 	newtComponent component;
@@ -2486,7 +2402,7 @@
  */
 PHP_FUNCTION(newt_form_set_height)
 {
-	zval * z_form;
+	zval *z_form;
 	newtComponent form;
 	int height;
 
@@ -2504,7 +2420,7 @@
  */
 PHP_FUNCTION(newt_form_set_width)
 {
-	zval * z_form;
+	zval *z_form;
 	newtComponent form;
 	int width;
 
@@ -2522,7 +2438,7 @@
  */
 PHP_FUNCTION(newt_run_form)
 {
-	zval * z_form = NULL;
+	zval *z_form = NULL;
 	newtComponent form;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_form) == FAILURE) {
@@ -2530,7 +2446,7 @@
 	}
 	
 	ZEND_FETCH_RESOURCE(form, newtComponent, &z_form, -1, le_newt_comp_name, \
                le_newt_comp);
-	get_resource_by_data (return_value, newtRunForm(form), le_newt_comp);
+	php_newt_fetch_resource (return_value, newtRunForm(form), le_newt_comp);
 }
 /* }}} */
 
@@ -2539,8 +2455,8 @@
  */
 PHP_FUNCTION(newt_form_run)
 {
-	zval * z_form = NULL;
-	zval * z_es = NULL;
+	zval *z_form = NULL;
+	zval *z_es = NULL;
 	newtComponent form;
 	struct newtExitStruct es;
 	zval *z_reason, *z_watch, *z_key, *z_component;
@@ -2565,7 +2481,7 @@
 	ZVAL_LONG(z_reason, es.reason);
 	ZVAL_LONG(z_watch, es.u.watch);
 	ZVAL_LONG(z_key, es.u.key);
-	get_resource_by_data (z_component, es.u.co, le_newt_comp);
+	php_newt_fetch_resource (z_component, es.u.co, le_newt_comp);
 
 	zend_hash_update (HASH_OF(z_es), "reason", sizeof("reason"), (void *)&z_reason, \
sizeof(zval *), NULL);  zend_hash_update (HASH_OF(z_es), "watch", sizeof("watch"), \
(void *)&z_watch, sizeof(zval *), NULL); @@ -2579,7 +2495,7 @@
  */
 PHP_FUNCTION(newt_draw_form)
 {
-	zval * z_form = NULL;
+	zval *z_form = NULL;
 	newtComponent form;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_form) == FAILURE) {
@@ -2596,7 +2512,7 @@
  */
 PHP_FUNCTION(newt_form_add_hot_key)
 {
-	zval * z_form = NULL;
+	zval *z_form = NULL;
 	newtComponent form;
 	int key;
 
@@ -2639,7 +2555,7 @@
  */
 PHP_FUNCTION(newt_entry_set)
 {
-	zval * z_entry;
+	zval *z_entry;
 	newtComponent entry;
 	char *value = NULL;
 	int value_len;
@@ -2659,43 +2575,41 @@
  */
 PHP_FUNCTION(newt_entry_set_filter)
 {
-	zval *z_entry, *z_func_name, *z_data;
+	zval *z_callback, *z_data, *z_entry;
 	newtComponent entry;
-	newt_data_st * cb;
-	php_serialize_data_t var_hash;
-	smart_str data_buf = {0}, func_buf = {0};
-	char *func_name_str = NULL;
+	php_newt_cb *cb = NULL;
 
-	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &z_entry, \
&z_func_name, &z_data) == FAILURE) { +	cb = emalloc(sizeof(php_newt_cb));
+	memset (cb, 0, sizeof(php_newt_cb));
+	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz/z/", &z_entry, \
&z_callback, &z_data) == FAILURE) { +		efree (cb);
 		return;
 	}
 
-	if (Z_TYPE_P(z_func_name) != IS_STRING && Z_TYPE_P(z_func_name) != IS_ARRAY) {
-		SEPARATE_ZVAL (&z_func_name);
-		convert_to_string_ex (&z_func_name);
+	if (Z_TYPE_P(z_callback) != IS_STRING && Z_TYPE_P(z_callback) != IS_ARRAY) {
+		SEPARATE_ZVAL (&z_callback);
+		convert_to_string_ex (&z_callback);
 	}
 
-	/* Fill callback struct */
-	cb = emalloc (sizeof(newt_data_st));
-	memset (cb, 0, sizeof(newt_data_st));
-
-	if (!zend_is_callable(z_func_name, 0, &func_name_str)) {
+	if (!zend_is_callable(z_callback, 0, &cb->func_name)) {
+		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument is expected to be a \
valid callback", cb->func_name); +		efree (cb->func_name);
 		efree (cb);
-		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument is expected to be a \
                valid callback", func_name_str);
-		efree (func_name_str);
 		return;
 	}
-	if(func_name_str) efree (func_name_str);
 
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&data_buf, &z_data, &var_hash TSRMLS_CC);
-	cb->data = (char *) estrdup (data_buf.c);
-	php_var_serialize(&func_buf, &z_func_name, &var_hash TSRMLS_CC);
-	cb->func_name = (char *) estrdup (func_buf.c);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	MAKE_STD_ZVAL(cb->callback);
+	*cb->callback = *z_callback;
+	zval_copy_ctor(cb->callback);
+
+	MAKE_STD_ZVAL(cb->data);
+	*cb->data = *z_data;
+	zval_copy_ctor(cb->data);
+
+	PHP_NEWT_STORE_CALLBACK (cb);
 
 	ZEND_FETCH_RESOURCE(entry, newtComponent, &z_entry, -1, le_newt_comp_name, \
                le_newt_comp);
-	newtEntrySetFilter (entry, (newtEntryFilter) newt_entry_filter_callback_wrapper, \
cb); +	newtEntrySetFilter (entry, (newtEntryFilter) \
newt_entry_filter_callback_wrapper, cb->key);  }
 /* }}} */
 
@@ -2704,7 +2618,7 @@
  */
 PHP_FUNCTION(newt_entry_get_value)
 {
-	zval * z_entry;
+	zval *z_entry;
 	newtComponent entry;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_entry) == FAILURE) {
@@ -2722,7 +2636,7 @@
  */
 PHP_FUNCTION(newt_entry_set_flags)
 {
-	zval * z_entry;
+	zval *z_entry;
 	newtComponent entry;
 	int flags;
 	int sense;
@@ -2763,7 +2677,7 @@
  */
 PHP_FUNCTION(newt_scale_set)
 {
-	zval * z_scale;
+	zval *z_scale;
 	newtComponent scale;
 	unsigned long long amount;
 
@@ -2781,43 +2695,41 @@
  */
 PHP_FUNCTION(newt_component_add_callback)
 {
-	zval *z_component, *z_func_name, *z_data;
+	zval *z_callback, *z_data, *z_component;
 	newtComponent component;
-	newt_data_st * cb;
-	php_serialize_data_t var_hash;
-	smart_str data_buf = {0}, func_buf = {0};
-	char *func_name_str = NULL;
+	php_newt_cb *cb = NULL;
 
-	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &z_component, \
&z_func_name, &z_data) == FAILURE) { +	cb = emalloc(sizeof(php_newt_cb));
+	memset (cb, 0, sizeof(php_newt_cb));
+	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "zz/z/", &z_component, \
&z_callback, &z_data) == FAILURE) { +		efree (cb);
 		return;
 	}
 
-	if (Z_TYPE_P(z_func_name) != IS_STRING && Z_TYPE_P(z_func_name) != IS_ARRAY) {
-		SEPARATE_ZVAL (&z_func_name);
-		convert_to_string_ex (&z_func_name);
+	if (Z_TYPE_P(z_callback) != IS_STRING && Z_TYPE_P(z_callback) != IS_ARRAY) {
+		SEPARATE_ZVAL (&z_callback);
+		convert_to_string_ex (&z_callback);
 	}
 
-	/* Fill callback struct */
-	cb = emalloc (sizeof(newt_data_st));
-	memset (cb, 0, sizeof(newt_data_st));
-
-	if (!zend_is_callable(z_func_name, 0, &func_name_str)) {
+	if (!zend_is_callable(z_callback, 0, &cb->func_name)) {
+		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument is expected to be a \
valid callback", cb->func_name); +		efree (cb->func_name);
 		efree (cb);
-		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument is expected to be a \
                valid callback", func_name_str);
-		efree (func_name_str);
 		return;
 	}
-	if(func_name_str) efree (func_name_str);
 
-	PHP_VAR_SERIALIZE_INIT(var_hash);
-	php_var_serialize(&data_buf, &z_data, &var_hash TSRMLS_CC);
-	cb->data = (char *) estrdup (data_buf.c);
-	php_var_serialize(&func_buf, &z_func_name, &var_hash TSRMLS_CC);
-	cb->func_name = (char *) estrdup (func_buf.c);
-	PHP_VAR_SERIALIZE_DESTROY(var_hash);
+	MAKE_STD_ZVAL(cb->callback);
+	*cb->callback = *z_callback;
+	zval_copy_ctor(cb->callback);
+
+	MAKE_STD_ZVAL(cb->data);
+	*cb->data = *z_data;
+	zval_copy_ctor(cb->data);
+
+	PHP_NEWT_STORE_CALLBACK (cb);
 
 	ZEND_FETCH_RESOURCE(component, newtComponent, &z_component, -1, le_newt_comp_name, \
                le_newt_comp);
-	newtComponentAddCallback (component, (newtCallback) newt_comp_callback_wrapper, \
cb); +	newtComponentAddCallback (component, (newtCallback) \
newt_comp_callback_wrapper, cb->key);  }
 /* }}} */
 
@@ -2826,7 +2738,7 @@
  */
 PHP_FUNCTION(newt_component_takes_focus)
 {
-	zval * z_component;
+	zval *z_component;
 	newtComponent component;
 	int takes_focus;
 
@@ -2843,7 +2755,7 @@
  */
 PHP_FUNCTION(newt_form_destroy)
 {
-	zval * z_form;
+	zval *z_form;
 	newtComponent form;
 
 	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_form) == FAILURE) {
@@ -3114,10 +3026,10 @@
  */
 PHP_FUNCTION(newt_grid_set_field)
 {
-	zval * z_grid;
+	zval *z_grid;
 	newtGrid grid;
 	int col, row, type;
-	zval * z_val;
+	zval *z_val;
 	newtComponent val;
 	int pad_left, pad_top, pad_right, pad_bottom, anchor, flags = 0;
 
@@ -3137,7 +3049,7 @@
  */
 PHP_FUNCTION(newt_grid_place)
 {
-	zval * z_grid;
+	zval *z_grid;
 	newtGrid grid;
 	int left, top;
 
@@ -3155,7 +3067,7 @@
  */
 PHP_FUNCTION(newt_grid_free)
 {
-	zval * z_grid;
+	zval *z_grid;
 	newtGrid grid;
 	int recurse;
 
@@ -3173,7 +3085,7 @@
  */
 PHP_FUNCTION(newt_grid_get_size)
 {
-	zval * z_grid;
+	zval *z_grid;
 	newtGrid grid;
 	zval *z_width = NULL, *z_height = NULL;
 	int width, height;
@@ -3201,7 +3113,7 @@
  */
 PHP_FUNCTION(newt_grid_wrapped_window)
 {
-	zval * z_grid;
+	zval *z_grid;
 	newtGrid grid;
 	char *title = NULL;
 	int title_len;
@@ -3220,7 +3132,7 @@
  */
 PHP_FUNCTION(newt_grid_wrapped_window_at)
 {
-	zval * z_grid;
+	zval *z_grid;
 	newtGrid grid;
 	char *title = NULL;
 	int title_len;
@@ -3240,7 +3152,7 @@
  */
 PHP_FUNCTION(newt_grid_add_components_to_form)
 {
-	zval * z_grid, * z_form;
+	zval *z_grid, *z_form;
 	newtGrid grid;
 	newtComponent form;
 	int recurse;
@@ -3305,9 +3217,7 @@
 			MAKE_STD_ZVAL (z_tmp);
 			ZEND_REGISTER_RESOURCE (z_tmp, buttons[bi], le_newt_comp);
 			zval_add_ref (&z_tmp);
-
-			zend_hash_update (Z_ARRVAL_P(z_buttons), newt_args[i], strlen(newt_args[i])+1,
-					(void **)&z_tmp, sizeof(zval *), NULL);
+			zend_hash_update (Z_ARRVAL_P(z_buttons), newt_args[i], strlen(newt_args[i])+1, \
(void **)&z_tmp, sizeof(zval *), NULL);  }
 	}
 	zend_hash_internal_pointer_reset (Z_ARRVAL_P(z_buttons));
@@ -3542,9 +3452,6 @@
 	int num_items, i;
 	char **buttons = NULL;
 	int num_buttons;
-	php_serialize_data_t var_hash_s;
-	smart_str buf = {0};
-	php_unserialize_data_t var_hash_u;
 	int rc;
 
 	int argc = ZEND_NUM_ARGS();
@@ -3564,9 +3471,9 @@
 	items = (struct newtWinEntry *) emalloc (sizeof(struct newtWinEntry) * \
(num_items+1));  
 	i=0;
-	PHP_VAR_SERIALIZE_INIT (var_hash_s);
 	while (zend_hash_index_find (Z_ARRVAL_P(z_items), i, (void **)&z_item) == SUCCESS) \
{  zval **z_item_text, **z_item_value, **z_item_flags;
+		char *key = NULL;
 
 		if(Z_TYPE_PP(z_item) != IS_ARRAY) {
 			efree (args);
@@ -3607,13 +3514,12 @@
 		}
 
 		items[i].text = Z_STRVAL_PP(z_item_text);
-		php_var_serialize(&buf, z_item_value, &var_hash_s TSRMLS_CC);
-		items[i].value = (const char **) &buf.c;
+		PHP_NEWT_STORE_DATA (*z_item_value, key);
+		items[i].value = (const char **) key;
 		items[i].flags = Z_LVAL_PP(z_item_flags);
 
 		i++;
 	}
-	PHP_VAR_SERIALIZE_DESTROY (var_hash_s);
 	items[i].text = NULL; // original function finishes processing items on null text \
entry  
 	newt_args = (void **) emalloc (sizeof(void *) * argc);
@@ -3638,17 +3544,14 @@
 			
 	rc = (int)newt_vcall ((void *)newtWinEntries, newt_args, argc);
 
-	PHP_VAR_UNSERIALIZE_INIT (var_hash_u);
 	for(i=0; i<num_items; i++) {
 		if (items[i].text && zend_hash_index_find (Z_ARRVAL_P(z_items), i, (void \
**)&z_item) == SUCCESS) {  zval *z_item_text;
-			const char *p = items[i].text;
-
-			php_var_unserialize(&z_item_text, &p, p + strlen(p), &var_hash_u TSRMLS_CC);
+			PHP_NEWT_FETCH_DATA (items[i].text, z_item_text);
 			zend_hash_update (Z_ARRVAL_PP(z_item), "text", sizeof("text"), (void \
*)&z_item_text, sizeof(zval *), NULL); +			zval_add_ref (&z_item_text);
 		}
 	}
-	PHP_VAR_UNSERIALIZE_DESTROY (var_hash_u);
 	
 	efree (args);
 	efree (items);
http://cvs.php.net/diff.php/pecl/newt/php_newt.h?r1=1.8&r2=1.9&ty=u
Index: pecl/newt/php_newt.h
diff -u pecl/newt/php_newt.h:1.8 pecl/newt/php_newt.h:1.9
--- pecl/newt/php_newt.h:1.8	Sun Dec 19 18:30:54 2004
+++ pecl/newt/php_newt.h	Mon Dec 27 12:57:10 2004
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_newt.h,v 1.8 2004/12/19 23:30:54 michael Exp $ */
+/* $Id: php_newt.h,v 1.9 2004/12/27 17:57:10 michael Exp $ */
 
 #include <newt.h>
 
@@ -172,40 +172,50 @@
 PHP_FUNCTION(newt_win_menu);
 PHP_FUNCTION(newt_win_entries);
 
-/* Structure for storing newt callbacks */
-typedef struct _newt_data_st {
-	char *func_name;
-	void *data;
-}
-newt_data_st;
-
 #ifndef newtComponent_struct
 struct newtComponent_struct {
 	int height, width;
 	int top, left;
 	int takesFocus;
 	int isMapped;
-	struct componentOps * ops;
+	struct componentOps *ops;
 	newtCallback callback;
-	void * callbackData;
-	void * data;
+	void *callbackData;
+	void *data;
 };
 #endif
 
+typedef struct {
+	char *func_name;
+	char *key;
+	zval *callback;
+	zval *data;
+}
+php_newt_cb;
+
+// Must be greater, that length of hexadecimal representation of memory address
+#define PHP_NEWT_RK_SIZE 8 *sizeof(void*)
+
 ZEND_BEGIN_MODULE_GLOBALS (newt)
-	zval *z_newt_help_callback;
+	HashTable callbacks;
+	HashTable data;
+	char *php_newt_help_cb_key;
 	int newt_has_inited;
 ZEND_END_MODULE_GLOBALS (newt)
 
 #define REGISTER_NEWT_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS | \
CONST_PERSISTENT)  
 /* Callback wrappers */
-static void newt_comp_callback_wrapper (newtComponent component, newt_data_st *cb);
-static int newt_entry_filter_callback_wrapper (newtComponent entry, newt_data_st * \
                cb, int ch, int cursor);
-static void newt_suspend_callback_wrapper (newt_data_st * cb);
+static void newt_comp_callback_wrapper (newtComponent component, void *cb_key);
+static int newt_entry_filter_callback_wrapper (newtComponent entry, void *cb_key, \
int ch, int cursor); +static void newt_suspend_callback_wrapper (void *cb_key);
 static void newt_help_callback_wrapper (newtComponent form, char *help);
 
-static int get_resource_by_data (zval * rsrc, void * data, int le_type);
+void php_newt_init_globals (zend_newt_globals *newt_globals TSRMLS_DC);
+void php_newt_destroy_globals(zend_newt_globals *newt_globals TSRMLS_DC);
+void php_newt_free_cb (php_newt_cb **cb_ptr);
+int php_newt_fetch_resource (zval *rsrc, void *data, int le_type);
+
 static void newt_call_php_function (INTERNAL_FUNCTION_PARAMETERS, char *func_name, \
zval **ret_val, int argc, zval ***args);  
 #ifdef ZTS



-- 
PECL CVS Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic