@@ -145,6 +145,54 @@ zend_object* pthreads_threaded_ctor(zend_class_entry *entry) {
145
145
return & threaded -> std ;
146
146
} /* }}} */
147
147
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
+
148
196
/* {{{ */
149
197
void pthreads_current_thread (zval * return_value ) {
150
198
if (Z_TYPE (PTHREADS_ZG (this )) != IS_UNDEF ) {
0 commit comments