Skip to content

Commit

Permalink
Merge pull request #14 from zelgerj/v1.x.x
Browse files Browse the repository at this point in the history
added globals inheritation support
  • Loading branch information
zelgerj committed Apr 29, 2015
2 parents d0bff3e + d508119 commit e0c9ef3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 14 deletions.
16 changes: 14 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
language: c
language: php
php:
- 5.4
- 5.5
- 5.6

script: ./travis/ci.sh
script:
- phpize
- ./configure
- make
- REPORT_EXIT_STATUS=1 TEST_PHP_ARGS="-q --show-diff" make test

notifications:
email: [email protected]
hipchat: 95d47a72c5372d4a0fef20048c3200@Appserver
1 change: 1 addition & 0 deletions php_pthreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ PHP_MINIT_FUNCTION(pthreads)
REGISTER_LONG_CONSTANT("PTHREADS_INHERIT_COMMENTS", PTHREADS_INHERIT_COMMENTS, CONST_CS | CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("PTHREADS_ALLOW_HEADERS", PTHREADS_ALLOW_HEADERS, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PTHREADS_ALLOW_GLOBALS", PTHREADS_ALLOW_GLOBALS, CONST_CS | CONST_PERSISTENT);

INIT_CLASS_ENTRY(te, "Thread", pthreads_thread_methods);
te.create_object = pthreads_thread_ctor;
Expand Down
27 changes: 27 additions & 0 deletions src/prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,33 @@ void pthreads_prepare(PTHREAD thread TSRMLS_DC){
);
}

/* inherit globals */
if (thread->options & PTHREADS_ALLOW_GLOBALS) {
HashPosition position;
HashTable *tables[] = {&PTHREADS_EG(thread->cls, symbol_table), &EG(symbol_table)};
zval **symbol = NULL;

for (zend_hash_internal_pointer_reset_ex(tables[0], &position);
zend_hash_get_current_data_ex(tables[0], (void**) &symbol, &position) == SUCCESS;
zend_hash_move_forward_ex(tables[0], &position)) {
char *symname = NULL;
int symlen = 0;
zend_ulong symidx = 0L;

if (zend_hash_get_current_key_ex(tables[0], &symname, &symlen, &symidx, 0, &position) == HASH_KEY_IS_STRING) {
zval *separated = NULL;

if (pthreads_store_separate_from(*symbol, &separated, 1, 1, thread->cls TSRMLS_CC) == SUCCESS) {
Z_SET_REFCOUNT_P(separated, 1);
Z_SET_ISREF_P(separated);
zend_hash_update(tables[1], symname, symlen, (void**) &separated, sizeof(zval*), NULL);
} else {
zval_ptr_dtor(&separated);
}
}
}
}

/* set sensible resource destructor */
if (!PTHREADS_G(default_resource_dtor))
PTHREADS_G(default_resource_dtor)=(EG(regular_list).pDestructor);
Expand Down
23 changes: 23 additions & 0 deletions src/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,29 @@ zend_bool pthreads_store_unlock(zval *this_ptr TSRMLS_DC) {
return 0;
} /* }}} */

/* {{{ seperate a zval using internals */
int pthreads_store_separate_from(zval * pzval, zval **separated, zend_bool allocate, zend_bool complex, void ***parent TSRMLS_DC) {
int result = FAILURE;
pthreads_storage storage;

if (allocate) {
MAKE_STD_ZVAL(*separated);
}

if (pzval) {
pthreads_store_create(&storage, pzval, complex, parent);

result = pthreads_store_convert(
&storage, *separated TSRMLS_CC);

if (result == SUCCESS)
pthreads_store_storage_dtor(&storage);
else Z_TYPE_PP(separated) = IS_NULL;
} else Z_TYPE_PP(separated) = IS_NULL;

return result;
} /* }}} */

/* {{{ delete a value from the store */
int pthreads_store_delete(pthreads_store store, char *key, int keyl TSRMLS_DC) {
int result = FAILURE;
Expand Down
3 changes: 3 additions & 0 deletions src/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ void pthreads_store_zval_reset(pthreads_store store TSRMLS_DC); /* }}} */
/* {{{ free buffers */
void pthreads_store_free(pthreads_store store TSRMLS_DC); /* }}} */

/* {{{ separate a zval using internals */
int pthreads_store_separate_from(zval * pzval, zval **separated, zend_bool allocate, zend_bool complex, void ***parent TSRMLS_DC); /* }}} */

#endif
3 changes: 2 additions & 1 deletion src/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ static inline int pthreads_equal_func(void **first, void **second){
#define PTHREADS_INHERIT_INCLUDES 0x00010000
#define PTHREADS_INHERIT_COMMENTS 0x00100000
#define PTHREADS_INHERIT_ALL 0x00111111
#define PTHREADS_ALLOW_HEADERS 0x01000000 /* }}} */
#define PTHREADS_ALLOW_GLOBALS 0x01000000
#define PTHREADS_ALLOW_HEADERS 0x10000000 /* }}} */

/* {{{ scope constants */
#define PTHREADS_SCOPE_UNKNOWN 0x00000000
Expand Down
11 changes: 0 additions & 11 deletions travis/ci.sh

This file was deleted.

0 comments on commit e0c9ef3

Please sign in to comment.