-
Notifications
You must be signed in to change notification settings - Fork 78
/
php_git2_priv.h
98 lines (87 loc) · 3.52 KB
/
php_git2_priv.h
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
/*
* PHP Libgit2 Extension
*
* https://github.com/libgit2/php-git
*
* Copyright 2014 Shuhei Tanuma. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef PHP_GIT2_PRIV_H
#define PHP_GIT2_PRIV_H
extern int git2_resource_handle;
#if PHP_VERSION_ID>=50399
#define PHP_GIT2_LIST_INSERT(type, handle) zend_list_insert(type, handle TSRMLS_CC)
#else
#define PHP_GIT2_LIST_INSERT(type, handle) zend_list_insert(type, handle)
#endif
# if ZEND_MODULE_API_NO >= 20100525
# define PHP_GIT2_STD_CREATE_OBJECT(STRUCT_NAME) \
STRUCT_NAME *object;\
\
object = (STRUCT_NAME*)ecalloc(1, sizeof(*object));\
zend_object_std_init(&object->zo, ce TSRMLS_CC);\
object_properties_init(&object->zo, ce);\
\
retval.handle = zend_objects_store_put(object,\
(zend_objects_store_dtor_t)zend_objects_destroy_object,\
(zend_objects_free_object_storage_t) STRUCT_NAME##_free_storage ,\
NULL TSRMLS_CC);\
retval.handlers = zend_get_std_object_handlers();
# else
# define PHP_GIT2_STD_CREATE_OBJECT(STRUCT_NAME) \
STRUCT_NAME *object;\
zval *tmp = NULL;\
\
object = (STRUCT_NAME*)ecalloc(1, sizeof(*object));\
zend_object_std_init(&object->zo, ce TSRMLS_CC);\
zend_hash_copy(object->zo.properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); \
\
retval.handle = zend_objects_store_put(object,\
(zend_objects_store_dtor_t)zend_objects_destroy_object,\
(zend_objects_free_object_storage_t) STRUCT_NAME##_free_storage ,\
NULL TSRMLS_CC);\
retval.handlers = zend_get_std_object_handlers();
# endif
#define PHP_GIT2_V(git2, type) git2->v.type
#define GIT2_RVAL_P(git2) git2->resource_id
#define GIT2_SHOULD_FREE(git2) git2->should_free_v
#define PHP_GIT2_MAKE_RESOURCE(val) \
do {\
val = (php_git2_t *)emalloc(sizeof(php_git2_t));\
if (!val) {\
php_error_docref(NULL TSRMLS_CC, E_ERROR, "emalloc failed");\
RETURN_FALSE;\
}\
val->should_free_v = 0;\
val->type = 0;\
val->mutable = 0;\
} while (0);\
#define PHP_GIT2_MAKE_RESOURCE_NOCHECK(val) \
do {\
val = (php_git2_t *)emalloc(sizeof(php_git2_t));\
val->should_free_v = 0;\
val->type = 0;\
val->mutable = 0;\
} while (0);\
#define GIT2_OID_HEXSIZE (GIT_OID_HEXSZ+1)
#define GIT2_BUFFER_SIZE 512
int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC);
#include "helper.h"
#endif