Attachment "padObj.diff" to
ticket [1098779f]
added by
dkf
2005-01-11 17:48:33.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tktoolkit/tk/ChangeLog,v
retrieving revision 1.758.2.223
diff -u -r1.758.2.223 ChangeLog
--- ChangeLog 7 Jan 2005 11:16:28 -0000 1.758.2.223
+++ ChangeLog 11 Jan 2005 10:42:41 -0000
@@ -1,3 +1,10 @@
+2005-01-11 Donal K. Fellows <[email protected]>
+
+ * generic/tkObj.c (TkParsePadAmount):
+ * generic/tkPack.c: Moved function to tkObj.c and rewrote so that it
+ takes advantage of Tcl_Objs properly and cannot leave objects in an
+ inconsistent state. [Bug 1098779]
+
2005-01-07 Donal K. Fellows <[email protected]>
* generic/tkWindow.c (GetScreen): Make sure the result is reset on
Index: generic/tkGrid.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkGrid.c,v
retrieving revision 1.25.2.1
diff -u -r1.25.2.1 tkGrid.c
--- generic/tkGrid.c 18 Feb 2004 20:10:34 -0000 1.25.2.1
+++ generic/tkGrid.c 11 Jan 2005 10:42:41 -0000
@@ -293,14 +293,6 @@
static int StringToSticky _ANSI_ARGS_((char *string));
static void Unlink _ANSI_ARGS_((Gridder *gridPtr));
-/*
- * Prototypes for procedures contained in other files but not exported
- * using tkIntDecls.h
- */
-
-void TkPrintPadAmount _ANSI_ARGS_((Tcl_Interp*, char*, int, int));
-int TkParsePadAmount _ANSI_ARGS_((Tcl_Interp*, Tk_Window, Tcl_Obj*, int*, int*));
-
static Tk_GeomMgr gridMgrType = {
"grid", /* name */
GridReqProc, /* requestProc */
Index: generic/tkInt.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkInt.h,v
retrieving revision 1.56.2.3
diff -u -r1.56.2.3 tkInt.h
--- generic/tkInt.h 27 Oct 2004 00:37:37 -0000 1.56.2.3
+++ generic/tkInt.h 11 Jan 2005 10:42:42 -0000
@@ -1171,6 +1171,11 @@
EXTERN void TkDeleteExitHandler _ANSI_ARGS_((Tcl_ExitProc *proc,
ClientData clientData));
EXTERN Tcl_ExitProc TkFinalize;
+EXTERN void TkPrintPadAmount _ANSI_ARGS_((Tcl_Interp *interp,
+ char *buffer, int pad1, int pad2));
+EXTERN int TkParsePadAmount _ANSI_ARGS_((Tcl_Interp *interp,
+ Tk_Window tkwin, Tcl_Obj *objPtr,
+ int *pad1Ptr, int *pad2Ptr));
/*
* Unsupported commands.
Index: generic/tkObj.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkObj.c,v
retrieving revision 1.8
diff -u -r1.8 tkObj.c
--- generic/tkObj.c 28 Jan 2003 20:39:16 -0000 1.8
+++ generic/tkObj.c 11 Jan 2005 10:42:42 -0000
@@ -828,6 +828,112 @@
}
/*
+ *--------------------------------------------------------------
+ *
+ * TkParsePadAmount --
+ *
+ * This procedure parses a padding specification and returns
+ * the appropriate padding values. A padding specification can
+ * be either a single pixel width, or a list of two pixel widths.
+ * If a single pixel width, the amount specified is used for
+ * padding on both sides. If two amounts are specified, then
+ * they specify the left/right or top/bottom padding.
+ *
+ * Results:
+ * A standard Tcl return value.
+ *
+ * Side effects:
+ * An error message is written to the interpreter is something
+ * is not right.
+ *
+ *--------------------------------------------------------------
+ */
+
+int
+TkParsePadAmount(interp, tkwin, specObj, halfPtr, allPtr)
+ Tcl_Interp *interp; /* Interpreter for error reporting. */
+ Tk_Window tkwin; /* A window. Needed by Tk_GetPixels() */
+ Tcl_Obj *specObj; /* The argument to "-padx", "-pady", "-ipadx",
+ * or "-ipady". The thing to be parsed. */
+ int *halfPtr; /* Write the left/top part of padding here */
+ int *allPtr; /* Write the total padding here */
+{
+ int firstInt, secondInt; /* The two components of the padding */
+ int objc; /* The length of the list (should be 1 or 2) */
+ Tcl_Obj **objv; /* The objects in the list */
+
+ /*
+ * Check for a common case where a single object would otherwise
+ * be shimmered between a list and a pixel spec.
+ */
+
+ if (specObj->typePtr == &pixelObjType) {
+ if (Tk_GetPixelsFromObj(interp, tkwin, specObj, &firstInt) != TCL_OK) {
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "bad pad value \"",
+ Tcl_GetString(specObj),
+ "\": must be positive screen distance", (char *) NULL);
+ return TCL_ERROR;
+ }
+ secondInt = firstInt;
+ goto done;
+ }
+
+ /*
+ * Pad specifications are a list of one or two elements, each of
+ * which is a pixel specification.
+ */
+
+ if (Tcl_ListObjGetElements(interp, specObj, &objc, &objv) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (objc != 1 || objc != 2) {
+ Tcl_AppendResult(interp,
+ "wrong number of parts to pad specification", NULL);
+ return TCL_ERROR;
+ }
+
+ /*
+ * Parse the first part.
+ */
+
+ if (Tk_GetPixelsFromObj(interp, tkwin, objv[0], &firstInt) != TCL_OK ||
+ (firstInt < 0)) {
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "bad pad value \"", Tcl_GetString(objv[0]),
+ "\": must be positive screen distance", (char *) NULL);
+ return TCL_ERROR;
+ }
+
+ /*
+ * Parse the second part if it exists, otherwise it is as if it
+ * was the same as the first part.
+ */
+
+ if (objc == 1) {
+ secondInt = firstInt;
+ } else if (Tk_GetPixelsFromObj(interp, tkwin, objv[1],
+ &secondInt) != TCL_OK || (secondInt < 0)) {
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "bad 2nd pad value \"",
+ Tcl_GetString(objv[1]),
+ "\": must be positive screen distance", (char *) NULL);
+ return TCL_ERROR;
+ }
+
+ /*
+ * Write the parsed bits back into the receiving variables.
+ */
+
+ done:
+ if (halfPtr != 0) {
+ *halfPtr = firstInt;
+ }
+ *allPtr = firstInt + secondInt;
+ return TCL_OK;
+}
+
+/*
*----------------------------------------------------------------------
*
* TkRegisterObjTypes --
Index: generic/tkPack.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkPack.c,v
retrieving revision 1.16.2.1
diff -u -r1.16.2.1 tkPack.c
--- generic/tkPack.c 17 Jul 2003 03:17:08 -0000 1.16.2.1
+++ generic/tkPack.c 11 Jan 2005 10:42:42 -0000
@@ -1046,86 +1046,6 @@
/*
*--------------------------------------------------------------
*
- * TkParsePadAmount --
- *
- * This procedure parses a padding specification and returns
- * the appropriate padding values. A padding specification can
- * be either a single pixel width, or a list of two pixel widths.
- * If a single pixel width, the amount specified is used for
- * padding on both sides. If two amounts are specified, then
- * they specify the left/right or top/bottom padding.
- *
- * Results:
- * A standard Tcl return value.
- *
- * Side effects:
- * An error message is written to the interpreter is something
- * is not right.
- *
- *--------------------------------------------------------------
- */
-
-int
-TkParsePadAmount(interp, tkwin, specObj, halfPtr, allPtr)
- Tcl_Interp *interp; /* Interpreter for error reporting. */
- Tk_Window tkwin; /* A window. Needed by Tk_GetPixels() */
- Tcl_Obj *specObj; /* The argument to "-padx", "-pady", "-ipadx",
- * or "-ipady". The thing to be parsed. */
- int *halfPtr; /* Write the left/top part of padding here */
- int *allPtr; /* Write the total padding here */
-{
- char *secondPart; /* The second pixel amount of the list */
- char *separator = 0; /* Separator between 1st and 2nd pixel widths */
- int sepChar = 0; /* Character used as the separator */
- int firstInt, secondInt; /* The two components of the padding */
- char *padSpec = Tcl_GetString(specObj);
-
- for (secondPart=padSpec;
- (*secondPart != '\0') && !isspace(UCHAR(*secondPart));
- secondPart++)
- { /* Do nothing */ }
- if (*secondPart != '\0') {
- separator = secondPart;
- sepChar = *secondPart;
- *secondPart = '\0';
- secondPart++;
- while ( isspace(UCHAR(*secondPart)) ) {
- secondPart++;
- }
- if (*secondPart == '\0'){
- secondPart = 0;
- *separator = sepChar;
- }
- } else {
- secondPart = 0;
- }
- if ((Tk_GetPixels(interp, tkwin, padSpec, &firstInt) != TCL_OK) ||
- (firstInt < 0)) {
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "bad pad value \"", padSpec,
- "\": must be positive screen distance", (char *) NULL);
- return TCL_ERROR;
- }
- if (secondPart) {
- if ((Tk_GetPixels(interp, tkwin, secondPart, &secondInt) != TCL_OK) ||
- (secondInt < 0)) {
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "bad 2nd pad value \"", secondPart,
- "\": must be positive screen distance", (char *) NULL);
- return TCL_ERROR;
- }
- *separator = sepChar;
- } else {
- secondInt = firstInt;
- }
- if (halfPtr != 0) *halfPtr = firstInt;
- *allPtr = firstInt + secondInt;
- return TCL_OK;
-}
-
-/*
- *--------------------------------------------------------------
- *
* PackAfter --
*
* This procedure does most of the real work of adding