Tk Source Code

View Ticket
Login
Ticket UUID: d96974d99d72955f0f2f799a49be0b62c22c5b62
Title: Functions passed to Tcl_EventuallyFree() must be declared/defined as Tcl_FreeProc
Type: Patch Version: 8.6.13
Submitter: chrstphrchvz Created on: 2023-10-10 10:03:13
Subsystem: 81. Portability Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2023-12-01 16:09:49
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2023-12-01 16:09:49
Description:

As described in https://core.tcl-lang.org/tcl/info/8ab8a138c915

Aside from the attached patch, which mostly undoes [9279332cf22a] and [4854aa119bd0], there is one more instance to address in tkImage.c, but I would first like to understand why DeleteImage() is not consistently used as a Tcl_FreeProc (via Tcl_EventuallyFree()).

User Comments: chrstphrchvz added on 2023-10-25 14:38:01:

Sorry, those warnings/errors were because I tried building with outdated Tcl 8.7 (from before https://core.tcl-lang.org/tcl/info/56cb488cc3d4).


chrstphrchvz added on 2023-10-25 14:18:39:

Don, I assume you are building with Tcl 8.7. There are warnings for Tk 8.7 + Tcl 8.7 which by default are errors in LLVM.org Clang 16. Examples:

tk87ontcl87/generic/tkBusy.c:140:33: error: incompatible function pointer types passing 'void (void *)' to parameter of type 'Tcl_FreeProc *' (aka 'void (*)(char *)') [-Wincompatible-function-pointer-types]
  140 |     Tcl_EventuallyFree(busyPtr, DestroyBusy);
      |                                 ^~~~~~~~~~~
tk87ontcl87/generic/tkBusy.c:265:30: error: incompatible function pointer types passing 'void (void *)' to parameter of type 'Tcl_FreeProc *' (aka 'void (*)(char *)') [-Wincompatible-function-pointer-types]
  265 |         Tcl_EventuallyFree(busyPtr, DestroyBusy);
      |                                     ^~~~~~~~~~~
tk87ontcl87/generic/tkBusy.c:386:30: error: incompatible function pointer types passing 'void (void *)' to parameter of type 'Tcl_FreeProc *' (aka 'void (*)(char *)') [-Wincompatible-function-pointer-types]
  386 |         Tcl_EventuallyFree(busyPtr, DestroyBusy);
      |                                     ^~~~~~~~~~~
tk87ontcl87/generic/tkBusy.c:921:30: error: incompatible function pointer types passing 'void (void *)' to parameter of type 'Tcl_FreeProc *' (aka 'void (*)(char *)') [-Wincompatible-function-pointer-types]
  921 |         Tcl_EventuallyFree(busyPtr, DestroyBusy);
      |                                     ^~~~~~~~~~~


dgp added on 2023-10-25 13:27:45:
Testing the Tk trunk today I see many compiler warnings that
appear to be about this issue.

chrstphrchvz added on 2023-10-11 13:30:07:

For reference: in the Tcl ticket, the issue of compatibility with both Tcl 8 and 9 had been brought up; and there has since been discussion of shortcomings of the originally proposed fixes like [12043dec2720]—revising ticket name accordingly.

Note that in tkSquare.c and ttkWidget.c, the relevant function only calls ckfree(). In my patch, I assumed it was preferable to remove those functions and use TCL_DYNAMIC instead.


jan.nijtmans added on 2023-10-10 11:32:23:

Hi Christofer.

Your patch will work for Tcl 8.6, but the same approach would not work in Tk 8.7 when compiled with Tcl 9.0. Therefore, what I would like to do now is [12043dec272011fd|this].

This approach means that all functions use a (void *) parameter. When used with Tcl 9.0, the type-cast won't be necessary any more, but - hopelully - this way the -fsanitize=function message will be surpressed as well.

Thanks!


Attachments: