• 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

97.3
/src/runtime.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_RUNTIME
19
#define HAVE_PARALLEL_RUNTIME
20

21
#include "parallel.h"
22

23
zend_class_entry *php_parallel_runtime_ce;
24
zend_object_handlers php_parallel_runtime_handlers;
25

26
php_parallel_runtime_t* php_parallel_runtime_construct(zend_string *bootstrap) {
486✔
27
    zval rt;
486✔
28
    php_parallel_runtime_t *runtime;
486✔
29

30
    object_init_ex(&rt, php_parallel_runtime_ce);
486✔
31

32
    runtime = 
486✔
33
        php_parallel_runtime_from(&rt);
486✔
34

35
    php_parallel_scheduler_start(runtime, bootstrap);
486✔
36

37
    if (!EG(exception)) {
486✔
38
        return runtime;
39
    }
40

41
    zval_ptr_dtor(&rt);
×
UNCOV
42
    return NULL;
×
43
}
44

45
ZEND_BEGIN_ARG_INFO_EX(php_parallel_runtime_construct_arginfo, 0, 0, 0)
46
    ZEND_ARG_TYPE_INFO(0, bootstrap, IS_STRING, 0)
47
ZEND_END_ARG_INFO()
48

49
PHP_METHOD(Parallel_Runtime, __construct)
1,702✔
50
{
51
    php_parallel_runtime_t *runtime = php_parallel_runtime_from(getThis());
1,702✔
52
    zend_string            *bootstrap = NULL;
1,702✔
53

54
    ZEND_PARSE_PARAMETERS_START(0, 1)
1,702✔
55
        Z_PARAM_OPTIONAL
1,702✔
56
        Z_PARAM_STR(bootstrap)
1,966✔
57
    ZEND_PARSE_PARAMETERS_END();
1,702✔
58

59
    php_parallel_scheduler_start(runtime, bootstrap);
1,702✔
60
}
61

62
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(php_parallel_runtime_run_arginfo, 0, 1, \\parallel\\Future, 1)
63
    ZEND_ARG_OBJ_INFO(0, task, Closure, 0)
64
    ZEND_ARG_TYPE_INFO(0, argv, IS_ARRAY, 0)
65
ZEND_END_ARG_INFO()
66

67
PHP_METHOD(Parallel_Runtime, run)
2,072✔
68
{
69
    php_parallel_runtime_t  *runtime = php_parallel_runtime_from(getThis());
2,072✔
70
    zval *closure = NULL;
2,072✔
71
    zval *argv = NULL;
2,072✔
72

73
    ZEND_PARSE_PARAMETERS_START(1, 2)
2,072✔
74
        Z_PARAM_OBJECT_OF_CLASS(closure, zend_ce_closure)
4,144✔
75
        Z_PARAM_OPTIONAL
2,072✔
76
        Z_PARAM_ARRAY(argv)
2,774✔
77
    ZEND_PARSE_PARAMETERS_END();
2,072✔
78

79
    if (php_parallel_monitor_check(runtime->monitor, PHP_PARALLEL_CLOSED)) {
2,072✔
80
        php_parallel_exception_ex(
18✔
81
            php_parallel_runtime_error_closed_ce,
82
            "Runtime closed");
83
        return;
18✔
84
    }
85

86
    php_parallel_scheduler_push(runtime, closure, argv, return_value);
2,054✔
87
}
88

89
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(php_parallel_runtime_close_or_kill_arginfo, 0, 0, IS_VOID, 0)
90
ZEND_END_ARG_INFO()
91

92
PHP_METHOD(Parallel_Runtime, close)
114✔
93
{
94
    php_parallel_runtime_t *runtime =
114✔
95
        php_parallel_runtime_from(getThis());
114✔
96

97
    PARALLEL_PARAMETERS_NONE(return);
114✔
98

99
    php_parallel_scheduler_join(runtime, 0);
114✔
100
}
101

102
PHP_METHOD(Parallel_Runtime, kill)
72✔
103
{
104
    php_parallel_runtime_t *runtime =
72✔
105
        php_parallel_runtime_from(getThis());
72✔
106

107
    PARALLEL_PARAMETERS_NONE(return);
72✔
108

109
    php_parallel_scheduler_join(runtime, 1);
72✔
110
}
111

112
zend_function_entry php_parallel_runtime_methods[] = {
113
    PHP_ME(Parallel_Runtime, __construct, php_parallel_runtime_construct_arginfo, ZEND_ACC_PUBLIC)
114
    PHP_ME(Parallel_Runtime, run, php_parallel_runtime_run_arginfo, ZEND_ACC_PUBLIC)
115
    PHP_ME(Parallel_Runtime, close, php_parallel_runtime_close_or_kill_arginfo, ZEND_ACC_PUBLIC)
116
    PHP_ME(Parallel_Runtime, kill, php_parallel_runtime_close_or_kill_arginfo, ZEND_ACC_PUBLIC)
117
    PHP_FE_END
118
};
119

120
zend_object* php_parallel_runtime_create(zend_class_entry *type) {
2,188✔
121
    php_parallel_runtime_t *runtime = ecalloc(1,
2,188✔
122
            sizeof(php_parallel_runtime_t) + zend_object_properties_size(type));
123

124
    zend_object_std_init(&runtime->std, type);
2,188✔
125

126
    runtime->std.handlers = &php_parallel_runtime_handlers;
2,188✔
127

128
    php_parallel_scheduler_init(runtime);
2,188✔
129

130
    runtime->parent.server = SG(server_context);
2,188✔
131
    runtime->parent.argc = SG(request_info).argc;
2,188✔
132
    runtime->parent.argv = SG(request_info).argv;
2,188✔
133

134
    return &runtime->std;
2,188✔
135
}
136

137
void php_parallel_runtime_destroy(zend_object *o) {
2,188✔
138
    php_parallel_runtime_t *runtime =
2,188✔
139
        php_parallel_runtime_fetch(o);
2,188✔
140

141
    php_parallel_scheduler_stop(runtime);
2,188✔
142

143
    php_parallel_scheduler_destroy(runtime);
2,188✔
144

145
    zend_object_std_dtor(o);
2,188✔
146
}
2,188✔
147

148
PHP_MINIT_FUNCTION(PARALLEL_RUNTIME)
3,226✔
149
{
150
    zend_class_entry ce;
3,226✔
151

152
    memcpy(&php_parallel_runtime_handlers, php_parallel_standard_handlers(), sizeof(zend_object_handlers));
3,226✔
153

154
    php_parallel_runtime_handlers.offset = XtOffsetOf(php_parallel_runtime_t, std);
3,226✔
155
    php_parallel_runtime_handlers.free_obj = php_parallel_runtime_destroy;
3,226✔
156

157
    INIT_NS_CLASS_ENTRY(ce, "parallel", "Runtime", php_parallel_runtime_methods);
3,226✔
158

159
    php_parallel_runtime_ce = zend_register_internal_class(&ce);
3,226✔
160
    php_parallel_runtime_ce->create_object = php_parallel_runtime_create;
3,226✔
161
    php_parallel_runtime_ce->ce_flags |= ZEND_ACC_FINAL;
3,226✔
162

163
    #ifdef ZEND_ACC_NOT_SERIALIZABLE
164
        php_parallel_runtime_ce->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
2,379✔
165
    #else
166
        php_parallel_runtime_ce->serialize = zend_class_serialize_deny;
847✔
167
        php_parallel_runtime_ce->unserialize = zend_class_unserialize_deny;
847✔
168
    #endif
169

170
    PHP_MINIT(PARALLEL_FUTURE)(INIT_FUNC_ARGS_PASSTHRU);
3,226✔
171

172
    return SUCCESS;
3,226✔
173
}
174

175
PHP_MSHUTDOWN_FUNCTION(PARALLEL_RUNTIME)
3,226✔
176
{
177
    PHP_MSHUTDOWN(PARALLEL_FUTURE)(INIT_FUNC_ARGS_PASSTHRU);
3,226✔
178

179
    return SUCCESS;
3,226✔
180
}
181
#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

© 2025 Coveralls, Inc