Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
normalize members with (cast) to help with #78 and #79
Browse files Browse the repository at this point in the history
  • Loading branch information
krakjoe committed Mar 22, 2013
1 parent f16e614 commit bdc6f9f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
3 changes: 2 additions & 1 deletion php_pthreads.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ PHP_MINIT_FUNCTION(pthreads)


memcpy(&pthreads_handlers, zend_handlers, sizeof(zend_object_handlers)); 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.count_elements = pthreads_count_properties;

pthreads_handlers.get_debug_info = pthreads_read_debug; pthreads_handlers.get_debug_info = pthreads_read_debug;
pthreads_handlers.get_properties = pthreads_read_properties; pthreads_handlers.get_properties = pthreads_read_properties;


Expand Down
17 changes: 17 additions & 0 deletions src/handlers.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 #endif
14 changes: 9 additions & 5 deletions src/handlers.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 #ifndef HAVE_PTHREADS_HANDLERS_H
#define HAVE_PTHREADS_HANDLERS_H #define HAVE_PTHREADS_HANDLERS_H
Expand All @@ -30,10 +30,13 @@
# include <src/store.h> # include <src/store.h>
#endif #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 */ /* {{{ these resolve differences in 5.3 and 5.4 object handling API */
#if PHP_VERSION_ID > 50399 #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_D zval *object, int *is_temp TSRMLS_DC
# define PTHREADS_READ_DEBUG_PASSTHRU_C object, is_temp TSRMLS_CC # define PTHREADS_READ_DEBUG_PASSTHRU_C object, is_temp TSRMLS_CC
# define PTHREADS_READ_PROPERTIES_PASSTHRU_D zval *object TSRMLS_DC # define PTHREADS_READ_PROPERTIES_PASSTHRU_D zval *object TSRMLS_DC
Expand Down Expand Up @@ -63,8 +66,6 @@
# define PTHREADS_CALL_METHOD_PASSTHRU_D const char *method, INTERNAL_FUNCTION_PARAMETERS # define PTHREADS_CALL_METHOD_PASSTHRU_D const char *method, INTERNAL_FUNCTION_PARAMETERS
# define PTHREADS_CALL_METHOD_PASSTHRU_C method, INTERNAL_FUNCTION_PARAM_PASSTHRU # define PTHREADS_CALL_METHOD_PASSTHRU_C method, INTERNAL_FUNCTION_PARAM_PASSTHRU
#else #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_D zval *object, int *is_temp TSRMLS_DC
# define PTHREADS_READ_DEBUG_PASSTHRU_C object, is_temp TSRMLS_CC # define PTHREADS_READ_DEBUG_PASSTHRU_C object, is_temp TSRMLS_CC
# define PTHREADS_READ_PROPERTIES_PASSTHRU_D zval *object TSRMLS_DC # define PTHREADS_READ_PROPERTIES_PASSTHRU_D zval *object TSRMLS_DC
Expand Down Expand Up @@ -125,4 +126,7 @@ zend_function * pthreads_get_method(PTHREADS_GET_METHOD_PASSTHRU_D); /* }}} */


/* {{{ make a pthreads method call */ /* {{{ make a pthreads method call */
int pthreads_call_method(PTHREADS_CALL_METHOD_PASSTHRU_D); /* }}} */ 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 #endif
22 changes: 22 additions & 0 deletions tests/normalize-members.phpt
Original file line number Original file line Diff line number Diff line change
@@ -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.