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

krakjoe / parallel / 20273776347

16 Dec 2025 03:42PM UTC coverage: 96.75% (-0.07%) from 96.815%
20273776347

Pull #357

github

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

1527 of 1615 new or added lines in 27 files covered. (94.55%)

1 existing line in 1 file now uncovered.

2798 of 2892 relevant lines covered (96.75%)

6599.16 hits per line

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

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

79
    EG(fake_scope) = zend_ce_error;
360✔
80

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

83
    EG(fake_scope) = scope;
360✔
84

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

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

94
    EG(fake_scope) = zend_ce_error;
432✔
95

96
    info = zend_get_property_info(zend_ce_error, property, 1);
864✔
97

98
    slot = OBJ_PROP(exception, info->offset);
432✔
99

100
    if (Z_REFCOUNTED_P(slot)) {
432✔
NEW
101
        zval_ptr_dtor(slot);
×
102
    }
103

104
    ZVAL_COPY_VALUE(slot, value);
432✔
105

106
    EG(fake_scope) = scope;
432✔
107
}
108

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

119
    pefree(ex, 1);
72✔
120
}
72✔
121

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

130
    php_parallel_exception_t *ex = (php_parallel_exception_t *)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
{
154
    zend_object *object;
72✔
155
    zend_class_entry *type;
72✔
156
    zval file, line, message, code, trace, previous;
72✔
157

158
    php_parallel_exception_t *ex = (php_parallel_exception_t *)Z_PTR_P(exception);
72✔
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 */
NEW
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 = zend_register_internal_class_ex(&ce, zend_ce_error);
3,168✔
197

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

204
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "Bootstrap", NULL);
3,168✔
205
    php_parallel_runtime_error_bootstrap_ce = zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
206

207
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "Closed", NULL);
3,168✔
208
    php_parallel_runtime_error_closed_ce = zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
209

210
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "Killed", NULL);
3,168✔
211
    php_parallel_runtime_error_killed_ce = zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
212

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

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

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

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

229
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Runtime\\Error", "IllegalReturn", NULL);
3,168✔
230
    php_parallel_runtime_error_illegal_return_ce = zend_register_internal_class_ex(&ce, php_parallel_runtime_error_ce);
3,168✔
231

232
    /*
233
     * Future Exceptions
234
     */
235
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future", "Error", NULL);
3,168✔
236
    php_parallel_future_error_ce = zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
237

238
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future\\Error", "Killed", NULL);
3,168✔
239
    php_parallel_future_error_killed_ce = zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
240

241
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future\\Error", "Cancelled", NULL);
3,168✔
242
    php_parallel_future_error_cancelled_ce = zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
243

244
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Future\\Error", "Foreign", NULL);
3,168✔
245
    php_parallel_future_error_foreign_ce = zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
246

247
    /*
248
     * Channel Exceptions
249
     */
250
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel", "Error", NULL);
3,168✔
251
    php_parallel_channel_error_ce = zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
252

253
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel\\Error", "Existence", NULL);
3,168✔
254
    php_parallel_channel_error_existence_ce = zend_register_internal_class_ex(&ce, php_parallel_channel_error_ce);
3,168✔
255

256
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel\\Error", "IllegalValue", NULL);
3,168✔
257
    php_parallel_channel_error_illegal_value_ce = zend_register_internal_class_ex(&ce, php_parallel_channel_error_ce);
3,168✔
258

259
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Channel\\Error", "Closed", NULL);
3,168✔
260
    php_parallel_channel_error_closed_ce = zend_register_internal_class_ex(&ce, php_parallel_channel_error_ce);
3,168✔
261

262
    /*
263
     * Sync Exceptions
264
     */
265
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Sync", "Error", NULL);
3,168✔
266
    php_parallel_sync_error_ce = zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
267

268
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Sync\\Error", "IllegalValue", NULL);
3,168✔
269
    php_parallel_sync_error_illegal_value_ce = zend_register_internal_class_ex(&ce, php_parallel_sync_error_ce);
3,168✔
270

271
    /*
272
     * Events Exceptions
273
     */
274
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events", "Error", NULL);
3,168✔
275
    php_parallel_events_error_ce = zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
276

277
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Error", "Existence", NULL);
3,168✔
278
    php_parallel_events_error_existence_ce = zend_register_internal_class_ex(&ce, php_parallel_events_error_ce);
3,168✔
279

280
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Error", "Timeout", NULL);
3,168✔
281
    php_parallel_events_error_timeout_ce = zend_register_internal_class_ex(&ce, php_parallel_events_error_ce);
3,168✔
282

283
    /*
284
     * Input Exceptions
285
     */
286
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Input", "Error", NULL);
3,168✔
287
    php_parallel_events_input_error_ce = zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
288

289
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Input\\Error", "Existence", NULL);
3,168✔
290
    php_parallel_events_input_error_existence_ce =
6,336✔
291
        zend_register_internal_class_ex(&ce, php_parallel_events_input_error_ce);
3,168✔
292

293
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Input\\Error", "IllegalValue", NULL);
3,168✔
294
    php_parallel_events_input_error_illegal_value_ce =
6,336✔
295
        zend_register_internal_class_ex(&ce, php_parallel_events_input_error_ce);
3,168✔
296

297
    /*
298
     * Event Exceptions
299
     */
300
    INIT_NS_CLASS_ENTRY(ce, "parallel\\Events\\Event", "Error", NULL);
3,168✔
301
    php_parallel_events_event_error_ce = zend_register_internal_class_ex(&ce, php_parallel_error_ce);
3,168✔
302

303
    return SUCCESS;
3,168✔
304
}
305

306
PHP_MSHUTDOWN_FUNCTION(PARALLEL_EXCEPTIONS) { return SUCCESS; }
3,168✔
307
#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