Permalink
Browse files

build dmd 2.059

  • Loading branch information...
1 parent b4a29fa commit 54200fc35f2557d24edaa5b00e477b9868b71dd6 @ValeriyBushenev ValeriyBushenev committed Apr 18, 2012
Showing with 223 additions and 22 deletions.
  1. +3 −2 build-libmongod-32bit.sh
  2. +66 −5 export/mongod/bson.di
  3. +20 −1 export/mongod/md5.di
  4. +122 −7 export/mongod/mongo.di
  5. +3 −3 export/mongod/myversion.di
  6. +5 −2 src/mongod/bson.d
  7. +4 −2 src/mongod/mongo.d
@@ -2,8 +2,9 @@ date
rm *.o
rm *.a
git log -1 --pretty=format:"module myversion; public static char[] author=cast(char[])\"%an\"; public static char[] date=cast(char[])\"%ad\"; public static char[] hash=cast(char[])\"%h\";">myversion.d
+echo make libmongod
dmd -m32 -version=D2 myversion.d src/mongod/*.d -Hdexport/mongod -inline -d -release -lib -oflibmongod-D2
-
-dmd -version=D2 -Iexport libmongod-D2.a example/connect.d
+echo make example
+dmd -m32 -version=D2 -Iexport libmongod-D2.a example/connect.d
View
@@ -4,7 +4,7 @@ private import std.c.stdlib;
private import std.c.string;
-private import std.date;
+private import std.datetime;
private import std.c.stdio;
@@ -122,8 +122,33 @@ return cast(char*)b.data;
}
static char hexbyte(char hex);
-void bson_oid_from_string(bson_oid_t* oid, char* str);
-void bson_oid_to_string(bson_oid_t* oid, char* str);
+void bson_oid_from_string(bson_oid_t* oid, char* str)
+{
+int i;
+{
+for (i = 0; i < 12; i++)
+{
+{
+oid.bytes[i] = cast(char)(hexbyte(str[2 * i]) << 4) | hexbyte(str[2 * i + 1]);
+}
+}
+}
+}
+void bson_oid_to_string(bson_oid_t* oid, char* str)
+{
+static char[16] hex = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];
+int i;
+{
+for (i = 0; i < 12; i++)
+{
+{
+str[2 * i] = hex[(oid.bytes[i] & 240) >> 4];
+str[2 * i + 1] = hex[oid.bytes[i] & 15];
+}
+}
+}
+str[24] = '\x00';
+}
void bson_set_oid_fuzz(int function() func)
{
oid_fuzz_func = func;
@@ -132,7 +157,31 @@ void bson_set_oid_inc(int function() func)
{
oid_inc_func = func;
}
-void bson_oid_gen(bson_oid_t* oid);
+void bson_oid_gen(bson_oid_t* oid)
+{
+static int incr = 0;
+static int fuzz = 0;
+int i;
+auto currentTime = Clock.currTime();
+time_t t = currentTime.toUnixTime();
+if (oid_inc_func)
+i = oid_inc_func();
+else
+i = incr++;
+if (!fuzz)
+{
+if (oid_fuzz_func)
+fuzz = oid_fuzz_func();
+else
+{
+srand(t);
+fuzz = rand();
+}
+}
+bson_big_endian32(&oid.ints[0],&t);
+oid.ints[1] = fuzz;
+bson_big_endian32(&oid.ints[2],&i);
+}
time_t bson_oid_generated_time(bson_oid_t* oid)
{
time_t _out;
@@ -220,7 +269,19 @@ int bson_iterator_string_len(bson_iterator* i)
return bson_iterator_int_raw(i);
}
char* bson_iterator_code(bson_iterator* i);
-void bson_iterator_code__scope(bson_iterator* i, bson* _scope);
+void bson_iterator_code__scope(bson_iterator* i, bson* _scope)
+{
+if (bson_iterator_type(i) == bson_type.BSON_CODEWSCOPE)
+{
+int code_len;
+bson_little_endian32(&code_len,bson_iterator_value(i) + 4);
+bson_init_data(_scope,cast(char*)(bson_iterator_value(i) + 8 + code_len));
+}
+else
+{
+bson_empty(_scope);
+}
+}
bson_date_t bson_iterator_date(bson_iterator* i)
{
return bson_iterator_long_raw(i);
View
@@ -176,4 +176,23 @@ pms.abcd[2] = T_MASK ^ 1732584193;
pms.abcd[3] = 271733878;
}
void mongo_md5_append(mongo_md5_state_t* pms, const mongo_md5_byte_t* data, int nbytes);
-void mongo_md5_finish(mongo_md5_state_t* pms, mongo_md5_byte_t[16] digest);
+void mongo_md5_finish(mongo_md5_state_t* pms, mongo_md5_byte_t[16] digest)
+{
+static mongo_md5_byte_t[64] pad = [128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
+mongo_md5_byte_t[8] data;
+int i;
+{
+for (i = 0; i < 8; ++i)
+{
+data[i] = cast(mongo_md5_byte_t)(pms.count[i >> 2] >> ((i & 3) << 3));
+}
+}
+mongo_md5_append(pms,pad.ptr,(55 - (pms.count[0] >> 3) & 63) + 1);
+mongo_md5_append(pms,data.ptr,8);
+{
+for (i = 0; i < 16; ++i)
+{
+digest[i] = cast(mongo_md5_byte_t)(pms.abcd[i >> 2] >> ((i & 3) << 3));
+}
+}
+}
View
@@ -4,7 +4,7 @@ private import std.c.stdlib;
private import std.c.string;
-private import std.date;
+private import std.datetime;
private import std.c.stdio;
@@ -14,6 +14,7 @@ import mongod.bson_h;
import mongod.bson;
import mongod.mongo_h;
import mongod.md5;
+import core.thread;
static int ZERO = 0;
static int ONE = 1;
@@ -80,7 +81,25 @@ mongo_set_socket_op_timeout(conn,millis);
return MONGO_OK;
}
int mongo_check_connection(mongo* conn);
-void mongo_destroy(mongo* conn);
+void mongo_destroy(mongo* conn)
+{
+mongo_disconnect(conn);
+if (conn.replset)
+{
+mongo_replset_free_list(&conn.replset.seeds);
+mongo_replset_free_list(&conn.replset.hosts);
+bson_free(conn.replset.name);
+bson_free(conn.replset);
+conn.replset = null;
+}
+bson_free(conn.primary);
+bson_free(conn.errstr);
+bson_free(conn.lasterrstr);
+conn.err = cast(mongo_error_t)0;
+conn.errstr = null;
+conn.lasterrcode = 0;
+conn.lasterrstr = null;
+}
static int mongo_bson_valid(mongo* conn, bson* bson, int write);
static int mongo_cursor_bson_valid(mongo_cursor* cursor, bson* bson);
@@ -167,7 +186,30 @@ bson_free(ns);
return res;
}
int mongo_simple_int_command(mongo* conn, char* db, char* cmdstr, int arg, bson* realout);
-int mongo_simple_str_command(mongo* conn, char* db, char* cmdstr, char* arg, bson* realout);
+int mongo_simple_str_command(mongo* conn, char* db, char* cmdstr, char* arg, bson* realout)
+{
+bson _out = {null,null};
+int success = 0;
+bson cmd;
+bson_init(&cmd);
+bson_append_string(&cmd,cmdstr,arg);
+bson_finish(&cmd);
+if (mongo_run_command(conn,db,&cmd,&_out) == MONGO_OK)
+{
+bson_iterator it;
+if (bson_find(&it,&_out,cast(char*)"ok"))
+success = bson_iterator_bool(&it);
+}
+bson_destroy(&cmd);
+if (realout)
+*realout = _out;
+else
+bson_destroy(&_out);
+if (success)
+return MONGO_OK;
+else
+return MONGO_ERROR;
+}
int mongo_cmd_drop_db(mongo* conn, char* db)
{
return mongo_simple_int_command(conn,db,cast(char*)"dropDatabase",1,null);
@@ -180,7 +222,37 @@ void mongo_cmd_reset_error(mongo* conn, char* db)
{
mongo_simple_int_command(conn,db,cast(char*)"reseterror",1,null);
}
-static int mongo_cmd_get_error_helper(mongo* conn, char* db, bson* realout, char* cmdtype);
+static int mongo_cmd_get_error_helper(mongo* conn, char* db, bson* realout, char* cmdtype)
+{
+bson _out = {null,null};
+bson_bool_t haserror = 0;
+conn.lasterrcode = 0;
+bson_free(conn.lasterrstr);
+conn.lasterrstr = null;
+if (mongo_simple_int_command(conn,db,cmdtype,1,&_out) == MONGO_OK)
+{
+bson_iterator it;
+haserror = bson_find(&it,&_out,cast(char*)"err") != bson_type.BSON_NULL;
+if (haserror)
+{
+conn.lasterrstr = cast(char*)bson_malloc(bson_iterator_string_len(&it));
+if (conn.lasterrstr)
+{
+strcpy(conn.lasterrstr,bson_iterator_string(&it));
+}
+if (bson_find(&it,&_out,cast(char*)"code") != bson_type.BSON_NULL)
+conn.lasterrcode = bson_iterator_int(&it);
+}
+}
+if (realout)
+*realout = _out;
+else
+bson_destroy(&_out);
+if (haserror)
+return MONGO_ERROR;
+else
+return MONGO_OK;
+}
int mongo_cmd_get_prev_error(mongo* conn, char* db, bson* _out)
{
@@ -190,8 +262,37 @@ int mongo_cmd_get_last_error(mongo* conn, char* db, bson* _out)
{
return mongo_cmd_get_error_helper(conn,db,_out,cast(char*)"getlasterror");
}
-bson_bool_t mongo_cmd_ismaster(mongo* conn, bson* realout);
-static void digest2hex(mongo_md5_byte_t[16] digest, char[33] hex_digest);
+bson_bool_t mongo_cmd_ismaster(mongo* conn, bson* realout)
+{
+bson _out = {null,null};
+bson_bool_t ismaster = 0;
+if (mongo_simple_int_command(conn,cast(char*)"admin",cast(char*)"ismaster",1,&_out) == MONGO_OK)
+{
+bson_iterator it;
+bson_find(&it,&_out,cast(char*)"ismaster");
+ismaster = bson_iterator_bool(&it);
+}
+if (realout)
+*realout = _out;
+else
+bson_destroy(&_out);
+return ismaster;
+}
+static void digest2hex(mongo_md5_byte_t[16] digest, char[33] hex_digest)
+{
+static char[16] hex = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];
+int i;
+{
+for (i = 0; i < 16; i++)
+{
+{
+hex_digest[2 * i] = hex[(digest[i] & 240) >> 4];
+hex_digest[2 * i + 1] = hex[digest[i] & 15];
+}
+}
+}
+hex_digest[32] = '\x00';
+}
static void mongo_pass_digest(char* user, char* pass, char[33] hex_digest)
{
@@ -260,7 +361,21 @@ int mongo_reconnect(mongo* conn);
void mongo_disconnect(mongo* conn);
static void mongo_replset_add_node(mongo_host_port** list, string host, int port);
-void mongo_parse_host(string host_string, mongo_host_port* host_port);
+void mongo_parse_host(string host_string, mongo_host_port* host_port)
+{
+string[] host_port_s = std.string.split(host_string,":");
+if (host_port_s.length == 2)
+{
+host_port.host = host_port_s[0];
+host_port.port = atoi(cast(char*)host_port_s[1]);
+}
+else
+if (host_port_s.length == 1)
+{
+host_port.host = host_string;
+host_port.port = MONGO_DEFAULT_PORT;
+}
+}
void mongo_replset_add_seed(mongo* conn, string host, int port)
{
mongo_replset_add_node(&conn.replset.seeds,host,port);
@@ -1,11 +1,11 @@
// D import file generated from 'myversion.d'
module myversion;
-public static char[] author = cast(char[])"itiu";
+public static char[] author = cast(char[])"Itiu";
-public static char[] date = cast(char[])"Thu Dec 22 21:49:05 2011 +0400";
+public static char[] date = cast(char[])"Wed Jan 18 14:47:42 2012 +0400";
-public static char[] hash = cast(char[])"ddbedad";
+public static char[] hash = cast(char[])"b4a29fa";
View
@@ -2,7 +2,7 @@ module mongod.bson;
private import std.c.stdlib;
private import std.c.string;
-private import std.date;
+private import std.datetime;
private import std.c.stdio;
private import std.stdarg;
@@ -339,7 +339,10 @@ void bson_oid_gen( bson_oid_t *oid ) {
static int incr = 0;
static int fuzz = 0;
int i;
- int t = cast(int) toInteger(getLocalTZA());
+
+ auto currentTime = Clock.currTime();
+
+ time_t t = currentTime.toUnixTime();
if( oid_inc_func )
i = oid_inc_func();
View
@@ -2,7 +2,7 @@ module mongod.mongo;
private import std.c.stdlib;
private import std.c.string;
-private import std.date;
+private import std.datetime;
private import std.c.stdio;
private import std.socket;
@@ -12,6 +12,8 @@ import mongod.bson;
import mongod.mongo_h;
import mongod.md5;
+import core.thread;
+
/* mongo.c */
/* Copyright 2009-2011 10gen Inc.
@@ -1086,7 +1088,7 @@ int mongo_read_response(mongo* conn, mongo_reply** reply, bool retry = false)
} catch(Exception ex)
{
printf("mongo_read_response:fail connect to mongodb, sleep 1s...\n");
- core.thread.Thread.getThis().sleep(10_000_000);
+ Thread.getThis().sleep(10_000_000);
printf("reconnect to mongodb...\n");
if(mongo_reconnect(conn) == MONGO_OK)
{

0 comments on commit 54200fc

Please sign in to comment.