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

Commit

Permalink
include null properties
Browse files Browse the repository at this point in the history
  • Loading branch information
sirsnyder committed Oct 15, 2018
1 parent 4757713 commit 00779ab
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ zend_bool pthreads_globals_init(){
} else {
zend_hash_init(&PTHREADS_G(objects), 64, NULL, (dtor_func_t) NULL, 1);
zend_hash_init(&PTHREADS_G(postcompile), 15, NULL, (dtor_func_t) NULL, 1);
zend_hash_init(&PTHREADS_G(default_static_props), 15, NULL, (dtor_func_t) NULL, 1);
}

#if PHP_VERSION_ID >= 70300
Expand Down
5 changes: 5 additions & 0 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ struct _pthreads_globals {
*/
pthreads_monitor_t *compile_hook_monitor;

/*
* Default static props cache
*/
HashTable default_static_props;

/*
* High Frequency Strings
*/
Expand Down
48 changes: 43 additions & 5 deletions src/prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ static void prepare_class_constants(pthreads_object_t* thread, zend_class_entry

/* {{{ */
static void prepare_class_statics(pthreads_object_t* thread, zend_class_entry *candidate, zend_class_entry *prepared) {
pthreads_def_statics_t *def_statics;
zend_property_info *info;
zend_string *name;
pthreads_storage *storage;

if (candidate->default_static_members_count) {
int i;

Expand All @@ -107,15 +112,24 @@ static void prepare_class_statics(pthreads_object_t* thread, zend_class_entry *c
prepared->default_static_members_table = (zval*) ecalloc(
sizeof(zval), candidate->default_static_members_count);
prepared->default_static_members_count = candidate->default_static_members_count;

memcpy(prepared->default_static_members_table,
candidate->default_static_members_table,
sizeof(zval) * candidate->default_static_members_count);

for (i=0; i<prepared->default_static_members_count; i++) {
pthreads_store_separate(
&candidate->default_static_members_table[i],
&prepared->default_static_members_table[i], 0);
}
def_statics = zend_hash_find_ptr(&PTHREADS_G(default_static_props), candidate->name);

ZEND_HASH_FOREACH_STR_KEY_PTR(&candidate->properties_info, name, info) {
if((info->flags & ZEND_ACC_STATIC) != 0) {
if(def_statics && (storage = zend_hash_find_ptr(def_statics, name)) != NULL) {
pthreads_store_convert(storage, &prepared->default_static_members_table[info->offset]);
} else {
pthreads_store_separate(
&candidate->default_static_members_table[info->offset],
&prepared->default_static_members_table[info->offset], 0);
}
}
} ZEND_HASH_FOREACH_END();
prepared->static_members_table = prepared->default_static_members_table;
} else prepared->default_static_members_count = 0;
} /* }}} */
Expand Down Expand Up @@ -436,13 +450,37 @@ static inline void pthreads_prepare_closures(pthreads_object_t *thread) {
void prepare_class_postcompile(zend_class_entry *candidate) {
zend_property_info *info;
zend_string *name;
zval *property, tmp;
pthreads_def_statics_t *def_statics = NULL;

if(candidate->default_static_members_count > 0) {
def_statics = (pthreads_def_statics_t*) calloc(1, sizeof(pthreads_def_statics_t));
zend_hash_init(def_statics, 4, NULL, NULL, 1);
}

ZEND_HASH_FOREACH_STR_KEY_PTR(&candidate->properties_info, name, info) {
if (info->doc_comment &&
(strstr(ZSTR_VAL(info->doc_comment), "@thread_local") || strstr(ZSTR_VAL(info->doc_comment), "@threadLocal"))) {
info->flags |= PTHREADS_ACC_THREADLOCAL;
}

if((info->flags & ZEND_ACC_STATIC) != 0
&& def_statics != NULL
&& !zend_hash_exists(def_statics, name)) {
property = &candidate->default_static_members_table[info->offset];

ZVAL_PTR(&tmp, pthreads_store_create(property, 1));

zend_hash_add(def_statics, name, &tmp);
}
} ZEND_HASH_FOREACH_END();

if(def_statics != NULL) {
ZVAL_PTR(&tmp, def_statics);
zend_hash_add(
&PTHREADS_G(default_static_props),
candidate->name, &tmp);
}
}
/* }}} */

Expand Down
2 changes: 2 additions & 0 deletions src/prepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# include <src/pthreads.h>
#endif

typedef HashTable pthreads_def_statics_t;

/* {{{ */
void prepare_class_postcompile(zend_class_entry *candidate); /* }}} */

Expand Down
19 changes: 5 additions & 14 deletions src/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,13 @@
# include <src/copy.h>
#endif

typedef struct _pthreads_storage {
zend_uchar type;
size_t length;
zend_bool exists;
union {
zend_long lval;
double dval;
} simple;
void *data;
} pthreads_storage;
#ifndef HAVE_PTHREADS_STORE_H
# include <src/store.h>
#endif

#define PTHREADS_STORAGE_EMPTY {0, 0, 0, 0, NULL}

/* {{{ */
static pthreads_storage* pthreads_store_create(zval *pzval, zend_bool complex);
static int pthreads_store_convert(pthreads_storage *storage, zval *pzval);
static int pthreads_store_tostring(zval *pzval, char **pstring, size_t *slength, zend_bool complex);
static int pthreads_store_tozval(zval *pzval, char *pstring, size_t slength);
static void pthreads_store_storage_dtor (pthreads_storage *element);
Expand Down Expand Up @@ -606,7 +597,7 @@ void pthreads_store_free(pthreads_store_t *store){
} /* }}} */

/* {{{ */
static pthreads_storage* pthreads_store_create(zval *unstore, zend_bool complex){
pthreads_storage* pthreads_store_create(zval *unstore, zend_bool complex){
pthreads_storage *storage = NULL;

if (Z_TYPE_P(unstore) == IS_INDIRECT)
Expand Down Expand Up @@ -677,7 +668,7 @@ static pthreads_storage* pthreads_store_create(zval *unstore, zend_bool complex)
/* }}} */

/* {{{ */
static int pthreads_store_convert(pthreads_storage *storage, zval *pzval){
int pthreads_store_convert(pthreads_storage *storage, zval *pzval){
int result = SUCCESS;

switch(storage->type) {
Expand Down
13 changes: 13 additions & 0 deletions src/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@

typedef HashTable pthreads_store_t;

typedef struct _pthreads_storage {
zend_uchar type;
size_t length;
zend_bool exists;
union {
zend_long lval;
double dval;
} simple;
void *data;
} pthreads_storage;

pthreads_store_t* pthreads_store_alloc();
void pthreads_store_sync(zval *object);
int pthreads_store_merge(zval *destination, zval *from, zend_bool overwrite);
Expand All @@ -42,6 +53,8 @@ int pthreads_store_chunk(zval *object, zend_long size, zend_bool preserve, zval
int pthreads_store_pop(zval *object, zval *member);
int pthreads_store_count(zval *object, zend_long *count);
void pthreads_store_free(pthreads_store_t *store);
pthreads_storage* pthreads_store_create(zval *unstore, zend_bool complex);
int pthreads_store_convert(pthreads_storage *storage, zval *pzval);

/* {{{ * iteration helpers */
void pthreads_store_reset(zval *object, HashPosition *position);
Expand Down

0 comments on commit 00779ab

Please sign in to comment.