diff --git a/generic/cursor.c b/generic/cursor.c index 79ca634..8502102 100644 --- a/generic/cursor.c +++ b/generic/cursor.c @@ -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: { diff --git a/generic/mongotcl.c b/generic/mongotcl.c index 656c453..b253a31 100644 --- a/generic/mongotcl.c +++ b/generic/mongotcl.c @@ -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; }