Skip to content

Commit e0c9ef3

Browse files
committed
Merge pull request #14 from zelgerj/v1.x.x
added globals inheritation support
2 parents d0bff3e + d508119 commit e0c9ef3

7 files changed

Lines changed: 70 additions & 14 deletions

File tree

.travis.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1-
language: c
1+
language: php
2+
php:
3+
- 5.4
4+
- 5.5
5+
- 5.6
26

3-
script: ./travis/ci.sh
7+
script:
8+
- phpize
9+
- ./configure
10+
- make
11+
- REPORT_EXIT_STATUS=1 TEST_PHP_ARGS="-q --show-diff" make test
12+
13+
notifications:
14+
email: jz@appserver.io
15+
hipchat: 95d47a72c5372d4a0fef20048c3200@Appserver

php_pthreads.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ PHP_MINIT_FUNCTION(pthreads)
153153
REGISTER_LONG_CONSTANT("PTHREADS_INHERIT_COMMENTS", PTHREADS_INHERIT_COMMENTS, CONST_CS | CONST_PERSISTENT);
154154

155155
REGISTER_LONG_CONSTANT("PTHREADS_ALLOW_HEADERS", PTHREADS_ALLOW_HEADERS, CONST_CS | CONST_PERSISTENT);
156+
REGISTER_LONG_CONSTANT("PTHREADS_ALLOW_GLOBALS", PTHREADS_ALLOW_GLOBALS, CONST_CS | CONST_PERSISTENT);
156157

157158
INIT_CLASS_ENTRY(te, "Thread", pthreads_thread_methods);
158159
te.create_object = pthreads_thread_ctor;

src/prepare.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,33 @@ void pthreads_prepare(PTHREAD thread TSRMLS_DC){
548548
);
549549
}
550550

551+
/* inherit globals */
552+
if (thread->options & PTHREADS_ALLOW_GLOBALS) {
553+
HashPosition position;
554+
HashTable *tables[] = {&PTHREADS_EG(thread->cls, symbol_table), &EG(symbol_table)};
555+
zval **symbol = NULL;
556+
557+
for (zend_hash_internal_pointer_reset_ex(tables[0], &position);
558+
zend_hash_get_current_data_ex(tables[0], (void**) &symbol, &position) == SUCCESS;
559+
zend_hash_move_forward_ex(tables[0], &position)) {
560+
char *symname = NULL;
561+
int symlen = 0;
562+
zend_ulong symidx = 0L;
563+
564+
if (zend_hash_get_current_key_ex(tables[0], &symname, &symlen, &symidx, 0, &position) == HASH_KEY_IS_STRING) {
565+
zval *separated = NULL;
566+
567+
if (pthreads_store_separate_from(*symbol, &separated, 1, 1, thread->cls TSRMLS_CC) == SUCCESS) {
568+
Z_SET_REFCOUNT_P(separated, 1);
569+
Z_SET_ISREF_P(separated);
570+
zend_hash_update(tables[1], symname, symlen, (void**) &separated, sizeof(zval*), NULL);
571+
} else {
572+
zval_ptr_dtor(&separated);
573+
}
574+
}
575+
}
576+
}
577+
551578
/* set sensible resource destructor */
552579
if (!PTHREADS_G(default_resource_dtor))
553580
PTHREADS_G(default_resource_dtor)=(EG(regular_list).pDestructor);

src/store.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,29 @@ zend_bool pthreads_store_unlock(zval *this_ptr TSRMLS_DC) {
114114
return 0;
115115
} /* }}} */
116116

117+
/* {{{ seperate a zval using internals */
118+
int pthreads_store_separate_from(zval * pzval, zval **separated, zend_bool allocate, zend_bool complex, void ***parent TSRMLS_DC) {
119+
int result = FAILURE;
120+
pthreads_storage storage;
121+
122+
if (allocate) {
123+
MAKE_STD_ZVAL(*separated);
124+
}
125+
126+
if (pzval) {
127+
pthreads_store_create(&storage, pzval, complex, parent);
128+
129+
result = pthreads_store_convert(
130+
&storage, *separated TSRMLS_CC);
131+
132+
if (result == SUCCESS)
133+
pthreads_store_storage_dtor(&storage);
134+
else Z_TYPE_PP(separated) = IS_NULL;
135+
} else Z_TYPE_PP(separated) = IS_NULL;
136+
137+
return result;
138+
} /* }}} */
139+
117140
/* {{{ delete a value from the store */
118141
int pthreads_store_delete(pthreads_store store, char *key, int keyl TSRMLS_DC) {
119142
int result = FAILURE;

src/store.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,7 @@ void pthreads_store_zval_reset(pthreads_store store TSRMLS_DC); /* }}} */
8585
/* {{{ free buffers */
8686
void pthreads_store_free(pthreads_store store TSRMLS_DC); /* }}} */
8787

88+
/* {{{ separate a zval using internals */
89+
int pthreads_store_separate_from(zval * pzval, zval **separated, zend_bool allocate, zend_bool complex, void ***parent TSRMLS_DC); /* }}} */
90+
8891
#endif

src/thread.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ static inline int pthreads_equal_func(void **first, void **second){
173173
#define PTHREADS_INHERIT_INCLUDES 0x00010000
174174
#define PTHREADS_INHERIT_COMMENTS 0x00100000
175175
#define PTHREADS_INHERIT_ALL 0x00111111
176-
#define PTHREADS_ALLOW_HEADERS 0x01000000 /* }}} */
176+
#define PTHREADS_ALLOW_GLOBALS 0x01000000
177+
#define PTHREADS_ALLOW_HEADERS 0x10000000 /* }}} */
177178

178179
/* {{{ scope constants */
179180
#define PTHREADS_SCOPE_UNKNOWN 0x00000000

travis/ci.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)