Skip to content

Commit

Permalink
Extend mongotcl_cursorObjectObjCmd to require a namespace and perform…
Browse files Browse the repository at this point in the history
… 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:
  • Loading branch information
lehenbauer committed Feb 13, 2014
1 parent cb0340d commit ef5250c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions generic/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions generic/mongotcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion generic/mongotcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit ef5250c

Please sign in to comment.