From 128d6ecc72ba0420891f4254a1cdebacae557eed Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Thu, 13 Feb 2014 22:29:39 +0000 Subject: [PATCH] Initialize cursor_magic field when creating cursor clientData structures. In the yet-unused mongotcl_cmdNameObjToCursor, make sure the error message gets set if the command object lookup fails. Extend README.md with more examples. BUGZID: --- README.md | 16 +++++++++++++++- generic/cursor.c | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd1cf8e..9570bf7 100755 --- a/README.md +++ b/README.md @@ -353,4 +353,18 @@ To build the same index in the bacground, append the '''background''' option to ```tcl $mongo create_index daystream.controlstream $keyBson $bsonResult background -`` +``` + +* search + +This is a little gross and is going to be simplified, but... + +```tcl + + set cursor [$mongo cursor #auto daystream.controlstream] + + $cursor next + + $cursor to_list + + diff --git a/generic/cursor.c b/generic/cursor.c index db57946..7620a0c 100644 --- a/generic/cursor.c +++ b/generic/cursor.c @@ -103,10 +103,11 @@ mongotcl_cmdNameObjToCursor (Tcl_Interp *interp, Tcl_Obj *commandNameObj, mongo_ Tcl_CmdInfo cmdInfo; if (!Tcl_GetCommandInfo (interp, Tcl_GetString(commandNameObj), &cmdInfo)) { - return TCL_ERROR; + goto lookup_error; } if (cmdInfo.objClientData == NULL || ((mongotcl_cursorClientData *)cmdInfo.objClientData)->cursor_magic != MONGOTCL_CURSOR_MAGIC) { + lookup_error: Tcl_AppendResult (interp, "Error: '", Tcl_GetString (commandNameObj), "' is not a mongo cursor object", NULL); return TCL_ERROR; } @@ -387,6 +388,7 @@ mongotcl_createCursorObjCmd(Tcl_Interp *interp, mongo *conn, char *commandName, mc->interp = interp; mc->conn = conn; mc->cursor = (mongo_cursor *)ckalloc(sizeof(mongo_cursor)); + mc->cursor_magic = MONGOTCL_CURSOR_MAGIC; mongo_cursor_init (mc->cursor, conn, namespace);