Permalink
Browse files

Explicit returns and clean up command

  • Loading branch information...
1 parent 1c1e2b6 commit 14c08338909e5b30a1db0b15c2f94b2058cfb31d @joshuaclayton committed Mar 23, 2011
Showing with 10 additions and 9 deletions.
  1. +2 −1 ext/faststep/bson_ruby_conversion.c
  2. +8 −8 ext/faststep/db.c
@@ -28,7 +28,7 @@ bson* bson_from_ruby_array(const VALUE array) {
}
}
- create_bson_from_ruby_hash(hash);
+ return create_bson_from_ruby_hash(hash);
}
VALUE ruby_array_to_bson_ordered_hash(const VALUE array) {
@@ -53,6 +53,7 @@ VALUE ensure_document_ok(const VALUE document) {
if(rb_funcall(rb_mFaststepSupport, rb_intern("ok?"), 1, document) == Qfalse) {
rb_raise(rb_eFaststepOperationFailure, _invalid_command_description(document));
}
+ return Qtrue;
}
static char* _invalid_command_description(const VALUE document) {
View
@@ -34,22 +34,22 @@ static VALUE faststep_db_drop(VALUE self) {
}
static VALUE faststep_db_command(VALUE self, VALUE command) {
- mongo_connection* conn = GetFaststepConnection(rb_iv_get(self, "@connection"));
-
- bson* result = (bson*)bson_malloc(sizeof(bson));
- bson_init(result, "", 1);
-
+ bson* result = (bson*)bson_malloc(sizeof(bson));
bson* bson_command = create_bson_from_ruby_hash(command);
char ns[500] = "";
build_collection_ns(ns, RSTRING_PTR(rb_iv_get(self, "@name")), "$cmd");
- mongo_find_one(conn, ns, bson_command, NULL, result);
-
- bson_destroy(bson_command);
+ mongo_find_one(GetFaststepConnection(rb_iv_get(self, "@connection")),
+ ns,
+ bson_command,
+ NULL,
+ result);
VALUE hash = ruby_hash_from_bson(result);
+
bson_destroy(result);
+ bson_destroy(bson_command);
ensure_document_ok(hash);

0 comments on commit 14c0833

Please sign in to comment.