From b6a5117e5bf615c3bbd60c2b3a9334eb29449b9b Mon Sep 17 00:00:00 2001 From: "U-ACER-6E40E97492\\Kristina Chodorow" Date: Mon, 29 Jun 2009 09:44:09 -0400 Subject: [PATCH] windows build MINOR --- bson.c | 12 +++++------- config.w32 | 3 ++- db.c | 5 ++++- gridfs.c | 18 +++++++++--------- mongo.c | 14 ++++++++++++++ mongo_types.c | 17 +++++++---------- mongo_types.h | 2 +- 7 files changed, 42 insertions(+), 29 deletions(-) diff --git a/bson.c b/bson.c index 38c69dfa7..470c55c7d 100644 --- a/bson.c +++ b/bson.c @@ -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 @@ -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); } diff --git a/config.w32 b/config.w32 index 7d86056ef..d16e35c95 100755 --- a/config.w32 +++ b/config.w32 @@ -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); } diff --git a/db.c b/db.c index f6b0bcd3a..b32882230 100644 --- a/db.c +++ b/db.c @@ -429,6 +429,9 @@ PHP_METHOD(MongoDB, execute) { code = obj; } + else { + zval_add_ref(&code); + } // create { $eval : code, args : [] } MAKE_STD_ZVAL(zdata); @@ -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(); diff --git a/gridfs.c b/gridfs.c index fa3daa0b4..d81d07681 100644 --- a/gridfs.c +++ b/gridfs.c @@ -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); @@ -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); @@ -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); } @@ -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; @@ -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; @@ -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); @@ -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; } diff --git a/mongo.c b/mongo.c index 128bc152f..499c9fd2d 100644 --- a/mongo.c +++ b/mongo.c @@ -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; } @@ -1095,6 +1099,15 @@ 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); @@ -1102,6 +1115,7 @@ int get_reply(mongo_cursor *cursor TSRMLS_DC) { 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; diff --git a/mongo_types.c b/mongo_types.c index 97090e029..8c5248645 100644 --- a/mongo_types.c +++ b/mongo_types.c @@ -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; @@ -223,8 +223,7 @@ 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; @@ -232,16 +231,16 @@ PHP_METHOD(MongoDate, __construct) { 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)); @@ -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; diff --git a/mongo_types.h b/mongo_types.h index 8dd0a730d..2076afaa6 100644 --- a/mongo_types.h +++ b/mongo_types.h @@ -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);