Tcl Source Code

View Ticket
Login
Ticket UUID: ef23a85ac6bab7d4f2cdb1eb1a03d23bb2e5b289
Title: Tcl_PanicProc - Tcl9 & NaviServer
Type: Bug Version: 9.0b2
Submitter: mookie Created on: 2024-04-22 23:45:54
Subsystem: 69. Other Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2024-04-25 19:07:08
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2024-04-25 19:07:08
Description:
Hi Core,

In attempt of using NaviServer with TCL9.0x -- a module for the server fails, log.c when compiling against TCL9.

OS: FreeBSD 14
TCL: 9.0b1/b2
NaviServer: 4.99 (pre-fix)

After reaching out to Gustaf, dev of NaviServer, a hot-patch has been created.

His explanation:

The issue is that Tcl_PanicProc is defined in Tcl9 with the attribute declaration TCL_NORETURN1, but it seems, this attribute definition has to be provided as well for the prototype. It would be certainly better, if this attribute definition would be part of the type declaration of Tcl_PanicProc in Tcl9. Not very long ago, the same code worked fine, so something has changed in Tcl9.

The patch below addresses this issue, but this is not nice. Maybe, the tcl-core people have a suggestion, since this will effect as well other applications requiring the use of Tcl_SetPanicProc().

Compilation error:

> log.c:262:22: error: incompatible function pointer types passing 'Tcl_PanicProc' (aka 'void (const char *, ...)') to parameter of type 'void (*)(const char *, ...) __attribute__((noreturn))' [-Wincompatible-function-pointer-types]
     Tcl_SetPanicProc(Panic);
                    ^~~~~
 /usr/local/include/tcl.h:2366:37: note: passing argument to parameter 'panicProc' here
                         TCL_NORETURN1 Tcl_PanicProc *panicProc);

NaviServer Issue: https://sourceforge.net/p/naviserver/mailman/message/58763387/

Source to patched log.c: https://github.com/naviserver-project/naviserver/commit/c96c143ac2c7a88b99f8c32e7d140019fe5e7629

Many Thanks,
David F
User Comments: jan.nijtmans added on 2024-04-25 19:07:08:

Thanks for confirming that it works! Closing.


gustafn3 added on 2024-04-25 17:21:01:
I tested with the new version. Everything is still fine.

Btw, the original issue was a compiler error, not a warning. Maybe, raising and error instead of a warning depends on the used compiler and version. 

I am still wondering why nobody else noted this. Everyone calling Tcl_SetPanicProc() was effected by this issue.

jan.nijtmans added on 2024-04-25 15:10:46:

Should be fixed [b95cc2b450d1f6dd|here]

> The version in branch bug-ef23a85ac6 fixes the issue.

Unfortunately, the earlier fix caused warnings on Linux:

/home/runner/work/tcl/tcl/generic/tcl.h:600:1: warning: ‘noreturn’ attribute ignored [-Wattributes]
  600 | typedef TCL_NORETURN1 void (Tcl_PanicProc) (const char *format, ...);
      | ^~~~~~~
which can be seen in the GITHUB build: https://github.com/tcltk/tcl/actions/runs/8812574046/job/24188518470

The best solution, it turns out, is no longer use the `TCL_NORETURN1` option when setting/getting exitproc/panicproc functions, but let `Tcl_Panic()` handle all of this. If the user provides a `TCL_NORETURN` function as panicproc, that's fine. If the user doesn't do that, but provides a function which returns, then `Tcl_Panic()` will handle the last part of exiting.

This way, I think, solves the NaviServer warning, and it handles everything I can think of.

Thanks for the report!


gustafn3 added on 2024-04-24 09:03:14:
The version in branch bug-ef23a85ac6 fixes the issue.
Putting the declaration into the type is the right thing.