summaryrefslogtreecommitdiffstats
path: root/generic
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
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')
-rw-r--r--generic/tcl.decls4
-rw-r--r--generic/tclBasic.c71
-rw-r--r--generic/tclDecls.h6
3 files changed, 24 insertions, 57 deletions
diff --git a/generic/tcl.decls b/generic/tcl.decls
index cd95420..05fe8f9 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -11,7 +11,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: tcl.decls,v 1.108 2005/01/27 00:22:58 andreas_kupries Exp $
+# RCS: @(#) $Id: tcl.decls,v 1.109 2005/05/02 21:45:58 dgp Exp $
library tcl
@@ -509,7 +509,7 @@ declare 141 generic {
Tcl_Obj **resultPtrPtr)
}
declare 142 generic {
- int Tcl_ExprString(Tcl_Interp *interp, CONST char *string)
+ int Tcl_ExprString(Tcl_Interp *interp, CONST char *exprString)
}
declare 143 generic {
void Tcl_Finalize(void)
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;
}
/*
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index 1226d00..6fe3188 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclDecls.h,v 1.110 2005/01/27 00:23:16 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclDecls.h,v 1.111 2005/05/02 21:45:59 dgp Exp $
*/
#ifndef _TCLDECLS
@@ -918,7 +918,7 @@ EXTERN int Tcl_ExprObj _ANSI_ARGS_((Tcl_Interp * interp,
#define Tcl_ExprString_TCL_DECLARED
/* 142 */
EXTERN int Tcl_ExprString _ANSI_ARGS_((Tcl_Interp * interp,
- CONST char * string));
+ CONST char * exprString));
#endif
#ifndef Tcl_Finalize_TCL_DECLARED
#define Tcl_Finalize_TCL_DECLARED
@@ -3626,7 +3626,7 @@ typedef struct TclStubs {
int (*tcl_ExprLong) _ANSI_ARGS_((Tcl_Interp * interp, CONST char * str, long * ptr)); /* 139 */
int (*tcl_ExprLongObj) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_Obj * objPtr, long * ptr)); /* 140 */
int (*tcl_ExprObj) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_Obj * objPtr, Tcl_Obj ** resultPtrPtr)); /* 141 */
- int (*tcl_ExprString) _ANSI_ARGS_((Tcl_Interp * interp, CONST char * string)); /* 142 */
+ int (*tcl_ExprString) _ANSI_ARGS_((Tcl_Interp * interp, CONST char * exprString)); /* 142 */
void (*tcl_Finalize) _ANSI_ARGS_((void)); /* 143 */
void (*tcl_FindExecutable) _ANSI_ARGS_((CONST char * argv0)); /* 144 */
Tcl_HashEntry * (*tcl_FirstHashEntry) _ANSI_ARGS_((Tcl_HashTable * tablePtr, Tcl_HashSearch * searchPtr)); /* 145 */