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

krakjoe / parallel / 20272758286

16 Dec 2025 03:11PM UTC coverage: 96.815%. Remained the same
20272758286

Pull #357

github

web-flow
Merge 771053661 into 14042a874
Pull Request #357: Cleanup code formatting and docs

44 of 48 new or added lines in 6 files covered. (91.67%)

30 existing lines in 11 files now uncovered.

3009 of 3108 relevant lines covered (96.81%)

6860.26 hits per line

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

98.75
/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) {
360✔
75
    zend_property_info *info;
360✔
76
    zend_class_entry *scope = EG(fake_scope);
360✔
77

78
    EG(fake_scope) = zend_ce_error;
360✔
79

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

82
    EG(fake_scope) = scope;
360✔
83

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

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

92
    EG(fake_scope) = zend_ce_error;
432✔
93

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

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

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

102
    ZVAL_COPY_VALUE(slot, value);
432✔
103

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

107
void php_parallel_exceptions_destroy(php_parallel_exception_t *ex) {
72✔
108
    PARALLEL_ZVAL_DTOR(&ex->class);
72✔
109
    PARALLEL_ZVAL_DTOR(&ex->file);
72✔
110
    PARALLEL_ZVAL_DTOR(&ex->line);
72✔
111
    PARALLEL_ZVAL_DTOR(&ex->message);
72✔
112
    PARALLEL_ZVAL_DTOR(&ex->code);
72✔
113
    PARALLEL_ZVAL_DTOR(&ex->trace);
72✔
114
    PARALLEL_ZVAL_DTOR(&ex->previous);
72✔
115

116
    pefree(ex, 1);
72✔
117
}
72✔
118

119
void php_parallel_exceptions_save(zval *saved, zend_object *exception) {
72✔
120
    zval class,
72✔
121
         *file     = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_FILE)),
72✔
122
         *line     = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_LINE)),
72✔
123
         *message  = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_MESSAGE)),
72✔
124
         *code     = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_CODE)),
72✔
125
         *trace    = php_parallel_exceptions_read(exception, ZSTR_KNOWN(ZEND_STR_TRACE)),
72✔
126
         previous;
127

128
    php_parallel_exception_t *ex =
72✔
129
        (php_parallel_exception_t*)
130
            pecalloc(1, sizeof(php_parallel_exception_t), 1);
72✔
131

132
    /* todo */
133
    ZVAL_NULL(&previous);
72✔
134

135
    ZVAL_STR(&class, exception->ce->name);
72✔
136

137
    PARALLEL_ZVAL_COPY(&ex->class,   &class,     1);
72✔
138
    PARALLEL_ZVAL_COPY(&ex->file,    file,       1);
72✔
139
    PARALLEL_ZVAL_COPY(&ex->line,    line,       1);
72✔
140
    PARALLEL_ZVAL_COPY(&ex->message, message,    1);
72✔
141
    PARALLEL_ZVAL_COPY(&ex->code,    code,       1);
72✔
142
    PARALLEL_ZVAL_COPY(&ex->trace,   trace,      1);
72✔
143
    PARALLEL_ZVAL_COPY(&ex->previous, &previous, 1);
72✔
144

145
    ex->handlers = exception->handlers;
72✔
146

147
    ZVAL_PTR(saved, ex);
72✔
148

149
    zend_clear_exception();
72✔
150
}
72✔
151

152
zend_object* php_parallel_exceptions_restore(zval *exception) {
72✔
153
    zend_object      *object;
72✔
154
    zend_class_entry *type;
72✔
155
    zval file, line, message, code, trace, previous;
72✔
156

157
    php_parallel_exception_t *ex =
72✔
158
        (php_parallel_exception_t*) Z_PTR_P(exception);
159

160
    PARALLEL_ZVAL_COPY(&file,     &ex->file,     0);
72✔
161
    PARALLEL_ZVAL_COPY(&line,     &ex->line,     0);
72✔
162
    PARALLEL_ZVAL_COPY(&message,  &ex->message,  0);
72✔
163
    PARALLEL_ZVAL_COPY(&code,     &ex->code,     0);
72✔
164
    PARALLEL_ZVAL_COPY(&trace,    &ex->trace,    0);
72✔
165
    PARALLEL_ZVAL_COPY(&previous, &ex->previous, 0);
72✔
166

167
    type = zend_lookup_class(Z_STR(ex->class));
72✔
168

169
    if (!type) {
72✔
170
        /* we lost type info */
171
        type = php_parallel_future_error_foreign_ce;
×
172
    }
173

174
    object = zend_objects_new(type);
72✔
175
    object->handlers = ex->handlers;
72✔
176
    object_properties_init(object, type);
72✔
177

178
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_FILE),     &file);
72✔
179
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_LINE),     &line);
72✔
180
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_MESSAGE),  &message);
72✔
181
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_CODE),     &code);
72✔
182
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_TRACE),    &trace);
72✔
183
    php_parallel_exceptions_write(object, ZSTR_KNOWN(ZEND_STR_PREVIOUS), &previous);
72✔
184

185
    return object;
72✔
186
}
187

188
PHP_MINIT_FUNCTION(PARALLEL_EXCEPTIONS)
3,168✔
189
{
190
    zend_class_entry ce;
3,168✔
191

192
    /*
193
    * Base Exceptions
194
    */
195
    INIT_NS_CLASS_ENTRY(ce, "parallel", "Error", NULL);
3,168✔
196
    php_parallel_error_ce =
6,336✔
197
        zend_register_internal_class_ex(&ce, zend_ce_error);
3,168✔
198

199
    /*
200
    * Runtime Exceptions
201
    */
202
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime", "Error", NULL);
3,168✔
203
    php_parallel_runtime_error_ce =
6,336✔
204
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
205

206
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "Bootstrap", NULL);
3,168✔
207
    php_parallel_runtime_error_bootstrap_ce =
6,336✔
208
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
209

210
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "Closed", NULL);
3,168✔
211
    php_parallel_runtime_error_closed_ce =
6,336✔
212
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
213

214
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "Killed", NULL);
3,168✔
215
    php_parallel_runtime_error_killed_ce =
6,336✔
216
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
217

218
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalFunction", NULL);
3,168✔
219
    php_parallel_runtime_error_illegal_function_ce =
6,336✔
220
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
221

222
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalVariable", NULL);
3,168✔
223
    php_parallel_runtime_error_illegal_variable_ce =
6,336✔
224
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
225

226
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalParameter", NULL);
3,168✔
227
    php_parallel_runtime_error_illegal_parameter_ce =
6,336✔
228
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
229

230
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalInstruction", NULL);
3,168✔
231
    php_parallel_runtime_error_illegal_instruction_ce =
6,336✔
232
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
233

234
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalReturn", NULL);
3,168✔
235
    php_parallel_runtime_error_illegal_return_ce =
6,336✔
236
        zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
237

238
    /*
239
    * Future Exceptions
240
    */
241
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future", "Error", NULL);
3,168✔
242
    php_parallel_future_error_ce =
6,336✔
243
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
244

245
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future\\Error", "Killed", NULL);
3,168✔
246
    php_parallel_future_error_killed_ce =
6,336✔
247
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
248

249
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future\\Error", "Cancelled", NULL);
3,168✔
250
    php_parallel_future_error_cancelled_ce =
6,336✔
251
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
252

253
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future\\Error", "Foreign", NULL);
3,168✔
254
    php_parallel_future_error_foreign_ce =
6,336✔
255
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
256

257
    /*
258
    * Channel Exceptions
259
    */
260
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel", "Error", NULL);
3,168✔
261
    php_parallel_channel_error_ce =
6,336✔
262
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
263

264
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel\\Error", "Existence", NULL);
3,168✔
265
    php_parallel_channel_error_existence_ce =
6,336✔
266
        zend_register_internal_class_ex(&ce, php_parallel_channel_error_ce);
3,168✔
267

268
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel\\Error", "IllegalValue", NULL);
3,168✔
269
    php_parallel_channel_error_illegal_value_ce =
6,336✔
270
        zend_register_internal_class_ex(&ce, php_parallel_channel_error_ce);
3,168✔
271

272
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel\\Error", "Closed", NULL);
3,168✔
273
    php_parallel_channel_error_closed_ce =
6,336✔
274
        zend_register_internal_class_ex(&ce, php_parallel_channel_error_ce);
3,168✔
275

276
    /*
277
    * Sync Exceptions
278
    */
279
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Sync", "Error", NULL);
3,168✔
280
    php_parallel_sync_error_ce =
6,336✔
281
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
282

283
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Sync\\Error", "IllegalValue", NULL);
3,168✔
284
    php_parallel_sync_error_illegal_value_ce =
6,336✔
285
        zend_register_internal_class_ex(&ce, php_parallel_sync_error_ce);
3,168✔
286

287
    /*
288
    * Events Exceptions
289
    */
290
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events", "Error", NULL);
3,168✔
291
    php_parallel_events_error_ce =
6,336✔
292
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
293

294
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Error", "Existence", NULL);
3,168✔
295
    php_parallel_events_error_existence_ce =
6,336✔
296
        zend_register_internal_class_ex(&ce, php_parallel_events_error_ce);
3,168✔
297

298
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Error", "Timeout", NULL);
3,168✔
299
    php_parallel_events_error_timeout_ce =
6,336✔
300
        zend_register_internal_class_ex(&ce, php_parallel_events_error_ce);
3,168✔
301

302
    /*
303
    * Input Exceptions
304
    */
305
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Input", "Error", NULL);
3,168✔
306
    php_parallel_events_input_error_ce =
6,336✔
307
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
308

309
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Input\\Error", "Existence", NULL);
3,168✔
310
    php_parallel_events_input_error_existence_ce =
6,336✔
311
        zend_register_internal_class_ex(&ce, php_parallel_events_input_error_ce);
3,168✔
312

313
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Input\\Error", "IllegalValue", NULL);
3,168✔
314
    php_parallel_events_input_error_illegal_value_ce =
6,336✔
315
        zend_register_internal_class_ex(&ce, php_parallel_events_input_error_ce);
3,168✔
316

317
    /*
318
    * Event Exceptions
319
    */
320
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Event", "Error", NULL);
3,168✔
321
    php_parallel_events_event_error_ce =
6,336✔
322
        zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
323

324
    return SUCCESS;
3,168✔
325
}
326

327
PHP_MSHUTDOWN_FUNCTION(PARALLEL_EXCEPTIONS)
3,168✔
328
{
329
    return SUCCESS;
3,168✔
330
}
331
#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