-
Notifications
You must be signed in to change notification settings - Fork 1
/
php-closure.cpp
106 lines (87 loc) · 2.2 KB
/
php-closure.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* php-closure.cpp
*
* Copyright (C) Roger P. Gee
*/
#include "php-object.h"
using namespace php_git2;
// Custom class handlers
#if PHP_API_VERSION >= 20220829
static zend_result closure_get_closure(
zend_object* obj,
zend_class_entry** ce_ptr,
zend_function** fptr_ptr,
zend_object** obj_ptr,
zend_bool check_only);
#else
static int closure_get_closure(
zend_object* obj,
zend_class_entry** ce_ptr,
zend_function** fptr_ptr,
zend_object** obj_ptr,
zend_bool check_only);
#endif
// Class method entries
zend_function_entry php_git2::closure_methods[] = {
PHP_FE_END
};
// php_zend_object init function
template<>
zend_object_handlers php_git2::php_zend_object<php_closure_object>::handlers;
template<>
void php_zend_object<php_closure_object>::init(zend_class_entry* ce)
{
handlers.get_closure = closure_get_closure;
handlers.get_constructor = php_git2::not_allowed_get_constructor;
handlers.offset = offset();
UNUSED(ce);
}
// Implementation of php_closure_object
php_closure_object::php_closure_object():
payload(nullptr), hasPayload(false), payloadDestructor(nullptr)
{
memset(&func,0,sizeof(zend_function));
}
php_closure_object::~php_closure_object()
{
// NOTE: Currently, the only allocated item from 'func' is the function name
// string.
if (func.common.function_name) {
zend_string_release(func.common.function_name);
}
if (payloadDestructor != nullptr) {
(*payloadDestructor)(payload);
}
}
// Implementation of custom class handlers
#if PHP_API_VERSION >= 20220829
zend_result closure_get_closure(
zend_object* obj,
zend_class_entry** ce_ptr,
zend_function** fptr_ptr,
zend_object** obj_ptr,
zend_bool check_only)
#else
int closure_get_closure(
zend_object* obj,
zend_class_entry** ce_ptr,
zend_function** fptr_ptr,
zend_object** obj_ptr,
zend_bool check_only)
#endif
{
php_closure_object* closure;
closure = php_zend_object<php_closure_object>::get_storage(obj);
*fptr_ptr = &closure->func;
*ce_ptr = obj->ce;
if (obj_ptr) {
*obj_ptr = obj;
}
return SUCCESS;
}
/*
* Local Variables:
* indent-tabs-mode:nil
* tab-width:4
* End:
*/