Skip to content

Commit

Permalink
Make mongo object is_master method actually work plus not coredump pl…
Browse files Browse the repository at this point in the history
…us make the bson argument optional.

BUGZID:
  • Loading branch information
lehenbauer committed Feb 13, 2014
1 parent e1b69e4 commit dbf785d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
6 changes: 1 addition & 5 deletions generic/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,12 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_
}

case OPT_CURSOR_BSON: {
char *bsonCommandObject;

if (objc != 3) {
Tcl_WrongNumArgs (interp, 2, objv, "bsonName");
return TCL_ERROR;
}

bsonCommandObject = Tcl_GetString (objv[2]);

return mongotcl_cmdNameObjSetBson (interp, bsonCommandObject, mongo_cursor_bson (mc->cursor));
return mongotcl_cmdNameObjSetBson (interp, objv[2], mongo_cursor_bson (mc->cursor));
}

case OPT_CURSOR_NEXT: {
Expand Down
24 changes: 13 additions & 11 deletions generic/mongotcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,24 +820,26 @@ mongotcl_mongoObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_O

case OPT_IS_MASTER: {
bson *bsonResult;
int status = 0;

if (objc != 3) {
Tcl_WrongNumArgs (interp, 1, objv, "is_master bsonResult");
return TCL_ERROR;
}

if (mongotcl_cmdNameObjToBson (interp, objv[3], &bsonResult) == TCL_ERROR) {
Tcl_AddErrorInfo (interp, " while locating bson result object");
if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs (interp, 1, objv, "is_master ?bsonResult?");
return TCL_ERROR;
}


if (mongo_cmd_ismaster (md->conn, bsonResult) == MONGO_OK) {
Tcl_SetObjResult (interp, Tcl_NewIntObj(1));
if (objc == 2) {
status = mongo_cmd_ismaster (md->conn, NULL);
} else {
Tcl_SetObjResult (interp, Tcl_NewIntObj(0));
if (mongotcl_cmdNameObjToBson (interp, objv[2], &bsonResult) == TCL_ERROR) {
Tcl_AddErrorInfo (interp, " while locating bson result object");
return TCL_ERROR;
}

status = mongo_cmd_ismaster (md->conn, bsonResult);
}

Tcl_SetObjResult (interp, Tcl_NewBooleanObj (status));

break;
}

Expand Down

0 comments on commit dbf785d

Please sign in to comment.