Attachment "None" to
ticket [403327ff]
added by
pgbaum
2001-01-19 14:58:36.
*** generic/tkObj.orig.c Tue Nov 7 20:35:43 2000
--- generic/tkObj.c Sun Jan 28 12:16:00 2001
***************
*** 60,65 ****
--- 59,65 ----
static void DupMMInternalRep _ANSI_ARGS_((Tcl_Obj *srcPtr,
Tcl_Obj *copyPtr));
+ static void UpdateStringOfMM _ANSI_ARGS_((Tcl_Obj *objPtr));
static void DupPixelInternalRep _ANSI_ARGS_((Tcl_Obj *srcPtr,
Tcl_Obj *copyPtr));
static void FreeMMInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr));
***************
*** 95,101 ****
"mm", /* name */
FreeMMInternalRep, /* freeIntRepProc */
DupMMInternalRep, /* dupIntRepProc */
! NULL, /* updateStringProc */
SetMMFromAny /* setFromAnyProc */
};
--- 95,101 ----
"mm", /* name */
FreeMMInternalRep, /* freeIntRepProc */
DupMMInternalRep, /* dupIntRepProc */
! UpdateStringOfMM, /* updateStringProc */
SetMMFromAny /* setFromAnyProc */
};
***************
*** 473,478 ****
--- 473,520 ----
/*
*----------------------------------------------------------------------
*
+ * 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
***************
*** 501,506 ****
--- 543,553 ----
int units;
MMRep *mmPtr;
+ if ((objPtr != NULL) && (objPtr->typePtr == Tcl_GetObjType("double"))) {
+ /* optimize for speed reasons */
+ Tcl_GetDoubleFromObj( interp, objPtr, &d );
+ units = -1;
+ } else {
string = Tcl_GetStringFromObj(objPtr, NULL);
d = strtod(string, &rest);
***************
*** 542,547 ****
--- 589,595 ----
default:
goto error;
}
+ }
/*
* Free the old internalRep before setting the new one.