summaryrefslogtreecommitdiffstats
path: root/generic/tclObj.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2013-04-21 21:01:26 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2013-04-21 21:01:26 (GMT)
commit6d9d2761b86a20a703ff568b0e3054d4136b7f48 (patch)
tree7439f83be43a9633d2d5197d9dc5b1cd4763681c /generic/tclObj.c
parent7ca7838da8f5ead8e4a814213b0d249be9bbe615 (diff)
downloadtcl-6d9d2761b86a20a703ff568b0e3054d4136b7f48.zip
tcl-6d9d2761b86a20a703ff568b0e3054d4136b7f48.tar.gz
tcl-6d9d2761b86a20a703ff568b0e3054d4136b7f48.tar.bz2
Revert part of [bb4707eb077f0cd9], which removed Tcl_NewIntObj, Tcl_SetIntObj, Tcl_NewBooleanObj, Tcl_DbNewBooleanObj and Tcl_SetBooleanObj from the stub table and replaced those by macros. Add those functions back were they were. Reason: the upcoming cygwin64 will change the definition of 'long', I'm not sure any more this was a good idea. More investigation needed before doing something like this in "novem".
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r--generic/tclObj.c235
1 files changed, 229 insertions, 6 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 2cbc6ed..2c156f9 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -1725,6 +1725,144 @@ Tcl_InvalidateStringRep(
/*
*----------------------------------------------------------------------
*
+ * Tcl_NewBooleanObj --
+ *
+ * This function is normally called when not debugging: i.e., when
+ * TCL_MEM_DEBUG is not defined. It creates a new Tcl_Obj and
+ * initializes it from the argument boolean value. A nonzero "boolValue"
+ * is coerced to 1.
+ *
+ * When TCL_MEM_DEBUG is defined, this function just returns the result
+ * of calling the debugging version Tcl_DbNewBooleanObj.
+ *
+ * Results:
+ * The newly created object is returned. This object will have an invalid
+ * string representation. The returned object has ref count 0.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+#undef Tcl_NewBooleanObj
+#ifdef TCL_MEM_DEBUG
+
+Tcl_Obj *
+Tcl_NewBooleanObj(
+ register int boolValue) /* Boolean used to initialize new object. */
+{
+ return Tcl_DbNewBooleanObj(boolValue, "unknown", 0);
+}
+
+#else /* if not TCL_MEM_DEBUG */
+
+Tcl_Obj *
+Tcl_NewBooleanObj(
+ register int boolValue) /* Boolean used to initialize new object. */
+{
+ register Tcl_Obj *objPtr;
+
+ TclNewLongObj(objPtr, boolValue!=0);
+ return objPtr;
+}
+#endif /* TCL_MEM_DEBUG */
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_DbNewBooleanObj --
+ *
+ * This function is normally called when debugging: i.e., when
+ * TCL_MEM_DEBUG is defined. It creates new boolean objects. It is the
+ * same as the Tcl_NewBooleanObj function above except that it calls
+ * Tcl_DbCkalloc directly with the file name and line number from its
+ * caller. This simplifies debugging since then the [memory active]
+ * command will report the correct file name and line number when
+ * reporting objects that haven't been freed.
+ *
+ * When TCL_MEM_DEBUG is not defined, this function just returns the
+ * result of calling Tcl_NewBooleanObj.
+ *
+ * Results:
+ * The newly created object is returned. This object will have an invalid
+ * string representation. The returned object has ref count 0.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+#undef Tcl_DbNewBooleanObj
+#ifdef TCL_MEM_DEBUG
+
+Tcl_Obj *
+Tcl_DbNewBooleanObj(
+ register int boolValue, /* Boolean used to initialize new object. */
+ const char *file, /* The name of the source file calling this
+ * function; used for debugging. */
+ int line) /* Line number in the source file; used for
+ * debugging. */
+{
+ register Tcl_Obj *objPtr;
+
+ TclDbNewObj(objPtr, file, line);
+ objPtr->bytes = NULL;
+
+ objPtr->internalRep.longValue = (boolValue? 1 : 0);
+ objPtr->typePtr = &tclIntType;
+ return objPtr;
+}
+
+#else /* if not TCL_MEM_DEBUG */
+
+Tcl_Obj *
+Tcl_DbNewBooleanObj(
+ register int boolValue, /* Boolean used to initialize new object. */
+ const char *file, /* The name of the source file calling this
+ * function; used for debugging. */
+ int line) /* Line number in the source file; used for
+ * debugging. */
+{
+ return Tcl_NewBooleanObj(boolValue);
+}
+#endif /* TCL_MEM_DEBUG */
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_SetBooleanObj --
+ *
+ * Modify an object to be a boolean object and to have the specified
+ * boolean value. A nonzero "boolValue" is coerced to 1.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The object's old string rep, if any, is freed. Also, any old internal
+ * rep is freed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+#undef Tcl_SetBooleanObj
+void
+Tcl_SetBooleanObj(
+ register Tcl_Obj *objPtr, /* Object whose internal rep to init. */
+ register int boolValue) /* Boolean used to set object's value. */
+{
+ if (Tcl_IsShared(objPtr)) {
+ Tcl_Panic("%s called with shared object", "Tcl_SetBooleanObj");
+ }
+
+ TclSetLongObj(objPtr, boolValue!=0);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_GetBooleanFromObj --
*
* Attempt to return a boolean from the Tcl object "objPtr". This
@@ -2242,6 +2380,90 @@ UpdateStringOfDouble(
/*
*----------------------------------------------------------------------
*
+ * Tcl_NewIntObj --
+ *
+ * If a client is compiled with TCL_MEM_DEBUG defined, calls to
+ * Tcl_NewIntObj to create a new integer object end up calling the
+ * debugging function Tcl_DbNewLongObj instead.
+ *
+ * Otherwise, if the client is compiled without TCL_MEM_DEBUG defined,
+ * calls to Tcl_NewIntObj result in a call to one of the two
+ * Tcl_NewIntObj implementations below. We provide two implementations so
+ * that the Tcl core can be compiled to do memory debugging of the core
+ * even if a client does not request it for itself.
+ *
+ * Integer and long integer objects share the same "integer" type
+ * implementation. We store all integers as longs and Tcl_GetIntFromObj
+ * checks whether the current value of the long can be represented by an
+ * int.
+ *
+ * Results:
+ * The newly created object is returned. This object will have an invalid
+ * string representation. The returned object has ref count 0.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+#undef Tcl_NewIntObj
+#ifdef TCL_MEM_DEBUG
+
+Tcl_Obj *
+Tcl_NewIntObj(
+ register int intValue) /* Int used to initialize the new object. */
+{
+ return Tcl_DbNewLongObj((long)intValue, "unknown", 0);
+}
+
+#else /* if not TCL_MEM_DEBUG */
+
+Tcl_Obj *
+Tcl_NewIntObj(
+ register int intValue) /* Int used to initialize the new object. */
+{
+ register Tcl_Obj *objPtr;
+
+ TclNewLongObj(objPtr, intValue);
+ return objPtr;
+}
+#endif /* if TCL_MEM_DEBUG */
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_SetIntObj --
+ *
+ * Modify an object to be an integer and to have the specified integer
+ * value.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The object's old string rep, if any, is freed. Also, any old internal
+ * rep is freed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+#undef Tcl_SetIntObj
+void
+Tcl_SetIntObj(
+ register Tcl_Obj *objPtr, /* Object whose internal rep to init. */
+ register int intValue) /* Integer used to set object's value. */
+{
+ if (Tcl_IsShared(objPtr)) {
+ Tcl_Panic("%s called with shared object", "Tcl_SetIntObj");
+ }
+
+ TclSetLongObj(objPtr, intValue);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_GetIntFromObj --
*
* Attempt to return an int from the Tcl object "objPtr". If the object
@@ -2382,8 +2604,8 @@ UpdateStringOfInt(
*----------------------------------------------------------------------
*/
-#ifdef TCL_MEM_DEBUG
#undef Tcl_NewLongObj
+#ifdef TCL_MEM_DEBUG
Tcl_Obj *
Tcl_NewLongObj(
@@ -2413,11 +2635,11 @@ Tcl_NewLongObj(
* Tcl_DbNewLongObj --
*
* If a client is compiled with TCL_MEM_DEBUG defined, calls to
- * Tcl_NewLongObj to create new long integer objects end up calling the
- * debugging function Tcl_DbNewLongObj instead. We provide two
- * implementations of Tcl_DbNewLongObj so that whether the Tcl core is
- * compiled to do memory debugging of the core is independent of whether
- * a client requests debugging for itself.
+ * Tcl_NewIntObj and Tcl_NewLongObj to create new integer or long integer
+ * objects end up calling the debugging function Tcl_DbNewLongObj
+ * instead. We provide two implementations of Tcl_DbNewLongObj so that
+ * whether the Tcl core is compiled to do memory debugging of the core is
+ * independent of whether a client requests debugging for itself.
*
* When the core is compiled with TCL_MEM_DEBUG defined, Tcl_DbNewLongObj
* calls Tcl_DbCkalloc directly with the file name and line number from
@@ -2493,6 +2715,7 @@ Tcl_DbNewLongObj(
*----------------------------------------------------------------------
*/
+#undef Tcl_SetLongObj
void
Tcl_SetLongObj(
register Tcl_Obj *objPtr, /* Object whose internal rep to init. */