| Ticket UUID: | 026e2bb685ffe42e4f0a5331421b2a42fcb423a7 | |||
| Title: | text tag sets bad relief, gets error, but bad relief is saved anyway | |||
| Type: | Bug | Version: | 8.6.9, revised_text | |
| Submitter: | anonymous | Created on: | 2024-01-14 08:16:27 | |
| Subsystem: | 18. [text] | Assigned To: | jan.nijtmans | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Pending | Last Modified: | 2024-06-04 08:04:46 | |
| Resolution: | Fixed | Closed By: | nobody | |
| Closed on: | 2024-01-16 23:54:53 | |||
| Description: |
If I have a text widget and I try to set a bad value for relief, it gives an error, but still saves the bad value. I think it should ignore it. By saving it, later code can error if one tries to use the value there, say to clone a tag with another tag's values by assuming all the values are valid.
% text .text
.text
% .text tag add red 1.0
% .text tag config red -relief
-relief {} {} {} {}
% .text tag config red -relief xxx
bad relief "xxx": must be flat, groove, raised, ridge, solid, or sunken
% .text tag config red -relief
-relief {} {} {} xxx
% .text tag cget red -relief
xxx
| |||
| User Comments: |
jan.nijtmans added on 2024-06-04 08:04:46:
Currently the only option not handled correctly is "-tags". I started writing a custom parser for that (see https://core.tcl-lang.org/tk/timeline?r=bug-026e2bb685), but it doesn't work yet. Low prio fvogel added on 2024-06-04 06:04:55: Jan, stumbling on this again. What do you mean by status "Pending"? what is awaited? fvogel added on 2024-02-29 22:08:35: Hi Jan, I'm lost again: did you address what remained to be done in the frame of this ticket? It's status is "Pending". Yeah, but pending what? What does this status mean? jan.nijtmans added on 2024-02-05 20:30:38: > What about -lmargin1 .... That's not needed any more. In Tk 8.7, it was stored as a string, so Tk_GetPixelFromObj() was needed to convert it to pixel values (which can generate an error). In Tcl 9.0, I converted it from TK_OPTION_STRING to TK_OPTION_PIXELS, which prevents this whole problem. fvogel added on 2024-02-05 20:02:19: What about -lmargin1, -lmargin2, -rmargin, -spacing1/2/3, -underline, -offset ? Don't these need to get a TK_OPTION_CUSTOM as well, as you did in [d5bcba02b7]? jan.nijtmans added on 2024-02-05 08:47:13: Well, for -relief and -justify, it's fixed now for all branches, so technically this ticket can be closed. However, watching for postprocessing immediately after Tk_SetOptions(), there's still one option sensitive for the same problem: "-tabs" If this postprocessing is able to return TCL_ERROR, it means that Tcl_SetOptions() already set the new values, which is noticable at script level. The best solution here is to transform this into a TCL_OPTION_CUSTOM, then the following options are not handled until the option is fully checked. I'm having a further look at "-tabs". fvogel added on 2024-02-04 19:42:20: I have seen [8fad9728] and [bb35ac63] for revised_text, thanks. I have a bit lost sight on what remains to be done but I'm sure you know. fvogel added on 2024-01-23 21:31:57: Thanks to you. Please go on merging in revised_text, I don't think I can handle this. jan.nijtmans added on 2024-01-23 14:20:54: Should be [d5bcba02b75a4e3e|fixed] in all branches now, excpt for revised_text. Thanks, François, for all your work on this! jan.nijtmans added on 2024-01-22 20:55:01: > OK. No problem for me, merge as you see good. Thanks! Well, I'm not 100% satisfied yet, but it's close. So, if you have more remarks on the implementation, fire away. I'm extra careful now, since Tcl 8.6.14 is approaching: I don't want to rush this into the release. fvogel added on 2024-01-22 20:39:52: OK. No problem for me, merge as you see good. jan.nijtmans added on 2024-01-21 22:44:51: In branch bug-026e2bb685
<pre>
$ wish8.6
% package require Tk
8.6.13
% text .t
.t
% .t tag configure x -spacing1 5 -spacing2 bad -spacing3 morebad
bad screen distance "morebad"
% .t tag configure x -spacing1
-spacing1 {} {} {} {}
</pre>
Indeed, you report the last error encountered, which is not the first error encountered in the argument list ......
jan.nijtmans added on 2024-01-21 22:29:49: > Worse, I think it's more complicated and less maintainable. Once you understand how Tk_ObjCustomOption works, it's not complicated at all. The special handling is generalized into 4 Tk_ObjCustomOption's, one for Pixels, one for Boolean's, one for relief and one for justify. Two other advantages: 1) performance, it's the same as the original code (your implementation will cost additional performance, because all old values have to be stored for possible recovery) 2) behavior when multiple options are provided in a single command is the same as the original Tk 8.6 code (and also the same as current Tk 8.7/9.0) fvogel added on 2024-01-21 21:44:20: > Why is the "spacing1" error reported, not the "spacing2" ???? In branch bug-026e2bb685, I get the expected error message: % pack req Tk 8.6.13 % text .t .t % .t tag configure x -spacing3 5 -spacing2 bad -spacing1 morebad bad screen distance "bad" % The error that is reported does not depend on the argument order: % .t tag configure x -spacing3 5 -spacing1 morebad -spacing2 bad bad screen distance "bad" % I believe the reported error is what is left in the interp result by Tk_GetPixels(). If there are more than one erroneous value, the last one to have been dealt with in the code erases the previous ones. This is all OK for me. I had a quick look at your alternate proposal in branch bug-026e2bb685-alt. It should work as well, but I don't see the advantage over branch bug-026e2bb685. Worse, I think it's more complicated and less maintainable. jan.nijtmans added on 2024-01-21 21:27:47: New attempt: [289a155a5e99c226] ;-) jan.nijtmans added on 2024-01-21 20:57:00: > About [042c281f]: I think that the expected result for the modified textTag-1.29 should be .... To me, whether -spacing3 reset or not is not a big deal. But ... it's a change in behavior compared to how Tk 8.6/8.7/9.0 is behaving now. It looks like Menu's, Canvas, Text windows and Text images don't use savePtr. I don't know why. But, what triggered me more is the strange error-message: $ wish8.6 % text .t .t % .t tag configure -spacing3 5 -spacing2 bad -spacing1 morebad unknown option "5" % .t tag configure x -spacing3 5 -spacing2 bad -spacing1 morebad bad screen distance "morebad" Why is the "spacing1" error reported, not the "spacing2" ???? Well, I figured you like challenges ...... fvogel added on 2024-01-21 19:34:14: To make myself clearer perhaps: % pack req Tk 8.6.13 % button .b .b % .b conf -bg -background background Background SystemButtonFace SystemButtonFace % .b conf -bg red -fg posdfs unknown color name "posdfs" % .b conf -bg -background background Background SystemButtonFace SystemButtonFace % This does not return "red". fvogel added on 2024-01-21 18:31:33: About [042c281f]: I think that the expected result for the modified textTag-1.29 should be:
bad screen distance "bad"} {-spacing1 {} {} {} {}} {-spacing2 {} {} {} {}} {-spacing3 {} {} {} {}}
instead of what you specified, that is:
bad screen distance "bad"} {-spacing1 {} {} {} {}} {-spacing2 {} {} {} {}} {-spacing3 {} {} {} 5}
is an erroneous statement which leads to rejection of the statement in its entirety. Do you have examples of widgets behaving in the way of your expected test result? jan.nijtmans added on 2024-01-21 11:22:36: I agree that this new implementation is better than what's currently on core-8-6-branch. I don't see memory leaks, nor big performance impact. fvogel added on 2024-01-21 10:45:24: Github's opinion at least is that this code is fine. fvogel added on 2024-01-20 13:44:10: I have followed your latest commits but I'm not ready to give up yet. I have proposed an implementation [507fdcab] based on my suggestion below (use of the savePtr argument to Tk_SetOptions). Opinions? fvogel added on 2024-01-17 21:26:38: About 3.: I had warned that my proposal was a "quick proof of concept". That it has leaks is not surprising. Thanks for having fixed this. Regarding performance, instead of the approach I have proposed couldn't we make use of the savePtr argument to Tk_SetOptions, which is designed precisely to handle error recovery? jan.nijtmans added on 2024-01-17 12:22:16: 1) Agreed. But Tk8.6 doesn't have TK_JUSTIFY_NULL, so I see no other way. 2) Agreed as well. But "when merging into revised_text", that won't happen: TIP #613 can implement this in a much cleaner way, see: [aa23a01fd9e8458c]. Done now for 8.7 and 9.0 3) In your implementation I see 2 problems: A memory leak and a performance problem with many tags. The memory leak is solvable: [592a36ae6628a992]. The performance problem is not: Consider a simple command like ".text tag config x -color red", allocating 7 additional strings (for all PIXEL-related options, if specified) , and throwing them away, just for this error-case .... I don't think we want that risk in 8.6. The text widget is already considered slow (that's why revised_text was developed in the first place). I hope you can agree with that. fvogel added on 2024-01-17 05:05:28: Reviewing the code and testing manually and with the test suite, I think the branch is fine. Here are a few comments:
tagPtr->justify = (Tk_Justify)-1;
if ((unsigned)tagPtr->relief <= TK_RELIEF_SUNKEN) { ...
if ((unsigned)tagPtr->justify <= (unsigned)TK_JUSTIFY_CENTER) { ...
jan.nijtmans added on 2024-01-16 23:54:53: It looks like the remaining options are working now too: [4c67cefe8a0cae4b] François, would you be able review this branch? Tk8.6.14 is coming out soon, so it isn't a good time for unexpected surprises now .... Thanks! I'm aware of the following 'strange' behavior:
% text .t
.t
% .t tag configure x -lmargin1
-lmargin1 {} {} {} {}
% .t tag configure x -lmargin1 3c
% .t tag configure x -lmargin1
-lmargin1 {} {} {} 3c
% .t tag configure x -lmargin1 abc
bad screen distance "abc"
% .t tag configure x -lmargin1
-lmargin1 {} {} {} 85
So, after an invalid value is given, the string representation of the previous pixel value is lost, but we still have the number of pixels ("3c" = 85 pixels). So, that's the best we can do here, for sure better than keeping the invalid value (which is what this bug ticket is about). The widget appearance on screen won't change.
jan.nijtmans added on 2024-01-16 21:34:19: I remember now that I couldn't make "-elide" work with TIP #613 in revised_text. Now I see it only had 1 bit assigned in StyleValues. That explains it! jan.nijtmans added on 2024-01-16 21:31:20: > One question: why did you change the bit fields in the StyleValues struct in [50e74fb4] ? The TIP #613 approach uses "-1" enum values to indicate that the value is not provided. That means that we need an extra sign-bit in all those bit-fields, and the bit-fields cannot be unsigned any more. Otherwise the enum values won't fit. We still stay below 32 bits in total .... fvogel added on 2024-01-16 19:03:59: Thanks, I'm following your progress. While testing I have found [dd35d8b1e2], which was already present before your changes. One question: why did you change the bit fields in the StyleValues struct in [50e74fb4] ? jan.nijtmans added on 2024-01-16 11:07:01: The text implementation in revised_text is so much different, so the fix for this ticket takes some more work. I reverted most of the changes now, I will have another look. fvogel added on 2024-01-16 07:29:59: For the revised text widget the behaviour is still incorrect. When requesting "XXX", the text widget gets the "flat" value instead of "" (the latter is correctly returned by the legacy text widget in trunk).
% pack req Tk
9.0b1
% text .t
.t
% .t tag add red 1.0
% .t tag config red -relief
-relief {} {} {} flat
% .t tag config red -relief xxx
bad relief "xxx": must be flat, groove, raised, ridge, solid, sunken, or ""
% .t tag config red -relief
-relief {} {} {} flat
% .t tag cget red -relief
flat
Another important thing is that your latest commits killed the "full" justification mode of the text widget, and this is a regression. See description of the "full" justification option value here, and example test code there (click "Expand/Collapse script" to see it). With this example the rendering is still correct with [02216b70] but full justification is no longer present with [5606e162] even if "-justify full" is still accepted without error. The rendering is no longer correct, the text seems justified as if "-justify left" was specified. Specifying ".t configure -justify" does not seem to be honored anymore. jan.nijtmans added on 2024-01-15 23:06:14: 1) Done 2) I'm aware of that. Can still be improved (but not really high prio) fvogel added on 2024-01-15 21:12:58: Thanks for having dealt with this. Two comments on my side:
pack req Tk text .t .t tag add red 1.0 .t tag config red -relief raised .t tag config red -relief xxx .t tag cget red -relief ; # should return "raised". In 8.6 now it's "" (but in trunk it's "raised" as expected). jan.nijtmans added on 2024-01-14 22:01:01: Fixed now in all branches. Thanks for the report! In Tk 8.7 and 9.0, TIP #613 functionality is used for the fix, which results in code simplification. In Tk 8.6 this was not possible, so the implementation is different: Just set it to NULL when an error occurs. B.T.W: The -justify option had the same problem, this is fixed too. | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki