Skip to content
Tcl Source Code History Of Ticket 1e48483c8b
Login

History Of Ticket 1e48483c8b

Artifacts Associated With Ticket 1e48483c8b

  1. Ticket change [64ac383dd3] (rid 225336) by gustafn3 on 2024-04-25 17:31:54:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. comment initialized to:
      The current version of Tcl9 uses the GNU statement expression extension inside 
      Tcl_GetBooleanFromObj(), actually in TCLBOOLWARNING
      
         tclsock.c:1321:22: warning: use of GNU statement expression extension from macro expansion [-Wgnu-statement-expression-from-macro-expansion]
                     result = Tcl_GetBooleanFromObj(interp, objPtr, &ok);
                              ^
         /usr/local/ns9/include/tclDecls.h:4056:3: note: expanded from macro 'Tcl_GetBooleanFromObj'
                 (TCLBOOLWARNING(boolPtr)(sizeof(*(boolPtr)) >= sizeof(int) && (TCL_MAJOR_VERSION == 8)) ? Tcl_GetBooleanFromObj(interp, objPtr, (int *)(boolPtr)) : \
                  ^
         /usr/local/ns9/include/tclDecls.h:4037:37: note: expanded from macro 'TCLBOOLWARNING'
         #   define TCLBOOLWARNING(boolPtr) ({__attribute__((unused)) char _bool_Var[sizeof(*(boolPtr)) > sizeof(int) ? -1 : 1];}),
            
      A "statement expressions" is an extension of the GNU C compiler and allows you
      to execute a group of statements, returning the value of the last statement. 
      This will cause problems on standard C compilers not supporting this extension
      
    5. foundin initialized to: "9.0b3"
    6. is_private initialized to: "0"
    7. login: "gustafn3"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "ef1993a98c1daa778fe0b246a7af12b3076f2240"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "gustafn3"
    14. subsystem initialized to: "10. Objects"
    15. title initialized to: "Use of non-standard C code in TCLBOOLWARNING"
    16. type initialized to: "Bug"
  2. Ticket change [667651bd10] (rid 225337) by jan.nijtmans on 2024-04-25 19:05:47:

    1. icomment:
      TCLBOOLWARNING is meant to produce a compiler error when sizeof(*(boolPtr)) > sizeof(int). There's an #ifdef __GNUC__ around it, so it isn't actually an error.
      
      I didn't find a better way to do this. If you have an idea, please let me known.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  3. Ticket change [b00eb3e745] (rid 225345) by gustafn3 on 2024-04-26 09:51:04:

    1. icomment:
      As i read this, the intention is to issue an error, when someone passes in a value larger than "int" as result pointer in
      
         Tcl_GetBooleanFromObj(interp, objv[0], boolPtr);
      
      since there is later a cast 
      
         Tcl_GetBooleanFromObj(interp, objPtr, (int *)(boolPtr))
      
      For the code
      
         {
             size_t large = 0;
             result = Tcl_GetBooleanFromObj(interp, objPtr, &large);
         }
      
      the error message in this case will be
      
         error: '_bool_Var' declared as an array with a negative size
      
      as also the comment documents.
      
      This is not great for the following reasons:
      1) strange error message
      2) generated only on GNU compatible compilers
      3) handles just a particular case (object for the result is too large, why not covering too small?)
      4) raises a warning also in cases, where everything is fine
         (when the paranoia flags are turned on, probably many developers will do this, when moving to tcl9)
      
      Why not using
      
         static_assert( constant-expression, string-literal )
      
      when available. It is part of
      - C11
      - MS: VS 2015
      - GCC since gcc-4.6
      
      With some mental contortion, one can also sneak it into expressions, 
      as the following snippet shows.
      
         {
             size_t large = 0;
             result = Tcl_GetBooleanFromObj(interp, objPtr, &large)
                     + (int)(sizeof(struct {static_assert(sizeof(large) <= sizeof(int),"all is lost");int dummy;})*0) ;
         }
      
      This would address (1) and (4) and improves the situation on (2) as well.
      
    2. login: "gustafn3"
    3. mimetype: "text/plain"
  4. Ticket change [4a403070a8] (rid 225348) by jan.nijtmans on 2024-04-26 11:32:55:

    1. icomment:
      Thanks for the suggestion. I tried it:
      <pre>
      warning: identifier ‘static_assert’ conflicts with C++ keyword [-Wc++-compat]
       2787 |                 if (Tcl_GetBooleanFromObj(interp, objv[1], &debugType)+ (int)(sizeof(struct {static_assert(sizeof(debugType) <= sizeof(int),"all is lost");int dummy;})*0)
            |                                                                                              ^~~~~~~~~~~~~
      warning: defining type in ‘sizeof’ expression is invalid in C++ [-Wc++-compat]
       2787 |                 if (Tcl_GetBooleanFromObj(interp, objv[1], &debugType)+ (int)(sizeof(struct {static_assert(sizeof(debugType) <= sizeof(int),"all is lost");int dummy;})*0)
            |                                                                                      ^~~~~~
      
      </pre>
      
      So, I changed it to _Static_assert(), that fixed the first warning but not the second. Conclusion: Your suggestion won't work when tcl.h is included in a C++ project.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  5. Ticket change [8d5dcc33a2] (rid 225349) by jan.nijtmans on 2024-04-26 11:35:29:

    1. icomment: "Does [066670e43164ede9|this] work for you?"
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  6. Ticket change [5384c5997e] (rid 225351) by gustafn3 on 2024-04-26 12:00:15:

    1. icomment:
      There are various means to address C++ compatibility:
      
      one can deactivate the check in c++ (there is anyhow no full coverage), this would address both cases, or
      
      ... one can add "-std=c++11" to the compile flags for c++ programs (for the first case)
      ... one can use the comma operator and a lambda-expression in the CPP case (([]{static_assert(true,"");}, ....)) ... this addresses the second case for c++
      
      Still wondering: wouldn't it be better to reduce casting and all this manual checking, 
      and let the compiler spit out warnings on type mismatches (maybe dependent on the "backward compatibility" flag)?
      
    2. login: "gustafn3"
    3. mimetype: "text/plain"
  7. Ticket change [96c93a50d3] (rid 225352) by gustafn3 on 2024-04-26 12:07:39:

    1. icomment:
      > does this work for you
      
      ... mostly, parentheses should be added
      
      tclsock.c:1333:22: warning: operator '?:' has lower precedence than '+'; '+' will be evaluated first [-Wparentheses]
                  result = Tcl_GetBooleanFromObj(interp, objPtr, &ok);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /usr/local/ns9/include/tclDecls.h:4057:90: note: expanded from macro 'Tcl_GetBooleanFromObj'
              (TCLBOOLWARNING(boolPtr)(sizeof(*(boolPtr)) >= sizeof(int) && (TCL_MAJOR_VERSION == 8)) ? Tcl_GetBooleanFromObj(interp, objPtr, (int *)(boolPtr)) : \
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
      tclsock.c:1333:22: note: place parentheses around the '+' expression to silence this warning
                  result = Tcl_GetBooleanFromObj(interp, objPtr, &ok);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /usr/local/ns9/include/tclDecls.h:4057:90: note: expanded from macro 'Tcl_GetBooleanFromObj'
              (TCLBOOLWARNING(boolPtr)(sizeof(*(boolPtr)) >= sizeof(int) && (TCL_MAJOR_VERSION == 8)) ? Tcl_GetBooleanFromObj(interp, objPtr, (int *)(boolPtr)) : \
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
      tclsock.c:1333:22: note: place parentheses around the '?:' expression to evaluate it first
                  result = Tcl_GetBooleanFromObj(interp, objPtr, &ok);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /usr/local/ns9/include/tclDecls.h:4057:90: note: expanded from macro 'Tcl_GetBooleanFromObj'
              (TCLBOOLWARNING(boolPtr)(sizeof(*(boolPtr)) >= sizeof(int) && (TCL_MAJOR_VERSION == 8)) ? Tcl_GetBooleanFromObj(interp, objPtr, (int *)(boolPtr)) : \
      
    2. login: "gustafn3"
    3. mimetype: "text/plain"
  8. Ticket change [917dd5a7a4] (rid 225354) by jan.nijtmans on 2024-04-26 12:29:59:

    1. icomment: "Another attempt: [c0bdbd9536f2b001|here]"
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  9. Ticket change [472b750bd0] (rid 225355) by gustafn3 on 2024-04-26 12:36:36:

    1. icomment: "yep, this works nicely, no warnings etc."
    2. login: "gustafn3"
    3. mimetype: "text/plain"
  10. Ticket change [df4cc83188] (rid 225376) by jan.nijtmans on 2024-04-26 16:37:02:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2460427.19239296"
    3. closer changed to: "jan.nijtmans"
    4. icomment: "Now merged to core-8-branch and trunk"
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"
  11. Ticket change [f28f57379b] (rid 225392) by jan.nijtmans on 2024-04-27 17:15:34:

    1. closedate changed to: "2460428.21915071"
    2. icomment:
      With Visual Studio 2022, this construct gives:
      <pre>
      D:\a\tcl\tcl\win\..\generic\tclTest.c(2676): error C2061: syntax error: identifier '_Static_assert'
      ...
      </pre>
      
      I don't know if that's fixed in later Visual Studio versions, but Tcl/Tk currently supports VS2015+
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
  12. Ticket change [cdd7c113b4] (rid 225393) by jan.nijtmans on 2024-04-27 17:16:07:

    1. closedate changed to: "2460428.21953103"
    2. foundin changed to: "9.0b2"
    3. login: "jan.nijtmans"
    4. mimetype: "text/plain"
  13. Ticket change [392bc88d77] (rid 225419) by gustafn3 on 2024-04-29 07:22:28:

    1. closedate changed to: "2460429.80727141"
    2. closer changed to: "gustafn3"
    3. icomment:
      One should use with MSVC 2015+ "static_assert" and not '_Static_assert'. See documentation:
      
      https://learn.microsoft.com/de-de/cpp/cpp/static-assert?view=msvc-140
      
    4. login: "gustafn3"
    5. mimetype: "text/plain"
  14. Ticket change [4145146399] (rid 225448) by jan.nijtmans on 2024-04-29 12:07:06:

    1. closedate changed to: "2460430.00493321"
    2. closer changed to: "jan.nijtmans"
    3. icomment:
      > See documentation ...
      
      Unfortunately, documentation doesn't always tell the whole story. Did you try it? I tried it with VS2017:
      <pre>
      tclZlib.c(474): error C2059: syntax error: 'static_assert'
      ...
      </pre>
      
      Most likely, for this feature to work we need Visual Studio 2019 version 16.8 Preview 3 (which added more C11 features), and possibly switches like /std:c11, or installing a special SDK. Conclusion: it's too early to depend on that or make any assumptions. Tcl 8.7/9.0 will support VS2015+
      
    4. login: "jan.nijtmans"
    5. mimetype: "text/x-fossil-wiki"
  15. Ticket change [8f20d08f64] (rid 225449) by gustafn3 on 2024-04-29 13:04:36:

    1. closedate changed to: "2460430.0448709"
    2. closer changed to: "gustafn3"
    3. icomment:
      I've lost my access to a Windows machine, so I have to rely on the docs...
      
    4. login: "gustafn3"
    5. mimetype: "text/plain"
  16. Ticket change [2a3d0fa5f3] (rid 225452) by gustafn3 on 2024-04-30 13:22:57:

    1. closedate changed to: "2460431.0576112"
    2. icomment:
      Unfortunately, the newest version generates an error (with gcc-11 and gcc-12)
      
      https://github.com/naviserver-project/naviserver/actions/runs/8894601239/job/24423198441
      
    3. login: "gustafn3"
    4. mimetype: "text/plain"
  17. Ticket change [5badc1601b] (rid 225453) by gustafn3 on 2024-04-30 13:26:21:

    1. closedate changed to: "2460431.05996535"
    2. icomment:
      ... when -std=c99 is used. What is the minimal required C version for Tcl?
      
    3. login: "gustafn3"
    4. mimetype: "text/plain"
  18. Ticket change [88d78ec95d] (rid 225454) by gustafn3 on 2024-04-30 13:30:24:

    1. closedate changed to: "2460431.06278168"
    2. icomment:
      I found an answer to my last question.
      
      Tcl/Tk does require an ANSI C C89 compatible compiler.
      https://www.tcl.tk/software/tcltk/platforms.html
      
      Seems as if some more guards are required.
      
    3. login: "gustafn3"
    4. mimetype: "text/plain"
  19. Ticket change [1de5fdf409] (rid 225458) by jan.nijtmans on 2024-04-30 14:05:46:

    1. closedate changed to: "2460431.08734461"
    2. closer changed to: "jan.nijtmans"
    3. icomment:
      Something like [27e88ccf5a512874|this]?
      
      I guess that the original -Wgnu-statement-expression-from-macro-expansion will be back then, unless you switch from -std=c99 to -std=c11
      
    4. login: "jan.nijtmans"
    5. mimetype: "text/x-fossil-wiki"
  20. Ticket change [9e9a0daf99] (rid 225459) by gustafn3 on 2024-04-30 14:07:03:

    1. closer changed to: "nobody"
    2. icomment:
      One can improve the situation when adding "&& __STDC_VERSION__ > 199901L" 
      appended to the first two clauses of the TCLBOOLWARNING macro.
      
      This works without any warnings on recent macOS with and without e.g. -std=c99 (tested with standard macOS compiler and e.g. clang-mp-17).
      
      Compiling with gcc (gcc-mp-12 or gcc-mp-13) leads to an error, but looks to me as a mess-up in the interplay of mac-ports if the newest MacOSX.sdk.
      
    3. login: "gustafn3"
    4. mimetype: "text/plain"
    5. status changed to: "Open"
  21. Ticket change [84c3fae015] (rid 225460) by jan.nijtmans on 2024-04-30 14:07:40:

    1. icomment:
      Starting with Tcl/Tk 8.7, we require C99 as a minimum.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  22. Ticket change [da547bc96a] (rid 225461) by gustafn3 on 2024-05-01 10:19:46:

    1. icomment:
      With the following version of the macro, it compiles clean with and without -std=c99 under Linux (tested with gcc version 12.2.0) and macOS (tested with standard Apple compiler clang-1500.3.9.4 and clang 17.0.6)
      
      #if !defined(__cplusplus) && !defined(BUILD_tcl) && !defined(BUILD_tk) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
      #       define TCLBOOLWARNING(boolPtr) (void)(sizeof(struct {_Static_assert(sizeof(*(boolPtr)) <= sizeof(int), "sizeof(boolPtr) too large");int dummy;})),
      #elif defined(__GNUC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
              /* If this gives: "error: size of array ‘_bool_Var’ is negative", it means that sizeof(*boolPtr)>sizeof(int), which is not allowed */
      #   define TCLBOOLWARNING(boolPtr) ({__attribute__((unused)) char _bool_Var[sizeof(*(boolPtr)) > sizeof(int) ? -1 : 1];}),
      #else
      #   define TCLBOOLWARNING(boolPtr)
      #endif
      
    2. login: "gustafn3"
    3. mimetype: "text/plain"
  23. Ticket change [76da8876fc] (rid 225462) by anonymous on 2024-05-01 17:57:22:

    1. icomment:
      BAWT compiles fine with Gustaf's new macro version on my 7 different Linux test environments. 
      The old macro (as contained in latest b2) generated errors when compiling tclMuPdf on Debian 12.
      
      Paul
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  24. Ticket change [caa60603f5] (rid 225468) by jan.nijtmans on 2024-05-02 08:44:58:

    1. icomment:
      Another attempth [10f1ca98d0145174|here]
      
      I don't think the second check is correct: we want to check here whether the gnu extensions are enabled or not, __STDC_VERSION__ doesn't really help there. The result is now that using -std=c99 actually disables all compile-time checks. We can put in an additional runtime-check as well (which I did now) for this case.
      
      Any idea to check whether the GNU extensions are enabled or not?
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  25. Ticket change [eb5dc1f771] (rid 225470) by gustafn3 on 2024-05-02 09:10:22:

    1. icomment:
      The second one gets rid of the strange warning message in case the code is
      compiled with -std=c99. The goal is a clean compile with paranoia settings. 
      
      One could try to deactivate the warning for this use case (requires pragma PUSH/POP of options), but this adds just more complexity for a job, a compiler should do.
      
    2. login: "gustafn3"
    3. mimetype: "text/plain"
  26. Ticket change [a9e1df5ee5] (rid 225471) by jan.nijtmans on 2024-05-02 09:15:13:

    1. icomment:
      Would [edf316533a466b98|checking for __STRICT_ANSI__] work as well?
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  27. Ticket change [caaffcc8d3] (rid 225497) by jan.nijtmans on 2024-05-02 15:03:51:

    1. icomment:
      Somebody already found the answer:
      
      [https://stackoverflow.com/questions/8656175/how-to-check-that-c99-is-used-and-not-gnu99]
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  28. Ticket change [3c661c1d5c] (rid 225498) by gustafn3 on 2024-05-02 16:51:34:

    1. icomment:
      I can confirm that the code tagged with "bug-1e48483c8b" works without complaints. Many thanks for your patience!
      
    2. login: "gustafn3"
    3. mimetype: "text/plain"
  29. Ticket change [041ad609f6] (rid 225513) by jan.nijtmans on 2024-05-03 11:56:51:

    1. closedate changed to: "2460433.99781788"
    2. closer changed to: "jan.nijtmans"
    3. icomment:
      Now merged to core-8-branch and trunk.
      
      Thanks for the report!
      
    4. login: "jan.nijtmans"
    5. mimetype: "text/x-fossil-wiki"
    6. status changed to: "Closed"
  30. Ticket change [9797e2f550] (rid 225514) by gustafn3 on 2024-05-03 12:17:27:

    1. closedate changed to: "2460434.01212251"
    2. closer changed to: "gustafn3"
    3. icomment:
      Great! The workflow run is now fixed by this:
      https://github.com/naviserver-project/naviserver/actions/runs/8894601239/job/24544555992
      
    4. login: "gustafn3"
    5. mimetype: "text/plain"
  31. Ticket change [d29f239ce1] (rid 225515) by jan.nijtmans on 2024-05-03 12:38:44:

    1. closedate changed to: "2460434.0269095"
    2. closer changed to: "jan.nijtmans"
    3. icomment:
      > The workflow run is now fixed by this:
      
      Not completely ... You didn't adapt the TIP #692 change yet: alias_oc should be changed to Tcl_Size type ;-)
      <pre>
      ./generic/nsf.c: In function ‘GetClassFromObj’:
      ./generic/nsf.c:2244:64: warning: passing argument 5 of ‘tclStubsPtr->tcl_GetAliasObj’ from incompatible pointer type [-Wincompatible-pointer-types]
       2244 |                                &alias_interp, &alias_cmd_name, &alias_oc, &alias_ov);
            |                                                                ^~~~~~~~~
            |                                                                |
            |                                                                int *
      ./generic/nsf.c:2244:64: note: expected ‘Tcl_Size *’ {aka ‘long int *’} but argument is of type ‘int *’
      </pre>
      
      There are more warnings in tcldom and tclexpat, which are not adapted to Tcl 9. yet. Workaround: compile with CFLAGS=-DTCL_8_API
      
    4. login: "jan.nijtmans"
    5. mimetype: "text/x-fossil-wiki"
  32. Ticket change [2bf9484842] (rid 225516) by gustafn3 on 2024-05-03 13:06:46:

    1. closedate changed to: "2460434.04637015"
    2. closer changed to: "gustafn3"
    3. icomment:
      NaviServer compiles now cleanly, but yes, there are still warnings from 
      other optional packages used in this compilation run which should be fixed.
      
      In previous iteration of tcl9, there was an error caused by TCLBOOLWARNING:
      
      adpcmds.c: In function ‘NsTclAdpCtlObjCmd’:
      /usr/local/ns/include/tclDecls.h:4036:62: error: expected specifier-qualifier-list before ‘extern’
       4036 | #       define TCLBOOLWARNING(boolPtr) (void)(sizeof(struct {_Static_assert(sizeof(*(boolPtr)) <= sizeof(int), "sizeof(boolPtr) too large");int dummy;})),
            |                                                              ^~~~~~~~~~~~~~
      /usr/local/ns/include/tclDecls.h:4058:10: note: in expansion of macro ‘TCLBOOLWARNING’
       4058 |         (TCLBOOLWARNING(boolPtr)(sizeof(*(boolPtr)) >= sizeof(int) && (TCL_MAJOR_VERSION == 8)) ? Tcl_GetBooleanFromObj(interp, objPtr, (int *)(boolPtr)) : \
            |          ^~~~~~~~~~~~~~
      adpcmds.c:318:25: note: in expansion of macro ‘Tcl_GetBooleanFromObj’
        318 |                     if (Tcl_GetBooleanFromObj(interp, objv[2], &boolVal) != TCL_OK) {
            |                         ^~~~~~~~~~~~~~~~~~~~~
      make[1]: *** [<builtin>: adpcmds.o] Error 1
      make[1]: *** Waiting for unfinished jobs....
      make[1]: Leaving directory '/home/runner/work/naviserver/naviserver/nsd'
      make: *** [Makefile:34: all] Error 1
      Error: Process completed with exit code 2.
      
      https://github.com/naviserver-project/naviserver/actions/runs/8894601239/job/24436196262
      
    4. login: "gustafn3"
    5. mimetype: "text/plain"