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-12-26 15:20:58 -05:00
committed by Tim Edwards
parent a3dce62887
commit 882d82a8ae
3 changed files with 25 additions and 23 deletions
+6 -6
View File
@@ -264,7 +264,7 @@ CmdExtToSim(w, cmd)
int option = EXTTOSIM_RUN; int option = EXTTOSIM_RUN;
int argc = cmd->tx_argc; int argc = cmd->tx_argc;
char **argv = cmd->tx_argv; char **argv = cmd->tx_argv;
char **msg; const char * const *msg;
bool err_result; bool err_result;
short s_rclass, d_rclass, sub_rclass; short s_rclass, d_rclass, sub_rclass;
@@ -276,7 +276,7 @@ CmdExtToSim(w, cmd)
static EFCapValue LocCapThreshold = 2; static EFCapValue LocCapThreshold = 2;
static int LocResistThreshold = 10; static int LocResistThreshold = 10;
static char *cmdExtToSimOption[] = { static const char * const cmdExtToSimOption[] = {
"[run] [options] run exttosim on current cell\n" "[run] [options] run exttosim on current cell\n"
" use \"run -help\" to get standard options", " use \"run -help\" to get standard options",
"alias on|off enable/disable alias (.al) file", "alias on|off enable/disable alias (.al) file",
@@ -291,14 +291,14 @@ CmdExtToSim(w, cmd)
NULL NULL
}; };
static char *sim_formats[] = { static const char * const sim_formats[] = {
"MIT", "MIT",
"LBL", "LBL",
"SU", "SU",
NULL NULL
}; };
static char *yesno[] = { static const char * const yesno[] = {
"yes", "yes",
"true", "true",
"on", "on",
@@ -308,7 +308,7 @@ CmdExtToSim(w, cmd)
NULL NULL
}; };
static char *cmdMergeTypes[] = { static const char * const cmdMergeTypes[] = {
"none don't merge parallel devices", "none don't merge parallel devices",
"conservative merge devices with same L, W", "conservative merge devices with same L, W",
"aggressive merge devices with same L" "aggressive merge devices with same L"
@@ -430,7 +430,7 @@ CmdExtToSim(w, cmd)
if (cmd->tx_argc == 2) if (cmd->tx_argc == 2)
{ {
#ifdef MAGIC_WRAPPER #ifdef MAGIC_WRAPPER
Tcl_SetResult(magicinterp, sim_formats[esFormat], TCL_STATIC); Tcl_SetResult(magicinterp, (char*)sim_formats[esFormat], TCL_STATIC);
#else #else
TxPrintf("Format: %s\n", sim_formats[esFormat]); TxPrintf("Format: %s\n", sim_formats[esFormat]);
#endif #endif
+12 -11
View File
@@ -269,7 +269,7 @@ CmdExtToSpice(w, cmd)
int option = EXTTOSPC_RUN; int option = EXTTOSPC_RUN;
int argc = cmd->tx_argc; int argc = cmd->tx_argc;
char **argv = cmd->tx_argv; char **argv = cmd->tx_argv;
char **msg; const char * const *msg;
char *resstr = NULL; char *resstr = NULL;
char *substr = NULL; char *substr = NULL;
bool err_result, locDoSubckt; bool err_result, locDoSubckt;
@@ -284,11 +284,11 @@ CmdExtToSpice(w, cmd)
static EFCapValue LocCapThreshold = 2; static EFCapValue LocCapThreshold = 2;
static int LocResistThreshold = INFINITE_THRESHOLD; static int LocResistThreshold = INFINITE_THRESHOLD;
static char *spiceFormats[] = { static const char * const spiceFormats[] = {
"SPICE2", "SPICE3", "HSPICE", "NGSPICE", NULL "SPICE2", "SPICE3", "HSPICE", "NGSPICE", NULL
}; };
static char *cmdExtToSpcOption[] = { static const char * const cmdExtToSpcOption[] = {
"[run] [options] run exttospice on current cell\n" "[run] [options] run exttospice on current cell\n"
" use \"run -help\" to get standard options", " use \"run -help\" to get standard options",
"default reset to default values", "default reset to default values",
@@ -313,20 +313,20 @@ CmdExtToSpice(w, cmd)
NULL NULL
}; };
static char *cmdMergeTypes[] = { static const char * const cmdMergeTypes[] = {
"none don't merge parallel devices", "none don't merge parallel devices",
"conservative merge devices with same L, W", "conservative merge devices with same L, W",
"aggressive merge devices with same L", "aggressive merge devices with same L",
NULL NULL
}; };
static char *cmdShortTypes[] = { static const char * const cmdShortTypes[] = {
"none merge shorted ports", "none merge shorted ports",
"resistor separate shorted ports with 0 ohm resistor", "resistor separate shorted ports with 0 ohm resistor",
"voltage separate shorted ports with 0 volt source", "voltage separate shorted ports with 0 volt source",
NULL NULL
}; };
static char *cmdExtToSpcFormat[] = { static const char * const cmdExtToSpcFormat[] = {
"spice2", "spice2",
"spice3", "spice3",
"hspice", "hspice",
@@ -334,7 +334,7 @@ CmdExtToSpice(w, cmd)
NULL NULL
}; };
static char *yesno[] = { static const char * const yesno[] = {
"yes", "yes",
"true", "true",
"on", "on",
@@ -344,7 +344,7 @@ CmdExtToSpice(w, cmd)
NULL NULL
}; };
static char *subcktopts[] = { static const char * const subcktopts[] = {
"yes", "yes",
"true", "true",
"on", "on",
@@ -357,7 +357,7 @@ CmdExtToSpice(w, cmd)
NULL NULL
}; };
static char *shorttypes[] = { static const char * const shorttypes[] = {
"none", "none",
"resistor", "resistor",
"voltage", "voltage",
@@ -649,7 +649,8 @@ CmdExtToSpice(w, cmd)
if (cmd->tx_argc == 2) if (cmd->tx_argc == 2)
{ {
#ifdef MAGIC_WRAPPER #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 #else
TxPrintf("Format: %s\n", cmdExtToSpcFormat[esFormat]); TxPrintf("Format: %s\n", cmdExtToSpcFormat[esFormat]);
#endif #endif
@@ -1181,7 +1182,7 @@ main(argc, argv)
esSpiceDevsMerged = 0; esSpiceDevsMerged = 0;
static char *spiceFormats[] = { static const char * const spiceFormats[] = {
"SPICE2", "SPICE3", "HSPICE", "NGSPICE", NULL "SPICE2", "SPICE3", "HSPICE", "NGSPICE", NULL
}; };
+7 -6
View File
@@ -82,8 +82,8 @@ windBorderCmd(w, cmd)
{ {
int place; int place;
bool value; bool value;
static char *onoff[] = {"on", "off", 0}; static const char * const onoff[] = {"on", "off", 0};
static bool truth[] = {TRUE, FALSE}; static const bool truth[] = {TRUE, FALSE};
if (cmd->tx_argc > 2) goto usage; if (cmd->tx_argc > 2) goto usage;
else if (cmd->tx_argc == 1) else if (cmd->tx_argc == 1)
@@ -97,7 +97,8 @@ windBorderCmd(w, cmd)
value = (w->w_flags & WIND_BORDER) ? 0 : 1; value = (w->w_flags & WIND_BORDER) ? 0 : 1;
#ifdef MAGIC_WRAPPER #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 #else
TxPrintf("Window border is %s\n", onoff[value]); TxPrintf("Window border is %s\n", onoff[value]);
#endif #endif
@@ -151,8 +152,8 @@ windCaptionCmd(w, cmd)
{ {
int place; int place;
Rect ts; Rect ts;
static char *onoff[] = {"on", "off", 0}; static const char * const onoff[] = {"on", "off", 0};
static bool truth[] = {TRUE, FALSE}; static const bool truth[] = {TRUE, FALSE};
if (cmd->tx_argc > 2) goto usage; if (cmd->tx_argc > 2) goto usage;
else if (cmd->tx_argc == 1) else if (cmd->tx_argc == 1)
@@ -903,7 +904,7 @@ windLogCommandsCmd(w, cmd)
unsigned char flags = 0; unsigned char flags = 0;
int idx = LOG_CMD_STOP; 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; if ((cmd->tx_argc < 1) || (cmd->tx_argc > 3)) goto usage;