Attachment "403327.patch" to
ticket [403327ff]
added by
hobbs
2001-03-24 07:58:22.
Also attachment "403327.patch" to
ticket [403327ff]
added by
hobbs
2001-03-24 07:57:08.
? doc/man.macros
? unix/linux
Index: generic/tkObj.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkObj.c,v
retrieving revision 1.3
diff -b -c -r1.3 tkObj.c
*** generic/tkObj.c 2000/12/13 19:44:15 1.3
--- generic/tkObj.c 2001/03/24 00:46:08
***************
*** 64,69 ****
--- 64,70 ----
Tcl_Obj *copyPtr));
static void FreeMMInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr));
static void FreePixelInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr));
+ static void UpdateStringOfMM _ANSI_ARGS_((Tcl_Obj *objPtr));
static int SetMMFromAny _ANSI_ARGS_((Tcl_Interp *interp,
Tcl_Obj *objPtr));
static int SetPixelFromAny _ANSI_ARGS_((Tcl_Interp *interp,
***************
*** 95,101 ****
"mm", /* name */
FreeMMInternalRep, /* freeIntRepProc */
DupMMInternalRep, /* dupIntRepProc */
! NULL, /* updateStringProc */
SetMMFromAny /* setFromAnyProc */
};
--- 96,102 ----
"mm", /* name */
FreeMMInternalRep, /* freeIntRepProc */
DupMMInternalRep, /* dupIntRepProc */
! UpdateStringOfMM, /* updateStringProc */
SetMMFromAny /* setFromAnyProc */
};
***************
*** 473,478 ****
--- 474,521 ----
/*
*----------------------------------------------------------------------
*
+ * UpdateStringOfMM --
+ *
+ * Update the string representation for a pixel Tcl_Obj
+ * this function is only called, if the pixel Tcl_Obj has no unit,
+ * because with units the string representation is created by
+ * SetMMFromAny
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The object's string is set to a valid string that results from
+ * the double-to-string conversion.
+ *
+ *----------------------------------------------------------------------
+ */
+
+ static void
+ UpdateStringOfMM(objPtr)
+ register Tcl_Obj *objPtr; /* pixel obj with string rep to update. */
+ {
+ MMRep *mmPtr;
+ char buffer[TCL_DOUBLE_SPACE];
+ register int len;
+
+ mmPtr = (MMRep *) objPtr->internalRep.otherValuePtr;
+ /* assert( mmPtr->units == -1 && objPtr->bytes == NULL ); */
+ if ((mmPtr->units != -1) || (objPtr->bytes != NULL)) {
+ panic("UpdateStringOfMM: false precondition");
+ }
+
+ Tcl_PrintDouble((Tcl_Interp *) NULL, mmPtr->value, buffer);
+ len = strlen(buffer);
+
+ objPtr->bytes = (char *) ckalloc((unsigned) len + 1);
+ strcpy(objPtr->bytes, buffer);
+ objPtr->length = len;
+ }
+
+ /*
+ *----------------------------------------------------------------------
+ *
* SetMMFromAny --
*
* Attempt to generate a mm internal form for the Tcl object
***************
*** 500,511 ****
double d;
int units;
MMRep *mmPtr;
! if (objPtr->typePtr == &tclDoubleType) {
! /* optimize for speed reasons */
Tcl_GetDoubleFromObj(interp, objPtr, &d);
units = -1;
} else {
string = Tcl_GetStringFromObj(objPtr, NULL);
d = strtod(string, &rest);
--- 543,581 ----
double d;
int units;
MMRep *mmPtr;
+
+ static Tcl_ObjType *tclDoubleObjType = NULL;
+ static Tcl_ObjType *tclIntObjType = NULL;
+
+ if (tclDoubleObjType == NULL) {
+ /*
+ * Cache the object types for comaprison below.
+ * This allows optimized checks for standard cases.
+ */
! tclDoubleObjType = Tcl_GetObjType("double");
! tclIntObjType = Tcl_GetObjType("int");
! }
!
! if (0 && objPtr->typePtr == tclDoubleObjType) {
Tcl_GetDoubleFromObj(interp, objPtr, &d);
units = -1;
+ } else if (0 && objPtr->typePtr == tclIntObjType) {
+ Tcl_GetIntFromObj(interp, objPtr, &units);
+ d = (double) units;
+ units = -1;
+
+ /*
+ * In the case of ints, we need to ensure that a valid
+ * string exists in order for int-but-not-string objects
+ * to be converted back to ints again from mm obj types.
+ */
+ (void) Tcl_GetStringFromObj(objPtr, NULL);
} else {
+ /*
+ * It wasn't a known int or double, so parse it.
+ */
+
string = Tcl_GetStringFromObj(objPtr, NULL);
d = strtod(string, &rest);
Index: tests/canvas.test
===================================================================
RCS file: /cvsroot/tktoolkit/tk/tests/canvas.test,v
retrieving revision 1.10
diff -b -c -r1.10 canvas.test
*** tests/canvas.test 2000/06/06 04:18:13 1.10
--- tests/canvas.test 2001/03/24 00:46:09
***************
*** 367,372 ****
--- 367,392 ----
-fill {} -stipple gray50 -outline black
} 1
+ test canvas-12.1 {canvas mm obj, patch SF-403327, 102471} {
+ destroy .c
+ pack [canvas .c]
+ set qx [expr {1.+1.}]
+ # qx has type double and no string representation
+ .c scale all $qx 0 1. 1.
+ # qx has now type MMRep and no string representation
+ list $qx [string length $qx]
+ } {2.0 3}
+ test canvas-12.2 {canvas mm obj, patch SF-403327, 102471} {
+ destroy .c
+ pack [canvas .c]
+ set val 10
+ incr val
+ # qx has type double and no string representation
+ .c scale all $val 0 1 1
+ # qx has now type MMRep and no string representation
+ incr val
+ } {12}
+
# cleanup
::tcltest::cleanupTests
return