Skip to content

Commit

Permalink
windows build MINOR
Browse files Browse the repository at this point in the history
  • Loading branch information
U-ACER-6E40E97492\Kristina Chodorow authored and U-ACER-6E40E97492\Kristina Chodorow committed Jun 29, 2009
1 parent 27f9aeb commit b6a5117
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 29 deletions.
12 changes: 5 additions & 7 deletions bson.c
Expand Up @@ -57,12 +57,8 @@ static int prep_obj_for_db(buffer *buf, zval *array TSRMLS_DC) {

// serialize a zval
int zval_to_bson(buffer *buf, zval *zhash, int prep TSRMLS_DC) {
zval **data;
char *key, *field_name;
uint key_len, start;
ulong index;
HashPosition pointer;
int num = 0, key_type;
uint start;
int num = 0;
HashTable *arr_hash = Z_ARRVAL_P(zhash);

// check buf size
Expand Down Expand Up @@ -178,7 +174,9 @@ int serialize_element(char *name, zval **data, buffer *buf, int prep TSRMLS_DC)
set_type(buf, BSON_OID);
serialize_string(buf, name, name_len);
id = (mongo_id*)zend_object_store_get_object(*data TSRMLS_CC);
MONGO_CHECK_INITIALIZED(id->id, MongoId);
if (!id->id) {
return ZEND_HASH_APPLY_KEEP;
}

serialize_bytes(buf, id->id, OID_SIZE);
}
Expand Down
3 changes: 2 additions & 1 deletion config.w32
Expand Up @@ -4,8 +4,9 @@
ARG_ENABLE("mongo", "MongoDB support", "no");

if (PHP_MONGO != "no") {
EXTENSION('mongo', 'mongo.c mongo_types.c bson.c cursor.c collection.c db.c util.c gridfs.c');
EXTENSION('mongo', 'mongo.c mongo_types.c bson.c cursor.c collection.c db.c gridfs.c');

AC_DEFINE('HAVE_MONGO', 1);
ADD_EXTENSION_DEP('mongo', 'spl', true);
ADD_EXTENSION_DEP('mongo', 'date', true);
}
5 changes: 4 additions & 1 deletion db.c
Expand Up @@ -429,6 +429,9 @@ PHP_METHOD(MongoDB, execute) {

code = obj;
}
else {
zval_add_ref(&code);
}

// create { $eval : code, args : [] }
MAKE_STD_ZVAL(zdata);
Expand Down Expand Up @@ -501,7 +504,7 @@ PHP_METHOD(MongoDB, command) {

// limit
Z_TYPE(limit) = IS_LONG;
Z_LVAL(limit) = 1;
Z_LVAL(limit) = -1;

PUSH_PARAM(&limit); PUSH_PARAM((void*)1);
PUSH_EO_PARAM();
Expand Down
18 changes: 9 additions & 9 deletions gridfs.c
Expand Up @@ -225,7 +225,7 @@ PHP_METHOD(MongoGridFS, storeBytes) {

zval temp;
zval *extra = 0, *zid = 0, *zfile = 0, *chunks = 0;
zval **zzid = 0, **zchunk_size;
zval **zzid = 0;

mongo_collection *c = (mongo_collection*)zend_object_store_get_object(getThis() TSRMLS_CC);
MONGO_CHECK_INITIALIZED(c->ns, MongoGridFS);
Expand Down Expand Up @@ -331,7 +331,7 @@ PHP_METHOD(MongoGridFS, storeFile) {

zval temp;
zval *extra = 0, *zid = 0, *zfile = 0, *chunks = 0, *upload_date = 0;
zval **zzid = 0, **md5 = 0, **zchunk_size;
zval **zzid = 0, **md5 = 0;

mongo_collection *c = (mongo_collection*)zend_object_store_get_object(getThis() TSRMLS_CC);
MONGO_CHECK_INITIALIZED(c->ns, MongoGridFS);
Expand Down Expand Up @@ -483,11 +483,9 @@ PHP_METHOD(MongoGridFS, storeFile) {
// cleanup
if (created_id) {
zend_objects_store_del_ref(zid TSRMLS_CC);
zval_ptr_dtor(&zid);
}
if (created_date) {
zend_objects_store_del_ref(upload_date TSRMLS_CC);
zval_ptr_dtor(&upload_date);
}
zval_ptr_dtor(&zfile);
}
Expand Down Expand Up @@ -714,7 +712,7 @@ PHP_METHOD(MongoGridFSFile, getSize) {
PHP_METHOD(MongoGridFSFile, write) {
char *filename = 0;
int filename_len, total = 0;
zval *gridfs, *file, *chunks, *n, *query, *cursor, *sort, *next;
zval *gridfs, *file, *chunks, *n, *query, *cursor, *sort;
zval **id;
FILE *fp;

Expand Down Expand Up @@ -794,7 +792,7 @@ PHP_METHOD(MongoGridFSFile, write) {

PHP_METHOD(MongoGridFSFile, getBytes) {
zval temp;
zval *file, *gridfs, *chunks, *n, *query, *cursor, *sort, *next;
zval *file, *gridfs, *chunks, *n, *query, *cursor, *sort;
zval **id, **size;
char *str, *str_ptr;
int len;
Expand Down Expand Up @@ -848,7 +846,7 @@ PHP_METHOD(MongoGridFSFile, getBytes) {
POP_PARAM(); POP_PARAM();

if (Z_TYPE_PP(size) == IS_DOUBLE) {
len = Z_DVAL_PP(size);
len = (int)Z_DVAL_PP(size);
}
else { // if Z_TYPE_PP(size) == IS_LONG
len = Z_LVAL_PP(size);
Expand All @@ -871,8 +869,10 @@ PHP_METHOD(MongoGridFSFile, getBytes) {
}

static int copy_bytes(void *to, char *from, int len) {
memcpy(to, from, len);
to += len;
char *winIsDumb = (char*)to;
memcpy(winIsDumb, from, len);
winIsDumb += len;
to = (void*)winIsDumb;

return len;
}
Expand Down
14 changes: 14 additions & 0 deletions mongo.c
Expand Up @@ -1084,7 +1084,11 @@ int get_reply(mongo_cursor *cursor TSRMLS_DC) {

// if this fails, we might be disconnected... but we're probably
// just out of results
#ifdef WIN32
if (recv(sock, &cursor->header.length, INT_32, FLAGS) == FAILURE) {
#else
if (read(sock, &cursor->header.length, INT_32) == FAILURE) {
#endif
return FAILURE;
}

Expand All @@ -1095,13 +1099,23 @@ int get_reply(mongo_cursor *cursor TSRMLS_DC) {
return FAILURE;
}

#ifdef WIN32
recv(sock, &cursor->header.request_id, INT_32, FLAGS);
recv(sock, &cursor->header.response_to, INT_32, FLAGS);
recv(sock, &cursor->header.op, INT_32, FLAGS);
recv(sock, &cursor->flag, INT_32, FLAGS);
recv(sock, &cursor->cursor_id, INT_64, FLAGS);
recv(sock, &cursor->start, INT_32, FLAGS);
recv(sock, &num_returned, INT_32, FLAGS);
#else
read(sock, &cursor->header.request_id, INT_32);
read(sock, &cursor->header.response_to, INT_32);
read(sock, &cursor->header.op, INT_32);
read(sock, &cursor->flag, INT_32);
read(sock, &cursor->cursor_id, INT_64);
read(sock, &cursor->start, INT_32);
read(sock, &num_returned, INT_32);
#endif

// create buf
cursor->header.length -= INT_32*9;
Expand Down
17 changes: 7 additions & 10 deletions mongo_types.c
Expand Up @@ -78,7 +78,7 @@ int mongo_mongo_id_serialize(zval *struc, unsigned char **serialized_data, zend_
return SUCCESS;
}

int mongo_mongo_id_unserialize(zval **rval, zend_class_entry *ce, const unsigned char* p, long datalen, zend_unserialize_data* var_hash TSRMLS_DC) {
int mongo_mongo_id_unserialize(zval **rval, zend_class_entry *ce, const unsigned char* p, zend_uint datalen, zend_unserialize_data* var_hash TSRMLS_DC) {
zval temp;
zval str;

Expand Down Expand Up @@ -223,25 +223,24 @@ PHP_METHOD(MongoId, __toString) {
*/
PHP_METHOD(MongoDate, __construct) {
zval *arg = 0;
struct timeval time;
int sec, usec = 0;
int usec = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zl", &arg, &usec) == FAILURE) {
return;
}

if (!arg) {
#ifdef WIN32
SYSTEMTIME systime;
GetSystemTime(&systime);
time.tv_sec = systime.wSecond;
time.tv_usec = systime.wMilliseconds * 1000;
time_t sec = time(0);
add_property_long(getThis(), "sec", sec);
add_property_long(getThis(), "usec", 0);
#else
struct timeval time;
gettimeofday(&time, NULL);
#endif

add_property_long(getThis(), "sec", time.tv_sec);
add_property_long(getThis(), "usec", time.tv_usec);
#endif
}
else if (Z_TYPE_P(arg) == IS_LONG) {
add_property_long(getThis(), "sec", Z_LVAL_P(arg));
Expand Down Expand Up @@ -537,8 +536,6 @@ PHP_METHOD(MongoDBRef, isRef) {
/* {{{ MongoDBRef::get()
*/
PHP_METHOD(MongoDBRef, get) {
char *c_name;
zval name;
zval *db, *ref, *collection, *query;
zval **ns, **id;

Expand Down
2 changes: 1 addition & 1 deletion mongo_types.h
Expand Up @@ -38,7 +38,7 @@ PHP_METHOD(MongoId, __construct);
PHP_METHOD(MongoId, __toString);

int mongo_mongo_id_serialize(zval*, unsigned char**, zend_uint*, zend_serialize_data* TSRMLS_DC);
int mongo_mongo_id_unserialize(zval**, zend_class_entry*, const unsigned char*, long, zend_unserialize_data* TSRMLS_DC);
int mongo_mongo_id_unserialize(zval**, zend_class_entry*, const unsigned char*, zend_uint, zend_unserialize_data* TSRMLS_DC);

PHP_METHOD(MongoRegex, __construct);
PHP_METHOD(MongoRegex, __toString);
Expand Down

0 comments on commit b6a5117

Please sign in to comment.