Skip to content

Commit 658a9dc

Browse files
committed
set backend callback
1 parent 0d1b66f commit 658a9dc

2 files changed

Lines changed: 75 additions & 12 deletions

File tree

backend.c

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
2727
PHPAPI zend_class_entry *git2_backend_class_entry;
2828
static zend_object_handlers git2_backend_object_handlers;
2929

30+
static int php_git2_backend_exists(git_odb_backend *backend, const git_oid *oid)
31+
{
32+
}
33+
static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type)
34+
{
35+
}
36+
static int php_git2_backend_read(void **buffer,size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id)
37+
{
38+
}
39+
static int php_git2_backend_read_header(size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id)
40+
{
41+
}
42+
static int php_git2_backend_read_prefix(git_oid *id,void ** buffer, size_t * size, git_otype * type,struct git_odb_backend * _backend,const git_oid * oid,unsigned int length)
43+
{
44+
}
45+
static void php_git2_backend_free(git_odb_backend *backend)
46+
{
47+
}
48+
3049
static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC)
3150
{
3251
if (object->backend != NULL) {
@@ -39,25 +58,65 @@ static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC)
3958
zend_object_value php_git2_backend_new(zend_class_entry *ce TSRMLS_DC)
4059
{
4160
zend_object_value retval;
61+
php_git2_backend *m_backend;
62+
php_git2_backend_internal *internal;
4263

4364
PHP_GIT2_STD_CREATE_OBJECT(php_git2_backend);
65+
66+
internal = ecalloc(1,sizeof(php_git2_backend_internal));
67+
internal->parent.read = &php_git2_backend_read;
68+
internal->parent.read_prefix = &php_git2_backend_read_prefix;
69+
internal->parent.read_header = &php_git2_backend_read_header;
70+
internal->parent.write = &php_git2_backend_write;
71+
internal->parent.exists = &php_git2_backend_exists;
72+
internal->parent.free = &php_git2_backend_free;
73+
74+
m_backend->backend = internal;
75+
4476
retval.handlers = &git2_backend_object_handlers;
77+
4578
return retval;
4679
}
4780

81+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_read, 0,0,2)
82+
ZEND_ARG_INFO(0, oid)
83+
ZEND_ARG_INFO(0, type)
84+
ZEND_END_ARG_INFO()
85+
86+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_read_prefix, 0,0,2)
87+
ZEND_ARG_INFO(0, oid)
88+
ZEND_ARG_INFO(0, type)
89+
ZEND_END_ARG_INFO()
90+
91+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_read_header, 0,0,2)
92+
ZEND_ARG_INFO(0, oid)
93+
ZEND_ARG_INFO(0, type)
94+
ZEND_END_ARG_INFO()
95+
96+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_write, 0,0,2)
97+
ZEND_ARG_INFO(0, oid)
98+
ZEND_ARG_INFO(0, data)
99+
ZEND_ARG_INFO(0, size)
100+
ZEND_ARG_INFO(0, type)
101+
ZEND_END_ARG_INFO()
102+
103+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_exists, 0,0,1)
104+
ZEND_ARG_INFO(0, oid)
105+
ZEND_END_ARG_INFO()
106+
48107
static zend_function_entry php_git2_backend_methods[] = {
49-
//int (* read)(void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *);
50-
//PHP_ME(git2_backend, read, arginfo_git2_backend_read, ZEND_ACC_PUBLIC)
51-
//int (* read_prefix)(git_oid *,void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *,unsigned int);
52-
//PHP_ME(git2_backend, readPrefix, arginfo_git2_backend_read_prefix, ZEND_ACC_PUBLIC)
53-
//int (* read_header)(size_t *, git_otype *,struct git_odb_backend *,const git_oid *);
54-
//PHP_ME(git2_backend, readHeader, arginfo_git2_backend_read_header, ZEND_ACC_PUBLIC)
55-
//int (* write)(git_oid *,struct git_odb_backend *,const void *,size_t,git_otype);
56-
//PHP_ME(git2_backend, write, arginfo_git2_backend_write, ZEND_ACC_PUBLIC)
57-
//int (* exists)(struct git_odb_backend *,const git_oid *);
58-
//PHP_ME(git2_backend, exists, arginfo_git2_backend_exists, ZEND_ACC_PUBLIC)
59-
//void (* free)(struct git_odb_backend *);
60-
//PHP_ME(git2_backend, free, arginfo_git2_backend_free, ZEND_ACC_PUBLIC)
108+
/* int (* read)(void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *); */
109+
PHP_ABSTRACT_ME(git2_backend, read, arginfo_git2_backend_read)
110+
/* int (* read_prefix)(git_oid *,void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *,unsigned int); */
111+
PHP_ABSTRACT_ME(git2_backend, readPrefix, arginfo_git2_backend_read_prefix)
112+
/* int (* read_header)(size_t *, git_otype *,struct git_odb_backend *,const git_oid *); */
113+
PHP_ABSTRACT_ME(git2_backend, readHeader, arginfo_git2_backend_read_header)
114+
/* int (* write)(git_oid *,struct git_odb_backend *,const void *,size_t,git_otype); */
115+
PHP_ABSTRACT_ME(git2_backend, write, arginfo_git2_backend_write)
116+
/* int (* exists)(struct git_odb_backend *,const git_oid *); */
117+
PHP_ABSTRACT_ME(git2_backend, exists, arginfo_git2_backend_exists)
118+
/* void (* free)(struct git_odb_backend *); */
119+
PHP_ABSTRACT_ME(git2_backend, free, NULL)
61120
{NULL,NULL,NULL}
62121
};
63122

php_git2.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ typedef struct{
151151
git_odb_backend *backend;
152152
} php_git2_backend;
153153

154+
typedef struct{
155+
git_odb_backend parent;
156+
} php_git2_backend_internal;
157+
154158

155159
# define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC);
156160

0 commit comments

Comments
 (0)