Skip to content

Commit 6de38b4

Browse files
committed
housework [ci skip]
1 parent 49c2d80 commit 6de38b4

File tree

3 files changed

+52
-46
lines changed

3 files changed

+52
-46
lines changed

php_pthreads.c

-46
Original file line numberDiff line numberDiff line change
@@ -130,52 +130,6 @@ void pthreads_throw_exception_hook(zval *ex TSRMLS_DC) {
130130
}
131131
}
132132

133-
static inline int pthreads_threaded_serialize(zval *object, unsigned char **buffer, size_t *buflen, zend_serialize_data *data) {
134-
pthreads_object_t *address = PTHREADS_FETCH_FROM(Z_OBJ_P(object));
135-
136-
(*buflen) = snprintf(NULL, 0, ":%lu:", (long unsigned int) address);
137-
(*buffer) = emalloc((*buflen) + 1);
138-
sprintf(
139-
(*buffer), ":%lu:", (long unsigned int) address);
140-
(*buffer)[(*buflen)] = 0;
141-
142-
return SUCCESS;
143-
}
144-
145-
static inline int pthreads_threaded_unserialize(zval *object, zend_class_entry *ce, const unsigned char *buffer, size_t buflen, zend_unserialize_data *data) {
146-
pthreads_object_t *address = NULL;
147-
148-
if (!sscanf((const char*) buffer, ":%lu:", (long unsigned int*)&address)) {
149-
zend_throw_exception_ex(spl_ce_RuntimeException, 0,
150-
"pthreads detected an attempt to connect to a corrupted object");
151-
return FAILURE;
152-
}
153-
154-
if (!address) {
155-
zend_throw_exception_ex(spl_ce_RuntimeException, 0,
156-
"pthreads detected an attempt to connect to an invalid object");
157-
return FAILURE;
158-
}
159-
160-
if (!pthreads_globals_object_validate((zend_ulong) address)) {
161-
zend_throw_exception_ex(spl_ce_RuntimeException, 0,
162-
"pthreads detected an attempt to connect to an object which has already been destroyed");
163-
return FAILURE;
164-
}
165-
166-
if (PTHREADS_IN_CREATOR(address)) {
167-
ZVAL_OBJ(object, &address->std);
168-
Z_ADDREF_P(object);
169-
} else {
170-
object_init_ex(object, ce);
171-
pthreads_connect(
172-
address,
173-
PTHREADS_FETCH_FROM(Z_OBJ_P(object)));
174-
}
175-
176-
return SUCCESS;
177-
}
178-
179133
PHP_MINIT_FUNCTION(pthreads)
180134
{
181135
zend_class_entry ce;

src/object.c

+48
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,54 @@ zend_object* pthreads_threaded_ctor(zend_class_entry *entry) {
145145
return &threaded->std;
146146
} /* }}} */
147147

148+
/* {{{ */
149+
int pthreads_threaded_serialize(zval *object, unsigned char **buffer, size_t *buflen, zend_serialize_data *data) {
150+
pthreads_object_t *address = PTHREADS_FETCH_FROM(Z_OBJ_P(object));
151+
152+
(*buflen) = snprintf(NULL, 0, ":%lu:", (long unsigned int) address);
153+
(*buffer) = emalloc((*buflen) + 1);
154+
sprintf(
155+
(*buffer), ":%lu:", (long unsigned int) address);
156+
(*buffer)[(*buflen)] = 0;
157+
158+
return SUCCESS;
159+
} /* }}} */
160+
161+
/* {{{ */
162+
int pthreads_threaded_unserialize(zval *object, zend_class_entry *ce, const unsigned char *buffer, size_t buflen, zend_unserialize_data *data) {
163+
pthreads_object_t *address = NULL;
164+
165+
if (!sscanf((const char*) buffer, ":%lu:", (long unsigned int*)&address)) {
166+
zend_throw_exception_ex(spl_ce_RuntimeException, 0,
167+
"pthreads detected an attempt to connect to a corrupted object");
168+
return FAILURE;
169+
}
170+
171+
if (!address) {
172+
zend_throw_exception_ex(spl_ce_RuntimeException, 0,
173+
"pthreads detected an attempt to connect to an invalid object");
174+
return FAILURE;
175+
}
176+
177+
if (!pthreads_globals_object_validate((zend_ulong) address)) {
178+
zend_throw_exception_ex(spl_ce_RuntimeException, 0,
179+
"pthreads detected an attempt to connect to an object which has already been destroyed");
180+
return FAILURE;
181+
}
182+
183+
if (PTHREADS_IN_CREATOR(address)) {
184+
ZVAL_OBJ(object, &address->std);
185+
Z_ADDREF_P(object);
186+
} else {
187+
object_init_ex(object, ce);
188+
pthreads_connect(
189+
address,
190+
PTHREADS_FETCH_FROM(Z_OBJ_P(object)));
191+
}
192+
193+
return SUCCESS;
194+
} /* }}} */
195+
148196
/* {{{ */
149197
void pthreads_current_thread(zval *return_value) {
150198
if (Z_TYPE(PTHREADS_ZG(this)) != IS_UNDEF) {

src/object.h

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ zend_object* pthreads_worker_ctor(zend_class_entry *entry);
3232
zend_object* pthreads_thread_ctor(zend_class_entry *entry);
3333
void pthreads_base_free(zend_object *object); /* }}} */
3434

35+
/* {{{ */
36+
int pthreads_threaded_unserialize(zval *object, zend_class_entry *ce, const unsigned char *buffer, size_t buflen, zend_unserialize_data *data);
37+
int pthreads_threaded_serialize(zval *object, unsigned char **buffer, size_t *buflen, zend_serialize_data *data); /* }}} */
38+
3539
/* {{{ */
3640
void pthreads_current_thread(zval *return_value); /* }}} */
3741

0 commit comments

Comments
 (0)