• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

krakjoe / parallel / 20173476927

12 Dec 2025 04:40PM UTC coverage: 96.534% (-0.3%) from 96.815%
20173476927

Pull #355

github

web-flow
Merge fad990571 into 14042a874
Pull Request #355: Handle undefined functions

57 of 68 new or added lines in 2 files covered. (83.82%)

13 existing lines in 2 files now uncovered.

3064 of 3174 relevant lines covered (96.53%)

6754.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.26
/src/exceptions.c
1
/*
2
  +----------------------------------------------------------------------+
3
  | parallel                                                             |
4
  +----------------------------------------------------------------------+
5
  | Copyright (c) Joe Watkins 2019-2024                                  |
6
  +----------------------------------------------------------------------+
7
  | This source file is subject to version 3.01 of the PHP license,      |
8
  | that is bundled with this package in the file LICENSE, and is        |
9
  | available through the world-wide-web at the following url:           |
10
  | http://www.php.net/license/3_01.txt                                  |
11
  | If you did not receive a copy of the PHP license and are unable to   |
12
  | obtain it through the world-wide-web, please send a note to          |
13
  | license@php.net so we can mail you a copy immediately.               |
14
  +----------------------------------------------------------------------+
15
  | Author: krakjoe                                                      |
16
  +----------------------------------------------------------------------+
17
 */
18
#ifndef HAVE_PARALLEL_EXCEPTIONS
19
#define HAVE_PARALLEL_EXCEPTIONS
20

21
#include "parallel.h"
22

23
struct _php_parallel_exception_t {
24
    zval class;
25
    zval file;
26
    zval line;
27
    zval code;
28
    zval message;
29
    zval trace;
30
    zval previous;
31
    const zend_object_handlers *handlers;
32
};
33

34
zend_class_entry* php_parallel_error_ce;
35
zend_class_entry* php_parallel_error_invalid_arguments_ce;
36

37
zend_class_entry* php_parallel_runtime_error_ce;
38
zend_class_entry* php_parallel_runtime_error_bootstrap_ce;
39
zend_class_entry* php_parallel_runtime_error_closed_ce;
40
zend_class_entry* php_parallel_runtime_error_killed_ce;
41
zend_class_entry* php_parallel_runtime_error_illegal_function_ce;
42
zend_class_entry* php_parallel_runtime_error_illegal_instruction_ce;
43
zend_class_entry* php_parallel_runtime_error_illegal_variable_ce;
44
zend_class_entry* php_parallel_runtime_error_illegal_parameter_ce;
45
zend_class_entry* php_parallel_runtime_error_illegal_type_ce;
46
zend_class_entry* php_parallel_runtime_error_illegal_return_ce;
47

48
zend_class_entry* php_parallel_future_error_ce;
49
zend_class_entry* php_parallel_future_error_killed_ce;
50
zend_class_entry* php_parallel_future_error_cancelled_ce;
51
zend_class_entry* php_parallel_future_error_foreign_ce;
52

53
zend_class_entry* php_parallel_channel_error_ce;
54
zend_class_entry* php_parallel_channel_error_existence_ce;
55
zend_class_entry* php_parallel_channel_error_illegal_value_ce;
56
zend_class_entry* php_parallel_channel_error_closed_ce;
57

58
zend_class_entry* php_parallel_sync_error_ce;
59
zend_class_entry* php_parallel_sync_error_illegal_value_ce;
60
zend_class_entry* php_parallel_sync_error_illegal_type_ce;
61
zend_class_entry* php_parallel_sync_error_illegal_offset_ce;
62
zend_class_entry* php_parallel_sync_error_illegal_access_ce;
63

64
zend_class_entry* php_parallel_events_error_ce;
65
zend_class_entry* php_parallel_events_error_existence_ce;
66
zend_class_entry* php_parallel_events_error_timeout_ce;
67

68
zend_class_entry* php_parallel_events_input_error_ce;
69
zend_class_entry* php_parallel_events_input_error_existence_ce;
70
zend_class_entry* php_parallel_events_input_error_illegal_value_ce;
71

72
zend_class_entry* php_parallel_events_event_error_ce;
73

74
static zend_always_inline zval* php_parallel_exceptions_read(zend_object *exception, zend_string *property) {
380✔
75
    zend_property_info *info;
380✔
76
    zend_class_entry *scope = EG(fake_scope);
380✔
77

78
    EG(fake_scope) = zend_ce_error;
380✔
79

80
    info = zend_get_property_info(zend_ce_error, property, 1);
456✔
81

82
    EG(fake_scope) = scope;
380✔
83

84
    return OBJ_PROP(exception, info->offset);
380✔
85
}
86

87
static zend_always_inline void php_parallel_exceptions_write(zend_object *exception, zend_string *property, zval *value) {
456✔
88
    zend_property_info *info;
456✔
89
    zend_class_entry *scope = EG(fake_scope);
456✔
90
    zval *slot;
456✔
91

92
    EG(fake_scope) = zend_ce_error;
456✔
93

94
    info = zend_get_property_info(zend_ce_error, property, 1);
912✔
95

96
    slot = OBJ_PROP(exception, info->offset);
456✔
97

98
    if (Z_REFCOUNTED_P(slot)) {
456✔
99
        zval_ptr_dtor(slot);
×
100
    }
101

102
    ZVAL_COPY_VALUE(slot, value);
456✔
103

104
    EG(fake_scope) = scope;
456✔
105
}
106

107
zend_object* php_parallel_exception_object(zend_class_entry *ce, const char *message, zend_long code, zend_string *file, zend_long line) {
4✔
108
    zend_object *exception = zend_objects_new(ce);
4✔
109

110
    object_properties_init(exception, ce);
4✔
111

112
    if (message) {
4✔
113
        zend_update_property_string(ce, exception, "message", sizeof("message")-1, message);
4✔
114
    }
115

116
    if (code) {
4✔
NEW
117
        zend_update_property_long(ce, exception, "code", sizeof("code")-1, code);
×
118
    }
119

120
    if (file) {
4✔
121
        zend_update_property_str(ce, exception, "file", sizeof("file")-1, file);
4✔
122
    }
123

124
    if (line) {
4✔
125
        zend_update_property_long(ce, exception, "line", sizeof("line")-1, line);
4✔
126
    }
127

128
    return exception;
4✔
129
}
130

131
void php_parallel_exceptions_destroy(php_parallel_exception_t *ex) {
76✔
132
    PARALLEL_ZVAL_DTOR(&ex->class);
76✔
133
    PARALLEL_ZVAL_DTOR(&ex->file);
76✔
134
    PARALLEL_ZVAL_DTOR(&ex->line);
76✔
135
    PARALLEL_ZVAL_DTOR(&ex->message);
76✔
136
    PARALLEL_ZVAL_DTOR(&ex->code);
76✔
137
    PARALLEL_ZVAL_DTOR(&ex->trace);
76✔
138
    PARALLEL_ZVAL_DTOR(&ex->previous);
76✔
139

140
    pefree(ex, 1);
76✔
141
}
76✔
142

143
void php_parallel_exceptions_save(zval *saved, zend_object *exception) {
76✔
144
    zval class,
76✔
145
         *file     = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_FILE)),
76✔
146
         *line     = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_LINE)),
76✔
147
         *message  = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_MESSAGE)),
76✔
148
         *code     = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_CODE)),
76✔
149
         *trace    = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_TRACE)),
76✔
150
         previous;
151

152
    php_parallel_exception_t *ex =
76✔
153
        (php_parallel_exception_t*)
154
            pecalloc(1, sizeof(php_parallel_exception_t), 1);
76✔
155

156
    /* todo */
157
    ZVAL_NULL(&previous);
76✔
158

159
    ZVAL_STR(&class, exception->ce->name);
76✔
160

161
    PARALLEL_ZVAL_COPY(&ex->class,   &class,     1);
76✔
162
    PARALLEL_ZVAL_COPY(&ex->file,    file,       1);
76✔
163
    PARALLEL_ZVAL_COPY(&ex->line,    line,       1);
76✔
164
    PARALLEL_ZVAL_COPY(&ex->message, message,    1);
76✔
165
    PARALLEL_ZVAL_COPY(&ex->code,    code,       1);
76✔
166
    PARALLEL_ZVAL_COPY(&ex->trace,   trace,      1);
76✔
167
    PARALLEL_ZVAL_COPY(&ex->previous, &previous, 1);
76✔
168

169
    ex->handlers = exception->handlers;
76✔
170

171
    ZVAL_PTR(saved, ex);
76✔
172

173
    zend_clear_exception();
76✔
174
}
76✔
175

176
zend_object* php_parallel_exceptions_restore(zval *exception) {
76✔
177
    zend_object      *object;
76✔
178
    zend_class_entry *type;
76✔
179
    zval file, line, message, code, trace, previous;
76✔
180

181
    php_parallel_exception_t *ex =
76✔
182
        (php_parallel_exception_t*) Z_PTR_P(exception);
183

184
    PARALLEL_ZVAL_COPY(&file,     &ex->file,     0);
76✔
185
    PARALLEL_ZVAL_COPY(&line,     &ex->line,     0);
76✔
186
    PARALLEL_ZVAL_COPY(&message,  &ex->message,  0);
76✔
187
    PARALLEL_ZVAL_COPY(&code,     &ex->code,     0);
76✔
188
    PARALLEL_ZVAL_COPY(&trace,    &ex->trace,    0);
76✔
189
    PARALLEL_ZVAL_COPY(&previous, &ex->previous, 0);
76✔
190

191
    type = zend_lookup_class(Z_STR(ex->class));
76✔
192

193
    if (!type) {
76✔
194
        /* we lost type info */
195
        type = php_parallel_future_error_foreign_ce;
×
196
    }
197

198
    object = zend_objects_new(type);
76✔
199
    object->handlers = ex->handlers;
76✔
200
    object_properties_init(object, type);
76✔
201

202
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_FILE),     &file);
76✔
203
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_LINE),     &line);
76✔
204
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_MESSAGE),  &message);
76✔
205
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_CODE),     &code);
76✔
206
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_TRACE),    &trace);
76✔
207
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_PREVIOUS), &previous);
76✔
208

209
    return object;
76✔
210
}
211

212
PHP_MINIT_FUNCTION(PARALLEL_EXCEPTIONS)
3,226✔
213
{
214
    zend_class_entry ce;
3,226✔
215

216
    /*
217
    * Base Exceptions
218
    */
219
    INIT_NS_CLASS_ENTRY(ce, "parallel", "Error", NULL);
3,226✔
220
    php_parallel_error_ce =
6,452✔
221
        zend_register_internal_class_ex(&ce, zend_ce_error);
3,226✔
222

223
    /*
224
    * Runtime Exceptions
225
    */
226
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime", "Error", NULL);
3,226✔
227
    php_parallel_runtime_error_ce =
6,452✔
228
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
229

230
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "Bootstrap", NULL);
3,226✔
231
    php_parallel_runtime_error_bootstrap_ce =
6,452✔
232
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,226✔
233

234
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "Closed", NULL);
3,226✔
235
    php_parallel_runtime_error_closed_ce =
6,452✔
236
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,226✔
237

238
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "Killed", NULL);
3,226✔
239
    php_parallel_runtime_error_killed_ce =
6,452✔
240
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,226✔
241

242
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalFunction", NULL);
3,226✔
243
    php_parallel_runtime_error_illegal_function_ce =
6,452✔
244
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,226✔
245

246
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalVariable", NULL);
3,226✔
247
    php_parallel_runtime_error_illegal_variable_ce =
6,452✔
248
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,226✔
249

250
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalParameter", NULL);
3,226✔
251
    php_parallel_runtime_error_illegal_parameter_ce =
6,452✔
252
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,226✔
253

254
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalInstruction", NULL);
3,226✔
255
    php_parallel_runtime_error_illegal_instruction_ce =
6,452✔
256
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,226✔
257

258
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalReturn", NULL);
3,226✔
259
    php_parallel_runtime_error_illegal_return_ce =
6,452✔
260
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,226✔
261

262
    /*
263
    * Future Exceptions
264
    */
265
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future", "Error", NULL);
3,226✔
266
    php_parallel_future_error_ce =
6,452✔
267
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
268

269
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future\\Error", "Killed", NULL);
3,226✔
270
    php_parallel_future_error_killed_ce =
6,452✔
271
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
272

273
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future\\Error", "Cancelled", NULL);
3,226✔
274
    php_parallel_future_error_cancelled_ce =
6,452✔
275
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
276

277
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future\\Error", "Foreign", NULL);
3,226✔
278
    php_parallel_future_error_foreign_ce =
6,452✔
279
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
280

281
    /*
282
    * Channel Exceptions
283
    */
284
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel", "Error", NULL);
3,226✔
285
    php_parallel_channel_error_ce =
6,452✔
286
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
287

288
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel\\Error", "Existence", NULL);
3,226✔
289
    php_parallel_channel_error_existence_ce =
6,452✔
290
        zend_register_internal_class_ex(&ce, php_parallel_channel_error_ce);
3,226✔
291

292
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel\\Error", "IllegalValue", NULL);
3,226✔
293
    php_parallel_channel_error_illegal_value_ce =
6,452✔
294
        zend_register_internal_class_ex(&ce, php_parallel_channel_error_ce);
3,226✔
295

296
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel\\Error", "Closed", NULL);
3,226✔
297
    php_parallel_channel_error_closed_ce =
6,452✔
298
        zend_register_internal_class_ex(&ce, php_parallel_channel_error_ce);
3,226✔
299

300
    /*
301
    * Sync Exceptions
302
    */
303
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Sync", "Error", NULL);
3,226✔
304
    php_parallel_sync_error_ce =
6,452✔
305
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
306

307
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Sync\\Error", "IllegalValue", NULL);
3,226✔
308
    php_parallel_sync_error_illegal_value_ce =
6,452✔
309
        zend_register_internal_class_ex(&ce, php_parallel_sync_error_ce);
3,226✔
310

311
    /*
312
    * Events Exceptions
313
    */
314
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events", "Error", NULL);
3,226✔
315
    php_parallel_events_error_ce =
6,452✔
316
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
317

318
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Error", "Existence", NULL);
3,226✔
319
    php_parallel_events_error_existence_ce =
6,452✔
320
        zend_register_internal_class_ex(&ce, php_parallel_events_error_ce);
3,226✔
321

322
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Error", "Timeout", NULL);
3,226✔
323
    php_parallel_events_error_timeout_ce =
6,452✔
324
        zend_register_internal_class_ex(&ce, php_parallel_events_error_ce);
3,226✔
325

326
    /*
327
    * Input Exceptions
328
    */
329
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Input", "Error", NULL);
3,226✔
330
    php_parallel_events_input_error_ce =
6,452✔
331
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
332

333
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Input\\Error", "Existence", NULL);
3,226✔
334
    php_parallel_events_input_error_existence_ce =
6,452✔
335
        zend_register_internal_class_ex(&ce, php_parallel_events_input_error_ce);
3,226✔
336

337
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Input\\Error", "IllegalValue", NULL);
3,226✔
338
    php_parallel_events_input_error_illegal_value_ce =
6,452✔
339
        zend_register_internal_class_ex(&ce, php_parallel_events_input_error_ce);
3,226✔
340

341
    /*
342
    * Event Exceptions
343
    */
344
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Event", "Error", NULL);
3,226✔
345
    php_parallel_events_event_error_ce =
6,452✔
346
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,226✔
347

348
    return SUCCESS;
3,226✔
349
}
350

351
PHP_MSHUTDOWN_FUNCTION(PARALLEL_EXCEPTIONS)
3,226✔
352
{
353
    return SUCCESS;
3,226✔
354
}
355
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc