From ef5250c2331c9c2f13a9db208b0a5ef1daef6fb3 Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Thu, 13 Feb 2014 19:16:14 +0000 Subject: [PATCH] Extend mongotcl_cursorObjectObjCmd to require a namespace and perform mongo_cursor_init in that function. Make the "cursor" method of the mongo object require a namespace argument and pass that to the aforementioned routine. This prevents coredumps from attempting to do things with an uninitialized cursor. BUGZID: --- generic/cursor.c | 10 ++++++---- generic/mongotcl.c | 8 +++++--- generic/mongotcl.h | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/generic/cursor.c b/generic/cursor.c index 79ce552..3bd705b 100644 --- a/generic/cursor.c +++ b/generic/cursor.c @@ -362,10 +362,10 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_ * * Create a mongo cursor object... * - * mongo_cursor create my_mongo - * mongo_cursor create #auto + * Give it an interp, mongo connection, command name to be + * created, and a MongoDB namespace to be a cursor for * - * The created object is invoked to do things with a MongoDB + * If successful, creates a new Tcl command. * * Results: * A standard Tcl result. @@ -376,7 +376,7 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_ /* ARGSUSED */ int -mongotcl_createCursorObjCmd(Tcl_Interp *interp, mongo *conn, char *commandName) +mongotcl_createCursorObjCmd(Tcl_Interp *interp, mongo *conn, char *commandName, char *namespace) { mongotcl_cursorClientData *mc; int autoGeneratedName; @@ -388,6 +388,8 @@ mongotcl_createCursorObjCmd(Tcl_Interp *interp, mongo *conn, char *commandName) mc->conn = conn; mc->cursor = (mongo_cursor *)ckalloc(sizeof(mongo_cursor)); + mongo_cursor_init (mc->cursor, conn, namespace); + // if commandName is #auto, generate a unique name for the object autoGeneratedName = 0; if (strcmp (commandName, "#auto") == 0) { diff --git a/generic/mongotcl.c b/generic/mongotcl.c index b253a31..9b14e8a 100644 --- a/generic/mongotcl.c +++ b/generic/mongotcl.c @@ -483,15 +483,17 @@ mongotcl_mongoObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_O case OPT_CURSOR: { char *commandName; + char *namespace; - if (objc != 3) { - Tcl_WrongNumArgs (interp, 2, objv, "name"); + if (objc != 4) { + Tcl_WrongNumArgs (interp, 2, objv, "name namespace"); return TCL_ERROR; } commandName = Tcl_GetString(objv[2]); + namespace = Tcl_GetString(objv[3]); - return mongotcl_createCursorObjCmd(interp, md->conn, commandName); + return mongotcl_createCursorObjCmd(interp, md->conn, commandName, namespace); break; } diff --git a/generic/mongotcl.h b/generic/mongotcl.h index 418ec0c..c9dbc25 100644 --- a/generic/mongotcl.h +++ b/generic/mongotcl.h @@ -45,7 +45,7 @@ extern int mongotcl_create_bson_command (Tcl_Interp *interp, char *commandName, CONST bson *bsonObj); extern int -mongotcl_createCursorObjCmd(Tcl_Interp *interp, mongo *conn, char *commandName); ; +mongotcl_createCursorObjCmd(Tcl_Interp *interp, mongo *conn, char *commandName, char *namespace); ; typedef struct mongotcl_clientData {