forked from RogerGee/php-git2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp-closure.cpp
88 lines (68 loc) · 1.79 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
/*
* php-closure.cpp
*
* Copyright (C) Roger P. Gee
*/
#include "php-object.h"
using namespace php_git2;
// Custom class handlers
static int closure_get_closure(zval* obj,
zend_class_entry** ce_ptr,
zend_function** fptr_ptr,
zend_object** obj_ptr);
// 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
int closure_get_closure(zval* obj,
zend_class_entry** ce_ptr,
zend_function** fptr_ptr,
zend_object** obj_ptr)
{
if (Z_TYPE_P(obj) != IS_OBJECT) {
return FAILURE;
}
php_closure_object* closure;
closure = php_zend_object<php_closure_object>::get_storage(obj);
*fptr_ptr = &closure->func;
*ce_ptr = Z_OBJCE_P(obj);
if (obj_ptr) {
*obj_ptr = Z_OBJ_P(obj);
}
return SUCCESS;
}
/*
* Local Variables:
* indent-tabs-mode:nil
* tab-width:4
* End:
*/