Permalink
Browse files

normalize members with (cast) to help with #78 and #79

  • Loading branch information...
1 parent f16e614 commit bdc6f9fb08e4a99795de03b4b99c666e3b509202 @krakjoe committed Mar 22, 2013
Showing with 50 additions and 6 deletions.
  1. +2 −1 php_pthreads.c
  2. +17 −0 src/handlers.c
  3. +9 −5 src/handlers.h
  4. +22 −0 tests/normalize-members.phpt
View
@@ -152,8 +152,9 @@ PHP_MINIT_FUNCTION(pthreads)
memcpy(&pthreads_handlers, zend_handlers, sizeof(zend_object_handlers));
+ pthreads_handlers.cast_object = pthreads_cast_object;
pthreads_handlers.count_elements = pthreads_count_properties;
-
+
pthreads_handlers.get_debug_info = pthreads_read_debug;
pthreads_handlers.get_properties = pthreads_read_properties;
View
@@ -458,4 +458,21 @@ int pthreads_call_method(PTHREADS_CALL_METHOD_PASSTHRU_D) {
} /* }}} */
+/* {{{ pthreads_cast_object */
+int pthreads_cast_object(PTHREADS_CAST_PASSTHRU_D) {
+ switch (type) {
+ case IS_ARRAY: {
+ pthreads_store_tohash(
+ (PTHREADS_FETCH_FROM(from))->store, Z_ARRVAL_P(to) TSRMLS_CC
+ );
+ return SUCCESS;
+ } break;
+
+ default:
+ return FAILURE;
+ }
+
+ return SUCCESS;
+} /* }}} */
+
#endif
View
@@ -17,7 +17,7 @@
*/
/*
-* These handlers provide thread-safe read/write/call for pthreads objects
+* These handlers provide thread-safe read/write/call/count/cast for pthreads objects
*/
#ifndef HAVE_PTHREADS_HANDLERS_H
#define HAVE_PTHREADS_HANDLERS_H
@@ -30,10 +30,13 @@
# include <src/store.h>
#endif
+#define PTHREADS_CAST_PASSTHRU_D zval *from, zval *to, int type TSRMLS_DC
+#define PTHREADS_CAST_PASSTHRU_C from, to, type TSRMLS_CC
+#define PTHREADS_COUNT_PASSTHRU_D zval *object, long *count TSRMLS_DC
+#define PTHREADS_COUNT_PASSTHRU_C object, count TSRMLS_CC
+
/* {{{ these resolve differences in 5.3 and 5.4 object handling API */
#if PHP_VERSION_ID > 50399
-# define PTHREADS_COUNT_PASSTHRU_D zval *object, long *count TSRMLS_DC
-# define PTHREADS_COUNT_PASSTHRU_C object, count TSRMLS_CC
# define PTHREADS_READ_DEBUG_PASSTHRU_D zval *object, int *is_temp TSRMLS_DC
# define PTHREADS_READ_DEBUG_PASSTHRU_C object, is_temp TSRMLS_CC
# define PTHREADS_READ_PROPERTIES_PASSTHRU_D zval *object TSRMLS_DC
@@ -63,8 +66,6 @@
# define PTHREADS_CALL_METHOD_PASSTHRU_D const char *method, INTERNAL_FUNCTION_PARAMETERS
# define PTHREADS_CALL_METHOD_PASSTHRU_C method, INTERNAL_FUNCTION_PARAM_PASSTHRU
#else
-# define PTHREADS_COUNT_PASSTHRU_D zval *object, long *count TSRMLS_DC
-# define PTHREADS_COUNT_PASSTHRU_C object, count TSRMLS_CC
# define PTHREADS_READ_DEBUG_PASSTHRU_D zval *object, int *is_temp TSRMLS_DC
# define PTHREADS_READ_DEBUG_PASSTHRU_C object, is_temp TSRMLS_CC
# define PTHREADS_READ_PROPERTIES_PASSTHRU_D zval *object TSRMLS_DC
@@ -125,4 +126,7 @@ zend_function * pthreads_get_method(PTHREADS_GET_METHOD_PASSTHRU_D); /* }}} */
/* {{{ make a pthreads method call */
int pthreads_call_method(PTHREADS_CALL_METHOD_PASSTHRU_D); /* }}} */
+
+/* {{{ cast an object to a normal array helper */
+int pthreads_cast_object(PTHREADS_CAST_PASSTHRU_D); /* }}} */
#endif
@@ -0,0 +1,22 @@
+--TEST--
+Testing normalizing members
+--DESCRIPTION--
+This test works that normalizing members works without effort
+--FILE--
+<?php
+class Test extends Stackable {
+ public function run() {
+ }
+}
+
+$t = new Test();
+$t[] = "one";
+$t[] = "two";
+$t["three"] = "three";
+
+/* get a normal array */
+$normal = (array) $t;
+var_dump(is_array($normal));
+?>
+--EXPECT--
+bool(true)

0 comments on commit bdc6f9f

Please sign in to comment.