summaryrefslogtreecommitdiffstats
path: root/generic/tclBasic.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2005-05-02 21:45:57 (GMT)
committerdgp <dgp@users.sourceforge.net>2005-05-02 21:45:57 (GMT)
commit76995b15620ca1eecef253001cd60a1a961b6605 (patch)
tree089fa1abfba39fead5b2bd44a7d8c52b56e81967 /generic/tclBasic.c
parentb290d7bf023688cef522986a270daa4cc1bdc4cf (diff)
downloadtcl-76995b15620ca1eecef253001cd60a1a961b6605.zip
tcl-76995b15620ca1eecef253001cd60a1a961b6605.tar.gz
tcl-76995b15620ca1eecef253001cd60a1a961b6605.tar.bz2
* generic/tcl.decls:
* generic/tclBasic.c: Simplified implementation of Tcl_ExprString. * tests/expr-old.test: * generic/tclDecls.h: `make gentstubs`
Diffstat (limited to 'generic/tclBasic.c')
-rw-r--r--generic/tclBasic.c71
1 files changed, 19 insertions, 52 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 8df8d17..d216d2d 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclBasic.c,v 1.147 2005/04/22 15:46:52 dgp Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.148 2005/05/02 21:45:59 dgp Exp $
*/
#include "tclInt.h"
@@ -1801,8 +1801,7 @@ TclInvokeObjectCommand(clientData, interp, argc, argv)
for (i = 0; i < argc; i++) {
length = strlen(argv[i]);
- TclNewObj(objPtr);
- TclInitStringRep(objPtr, argv[i], length);
+ TclNewStringObj(objPtr, argv[i], length);
Tcl_IncrRefCount(objPtr);
objv[i] = objPtr;
}
@@ -4322,61 +4321,29 @@ TclObjInvoke(interp, objc, objv, flags)
*/
int
-Tcl_ExprString(interp, string)
+Tcl_ExprString(interp, exprString)
Tcl_Interp *interp; /* Context in which to evaluate the
* expression. */
- CONST char *string; /* Expression to evaluate. */
+ CONST char *exprString; /* Expression to evaluate. */
{
- register Tcl_Obj *exprPtr;
- Tcl_Obj *resultPtr;
- int length = strlen(string);
- char buf[TCL_DOUBLE_SPACE];
- int result = TCL_OK;
-
- if (length > 0) {
- TclNewObj(exprPtr);
- TclInitStringRep(exprPtr, string, length);
+ int code = TCL_OK;
+ if (exprString[0] == '\0') {
+ /* An empty string. Just set the interpreter's result to 0. */
+ Tcl_SetResult(interp, "0", TCL_VOLATILE);
+ } else {
+ Tcl_Obj *resultPtr, *exprPtr = Tcl_NewStringObj(exprString, -1);
Tcl_IncrRefCount(exprPtr);
-
- result = Tcl_ExprObj(interp, exprPtr, &resultPtr);
- if (result == TCL_OK) {
- /*
- * Set the interpreter's string result from the result object.
- */
-
- if (resultPtr->typePtr == &tclIntType) {
- sprintf(buf, "%ld", resultPtr->internalRep.longValue);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- } else if (resultPtr->typePtr == &tclDoubleType) {
- Tcl_PrintDouble((Tcl_Interp *) NULL,
- resultPtr->internalRep.doubleValue, buf);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- } else {
- /*
- * Set interpreter's string result from the result object.
- */
-
- Tcl_SetResult(interp, TclGetString(resultPtr),
- TCL_VOLATILE);
- }
- Tcl_DecrRefCount(resultPtr); /* discard the result object */
- } else {
- /*
- * Move the interpreter's object result to the string result,
- * then reset the object result.
- */
-
- (void) Tcl_GetStringResult(interp);
+ code = Tcl_ExprObj(interp, exprPtr, &resultPtr);
+ Tcl_DecrRefCount(exprPtr);
+ if (code == TCL_OK) {
+ Tcl_SetObjResult(interp, resultPtr);
+ Tcl_DecrRefCount(resultPtr);
}
- Tcl_DecrRefCount(exprPtr); /* discard the expression object */
- } else {
- /*
- * An empty string. Just set the interpreter's result to 0.
- */
-
- Tcl_SetResult(interp, "0", TCL_VOLATILE);
+
+ /* Force the string rep of the interp result */
+ (void) Tcl_GetStringResult(interp);
}
- return result;
+ return code;
}
/*