Lookup() constify call-site with Tcl_SetResult()

ext2spice/ext2spice.c: Lookup() constify call-site
ext2sim/ext2sim.c: Lookup() constify call-site
windows/windCmdAM.c: Lookup() constify call-site

Tcl_SetResult() uses cast to remove 'const' from type, the pointer
is only used to take a copy of the data, the lack of 'const' is due
to Tcl heritage when supporting C89 era compilers.

TCL9 appears to fix this, in that the macro used ends up at
Tcl_NewStringObj() which has 'const' here.
This commit is contained in:
Darryl L. Miles 2024-10-10 20:16:09 +01:00 committed by Tim Edwards
parent a3dce62887
commit 882d82a8ae
3 changed files with 25 additions and 23 deletions

View File

@ -264,7 +264,7 @@ CmdExtToSim(w, cmd)
int option = EXTTOSIM_RUN;
int argc = cmd->tx_argc;
char **argv = cmd->tx_argv;
char **msg;
const char * const *msg;
bool err_result;
short s_rclass, d_rclass, sub_rclass;
@ -276,7 +276,7 @@ CmdExtToSim(w, cmd)
static EFCapValue LocCapThreshold = 2;
static int LocResistThreshold = 10;
static char *cmdExtToSimOption[] = {
static const char * const cmdExtToSimOption[] = {
"[run] [options] run exttosim on current cell\n"
" use \"run -help\" to get standard options",
"alias on|off enable/disable alias (.al) file",
@ -291,14 +291,14 @@ CmdExtToSim(w, cmd)
NULL
};
static char *sim_formats[] = {
static const char * const sim_formats[] = {
"MIT",
"LBL",
"SU",
NULL
};
static char *yesno[] = {
static const char * const yesno[] = {
"yes",
"true",
"on",
@ -308,7 +308,7 @@ CmdExtToSim(w, cmd)
NULL
};
static char *cmdMergeTypes[] = {
static const char * const cmdMergeTypes[] = {
"none don't merge parallel devices",
"conservative merge devices with same L, W",
"aggressive merge devices with same L"
@ -430,7 +430,7 @@ CmdExtToSim(w, cmd)
if (cmd->tx_argc == 2)
{
#ifdef MAGIC_WRAPPER
Tcl_SetResult(magicinterp, sim_formats[esFormat], TCL_STATIC);
Tcl_SetResult(magicinterp, (char*)sim_formats[esFormat], TCL_STATIC);
#else
TxPrintf("Format: %s\n", sim_formats[esFormat]);
#endif

View File

@ -269,7 +269,7 @@ CmdExtToSpice(w, cmd)
int option = EXTTOSPC_RUN;
int argc = cmd->tx_argc;
char **argv = cmd->tx_argv;
char **msg;
const char * const *msg;
char *resstr = NULL;
char *substr = NULL;
bool err_result, locDoSubckt;
@ -284,11 +284,11 @@ CmdExtToSpice(w, cmd)
static EFCapValue LocCapThreshold = 2;
static int LocResistThreshold = INFINITE_THRESHOLD;
static char *spiceFormats[] = {
static const char * const spiceFormats[] = {
"SPICE2", "SPICE3", "HSPICE", "NGSPICE", NULL
};
static char *cmdExtToSpcOption[] = {
static const char * const cmdExtToSpcOption[] = {
"[run] [options] run exttospice on current cell\n"
" use \"run -help\" to get standard options",
"default reset to default values",
@ -313,20 +313,20 @@ CmdExtToSpice(w, cmd)
NULL
};
static char *cmdMergeTypes[] = {
static const char * const cmdMergeTypes[] = {
"none don't merge parallel devices",
"conservative merge devices with same L, W",
"aggressive merge devices with same L",
NULL
};
static char *cmdShortTypes[] = {
static const char * const cmdShortTypes[] = {
"none merge shorted ports",
"resistor separate shorted ports with 0 ohm resistor",
"voltage separate shorted ports with 0 volt source",
NULL
};
static char *cmdExtToSpcFormat[] = {
static const char * const cmdExtToSpcFormat[] = {
"spice2",
"spice3",
"hspice",
@ -334,7 +334,7 @@ CmdExtToSpice(w, cmd)
NULL
};
static char *yesno[] = {
static const char * const yesno[] = {
"yes",
"true",
"on",
@ -344,7 +344,7 @@ CmdExtToSpice(w, cmd)
NULL
};
static char *subcktopts[] = {
static const char * const subcktopts[] = {
"yes",
"true",
"on",
@ -357,7 +357,7 @@ CmdExtToSpice(w, cmd)
NULL
};
static char *shorttypes[] = {
static const char * const shorttypes[] = {
"none",
"resistor",
"voltage",
@ -649,7 +649,8 @@ CmdExtToSpice(w, cmd)
if (cmd->tx_argc == 2)
{
#ifdef MAGIC_WRAPPER
Tcl_SetResult(magicinterp, cmdExtToSpcFormat[esFormat], NULL);
/* FIXME check NULL is ok here, should this be TCL_STATIC ? TCL_STATIC==0 maybe using TCL_STATIC is better? */
Tcl_SetResult(magicinterp, (char*)cmdExtToSpcFormat[esFormat], NULL);
#else
TxPrintf("Format: %s\n", cmdExtToSpcFormat[esFormat]);
#endif
@ -1181,7 +1182,7 @@ main(argc, argv)
esSpiceDevsMerged = 0;
static char *spiceFormats[] = {
static const char * const spiceFormats[] = {
"SPICE2", "SPICE3", "HSPICE", "NGSPICE", NULL
};

View File

@ -82,8 +82,8 @@ windBorderCmd(w, cmd)
{
int place;
bool value;
static char *onoff[] = {"on", "off", 0};
static bool truth[] = {TRUE, FALSE};
static const char * const onoff[] = {"on", "off", 0};
static const bool truth[] = {TRUE, FALSE};
if (cmd->tx_argc > 2) goto usage;
else if (cmd->tx_argc == 1)
@ -97,7 +97,8 @@ windBorderCmd(w, cmd)
value = (w->w_flags & WIND_BORDER) ? 0 : 1;
#ifdef MAGIC_WRAPPER
Tcl_SetResult(magicinterp, onoff[value], TCL_STATIC);
/* this cast to remove const is ok, TCL_STATIC conveys the storage handling of this string */
Tcl_SetResult(magicinterp, (char *)onoff[value], TCL_STATIC);
#else
TxPrintf("Window border is %s\n", onoff[value]);
#endif
@ -151,8 +152,8 @@ windCaptionCmd(w, cmd)
{
int place;
Rect ts;
static char *onoff[] = {"on", "off", 0};
static bool truth[] = {TRUE, FALSE};
static const char * const onoff[] = {"on", "off", 0};
static const bool truth[] = {TRUE, FALSE};
if (cmd->tx_argc > 2) goto usage;
else if (cmd->tx_argc == 1)
@ -903,7 +904,7 @@ windLogCommandsCmd(w, cmd)
unsigned char flags = 0;
int idx = LOG_CMD_STOP;
static char *logKeywords[] = {"start", "stop", "update", "suspend", "resume", 0};
static const char * const logKeywords[] = {"start", "stop", "update", "suspend", "resume", 0};
if ((cmd->tx_argc < 1) || (cmd->tx_argc > 3)) goto usage;