Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed all win32 compile errors #9

Open
wants to merge 5 commits into
base: 82108e67ae805b1416d7f3137510dae38636d915
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions src/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
#include "php_git.h"
#include <spl/spl_array.h>
#include <zend_interfaces.h>
#include <zend_exceptions.h>
#include <string.h>
#include <time.h>

PHPAPI zend_class_entry *git_backend_class_entry;
zend_class_entry *git_backend_class_entry;

ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_read, 0, 0, 1)
ZEND_ARG_INFO(0, key)
Expand Down Expand Up @@ -60,13 +61,14 @@ int php_git_backend__exists(git_odb_backend *_backend, const git_oid *oid)
TSRMLS_FETCH();
php_git_backend_internal *object = (php_git_backend_internal *)_backend;
char out[GIT_OID_HEXSZ+1] = {0};
git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);

zval *retval;
zval *params[1];
zval func;
int result;

git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);

MAKE_STD_ZVAL(retval);
ZVAL_NULL(retval);
ZVAL_STRING(&func,"exists", 1);
Expand Down Expand Up @@ -97,19 +99,22 @@ int php_git_backend__write(git_oid *id, git_odb_backend *_backend, git_rawobj *o
zval *retval;
zval *params[1];
zval func;
php_git_rawobject_t *raw;

MAKE_STD_ZVAL(retval);
ZVAL_NULL(retval);
ZVAL_STRING(&func,"write", 1);


MAKE_STD_ZVAL(params[0]);
object_init_ex(params[0],git_rawobject_class_entry);
object_init_ex(params[0], git_rawobject_class_entry);

add_property_stringl_ex(params[0],"data",sizeof("data"),obj->data,obj->len,1 TSRMLS_CC);
add_property_long(params[0],"type",obj->type);
add_property_long(params[0],"len",obj->len);

php_git_rawobject_t *raw = (php_git_rawobject_t *) zend_object_store_get_object(params[0] TSRMLS_CC);

raw = (php_git_rawobject_t *) zend_object_store_get_object(params[0] TSRMLS_CC);
raw->object = obj;

if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){
Expand All @@ -123,7 +128,7 @@ int php_git_backend__write(git_oid *id, git_odb_backend *_backend, git_rawobj *o
}else{
ret = GIT_ERROR;
}

zval_ptr_dtor(&retval);
//do not free Git\RawObject here.
//zval_ptr_dtor(&params[0]);
Expand All @@ -135,12 +140,14 @@ int php_git_backend__read(git_rawobj *obj, git_odb_backend *_backend, const git_
{
TSRMLS_FETCH();
php_git_backend_internal *object = (php_git_backend_internal *)_backend;
char out[GIT_OID_HEXSZ+1] = {0};
git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
char out[GIT_OID_HEXSZ+1] = {0};

zval *retval;
zval *params[1];
zval func;
zval *str;

git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);

MAKE_STD_ZVAL(retval);
ZVAL_NULL(retval);
Expand All @@ -161,30 +168,32 @@ int php_git_backend__read(git_rawobj *obj, git_odb_backend *_backend, const git_
return GIT_ENOTFOUND;
}

zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC);
str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC);

// do not use ecalloc. obj->data will free by git_rawobject_close()
obj->data = calloc(1,strlen(Z_STRVAL_P(str)));
obj->len = strlen(Z_STRVAL_P(str));
obj->type = GIT_OBJ_BLOB;
memcpy(obj->data, Z_STRVAL_P(str),obj->len);

zval_ptr_dtor(&retval);
zval_ptr_dtor(&params[0]);
zval_dtor(&func);

return GIT_SUCCESS;
}
int php_git_backend__read_header(git_rawobj *obj, git_odb_backend *_backend, const git_oid *oid)
{
TSRMLS_FETCH();
char out[GIT_OID_HEXSZ+1] = {0} ;
php_git_backend_internal *object = (php_git_backend_internal *)_backend;
git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);

zval *retval;
zval *params[1];
zval func;
zval *str;

git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);

MAKE_STD_ZVAL(retval);
ZVAL_NULL(retval);
Expand All @@ -205,20 +214,20 @@ int php_git_backend__read_header(git_rawobj *obj, git_odb_backend *_backend, con
return GIT_ENOTFOUND;
}

zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",sizeof("data"), 0 TSRMLS_CC);
str = zend_read_property(git_rawobject_class_entry, retval,"data",sizeof("data"), 0 TSRMLS_CC);

obj->data = NULL;
obj->len = strlen(Z_STRVAL_P(str));
obj->type = GIT_OBJ_BLOB;

zval_ptr_dtor(&retval);
zval_ptr_dtor(&params[0]);
zval_dtor(&func);

return GIT_SUCCESS;
}

void php_git_backend__free(git_odb_backend *backend)
int php_git_backend__free(git_odb_backend *backend)
{
TSRMLS_FETCH();
php_git_backend_internal *object = (php_git_backend_internal *)backend;
Expand All @@ -239,6 +248,8 @@ void php_git_backend__free(git_odb_backend *backend)

zval_ptr_dtor(&retval);
zval_dtor(&func);

return 1;
}

zend_object_value php_git_backend_new(zend_class_entry *ce TSRMLS_DC)
Expand Down Expand Up @@ -278,7 +289,7 @@ PHP_METHOD(git_backend, __construct)
this->backend = internal;
}

PHPAPI function_entry php_git_backend_methods[] = {
static zend_function_entry php_git_backend_methods[] = {
PHP_ME(git_backend, __construct, NULL, ZEND_ACC_PUBLIC)
PHP_ABSTRACT_ME(git_backend, read, arginfo_git_backend_read)
PHP_ABSTRACT_ME(git_backend, read_header, arginfo_git_backend_read_header)
Expand Down
43 changes: 24 additions & 19 deletions src/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <string.h>
#include <time.h>

PHPAPI zend_class_entry *git_blob_class_entry;
zend_class_entry *git_blob_class_entry;

ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob__construct, 0, 0, 1)
ZEND_ARG_INFO(0, repository)
Expand All @@ -41,46 +41,49 @@ ZEND_END_ARG_INFO()
static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC)
{
zend_object_std_dtor(&obj->zo TSRMLS_CC);

//obj->object will free by git_repository.
obj->object = NULL;
efree(obj);
}

zend_object_value php_git_blob_new(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
php_git_repository_t *obj;
zval *tmp;
zend_object_value retval;
php_git_repository_t *obj;
zval *tmp;

obj = ecalloc(1, sizeof(*obj));
zend_object_std_init( &obj->zo, ce TSRMLS_CC );
zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
obj = ecalloc(1, sizeof(*obj));
zend_object_std_init( &obj->zo, ce TSRMLS_CC );
zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));

retval.handle = zend_objects_store_put(obj,
retval.handle = zend_objects_store_put(obj,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
(zend_objects_free_object_storage_t)php_git_blob_free_storage,
NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
retval.handlers = zend_get_std_object_handlers();

return retval;
return retval;
}



PHP_METHOD(git_blob, __construct)
{
zval *z_repository;
php_git_repository_t *git;
php_git_blob_t *obj;
int ret;

if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"z", &z_repository) == FAILURE){
return;
}

php_git_repository_t *git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC);
php_git_blob_t *obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
int ret = git_blob_new(&obj->object,git->repository);
git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC);
obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);

ret = git_blob_new(&obj->object,git->repository);

if(ret != GIT_SUCCESS){
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Can't create new blob!");
Expand All @@ -93,23 +96,25 @@ PHP_METHOD(git_blob, setContent)
{
char *string;
size_t string_len = 0;
php_git_blob_t *obj;
int ret;

if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s", &string, &string_len) == FAILURE){
return;
}

php_git_blob_t *obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);

int ret = git_blob_set_rawcontent(obj->object,string, string_len);
ret = git_blob_set_rawcontent(obj->object,string, string_len);
if(ret != GIT_SUCCESS){
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Can't set content!");
return;
}
add_property_string_ex(getThis(), "data", sizeof("data"),string, 1 TSRMLS_CC);
}

PHPAPI function_entry php_git_blob_methods[] = {
zend_function_entry php_git_blob_methods[] = {
PHP_ME(git_blob, __construct, arginfo_git_blob__construct, ZEND_ACC_PUBLIC)
PHP_ME(git_blob, setContent, arginfo_git_blob_set_content, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
Expand All @@ -121,6 +126,6 @@ void git_init_blob(TSRMLS_D)
INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Blob", php_git_blob_methods);

git_blob_class_entry = zend_register_internal_class_ex(&ce, git_object_class_entry, NULL TSRMLS_CC);
git_blob_class_entry->create_object = php_git_blob_new;
git_blob_class_entry->create_object = php_git_blob_new;

}
Loading