[m-rev.] Fwd: for review: fix obsolete tcl-tk code in extras/graphics/mercury_tcltk

Julien Fischer jfischer at opturion.com
Wed Jan 5 17:57:58 AEDT 2022


Hi Fabrice,

On Wed, 5 Jan 2022, Fabrice Nicol wrote:

> As a modest proposal for review by anyone.
>
> ----------------------------------------------------------
>
> Bug issue (fixed): building libmercury_tcltk crashes with current tcl-tk 
> releases (8.6+).
>
> As a consequence, samples/calc cannot be built either.

...

> diff --git a/extras/graphics/mercury_tcltk/mtcltk.m b/extras/graphics/mercury_tcltk/mtcltk.m
> index 483f89c82..238a26cdc 100644
> --- a/extras/graphics/mercury_tcltk/mtcltk.m
> +++ b/extras/graphics/mercury_tcltk/mtcltk.m
> @@ -224,7 +224,7 @@ Tcl_AppInit(Tcl_Interp *interp)
>              MR_fatal_error(""Tcl_Eval returned neither TCL_OK or TCL_ERROR"");
>      }
> 
> -    Result = mtcltk_strdup(Interp->result);
> +    Result = mtcltk_strdup(Tcl_GetStringResult(Interp));
>  ").
>
>  :- pragma foreign_code("C", "
> @@ -284,8 +284,9 @@ mtcltk_do_callback(ClientData clientData, Tcl_Interp *interp,
>              (MR_Word) args);
>      }
> 
> +    char* s = Tcl_GetStringResult(interp);
>      mtcltk_call_mercury_closure((MR_Word) clientData, interp,
> -        args, &status, &interp->result);
> +        args, &status, &s);

That second part doesn't look correct.
The call to mtcltk_call_mercury_closure() sets 's' to point to a string
(i.e. it's an output argument) and this code should _set_ interp->result
to that string.  So rather than calling Tcl_GetStringResults() before
the call, I think there should be a call to Tcl_SetResult() or
Tcl_SetObjResult() somewhere after it.

Julien.


More information about the reviews mailing list