rxgen: Make input strings const

Modify the code generation routines so that string inputs to RPCs
are declared as (const char *) on the client side. This doesn't affect
callers as we can freely cast from (char *) to (const char *), but means
it is easier to write API wrappers that accept const arguments.

Change-Id: I4719d04f03bd76cbe7ee21ad7511f6f3b3d36163
Reviewed-on: http://gerrit.openafs.org/7556
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
This commit is contained in:
Simon Wilkinson 2012-05-30 18:25:51 +01:00 committed by Derrick Brashear
parent 9b97b80dd8
commit ed02c6ff8a
4 changed files with 31 additions and 19 deletions

View File

@ -590,7 +590,7 @@ bos_ProcessExecutionStateGet(const void *serverHandle,
static int
SetExecutionState(const void *serverHandle, const char *processName,
const bos_ProcessExecutionState_t processStatus,
int (*func) (struct rx_connection *, char *,
int (*func) (struct rx_connection *, const char *,
afs_int32), afs_status_p st)
{
int rc = 0;

View File

@ -519,16 +519,15 @@ print_param(declaration * dec)
} else if (streq(type, "opaque")) {
alt = "opaque";
}
if (alt) {
if (alt)
print_rxifopen(alt);
print_rxifarg(amp, objname, 0);
} else {
else
print_rxifopen("vector");
print_rxifarg(amp, "(char *)", 0);
sprintf(temp, "%s", objname);
strcat(Proc_list->code, temp);
strcat(Proc_list->scode, temp);
}
print_rxifarg(amp, "(char *)", 0);
sprintf(temp, "%s", objname);
strcat(Proc_list->code, temp);
strcat(Proc_list->scode, temp);
print_rxifarg("", amax, 1);
if (!alt) {
print_rxifsizeof(prefix, type);
@ -547,7 +546,7 @@ print_param(declaration * dec)
Proc_list->pl.param_flag |= OUT_STRING;
print_rxifarg("", objname, 0);
} else
print_rxifarg("&", objname, 0);
print_rxifarg("(char **) &", objname, 0);
/* print_rxifarg(amp, objname, 0); */
print_rxifarg("", amax, 1);
if (!alt) {

View File

@ -219,7 +219,7 @@ psproc1(definition * defp, int callTconnF, char *type, char *prefix,
f_print(fout, "\nextern %s %s%s%s(\n", type, prefix, defp->pc.proc_prefix,
defp->pc.proc_name);
if (callTconnF == 1) {
if (callTconnF == 1 || callTconnF == 3) {
f_print(fout, "\t/*IN */ struct rx_call *z_call");
} else if (callTconnF == 2) {
f_print(fout, "\tstruct ubik_client *aclient, afs_int32 aflags");
@ -232,7 +232,10 @@ psproc1(definition * defp, int callTconnF, char *type, char *prefix,
&& (iomask & (1 << plist->pl.param_kind))) {
switch (plist->pl.param_kind) {
case DEF_INPARAM:
f_print(fout, ",\n\t/*IN */ ");
f_print(fout, ",\n\t/*IN %d*/ ",callTconnF);
if ((callTconnF != 3)
&& strcmp(plist->pl.param_type, "char *")== 0)
f_print(fout, "const ");
break;
case DEF_OUTPARAM:
f_print(fout, ",\n\t/*OUT*/ ");
@ -274,7 +277,7 @@ psprocdef(definition * defp)
psproc1(defp, 2, "int", "ubik_", 0xFFFFFFFF);
if (*ServerPrefix)
psproc1(defp, 1, "afs_int32", ServerPrefix, 0xFFFFFFFF);
psproc1(defp, 3, "afs_int32", ServerPrefix, 0xFFFFFFFF);
}

View File

@ -1147,16 +1147,21 @@ cs_ProcName_setup(definition * defp, char *procheader, int split_flag)
if (!cflag) {
for (plist = defp->pc.plists; plist; plist = plist->next) {
if (plist->component_kind == DEF_PARAM) {
f_print(fout, ",");
if (ansic_flag) {
if (plist->pl.param_kind == DEF_INPARAM &&
strcmp(plist->pl.param_type, "char *") == 0) {
f_print(fout, "const ");
}
if (plist->pl.param_flag & OUT_STRING) {
f_print(fout, ",%s *%s", plist->pl.param_type,
f_print(fout, "%s *%s", plist->pl.param_type,
plist->pl.param_name);
} else {
f_print(fout, ",%s %s", plist->pl.param_type,
f_print(fout, "%s %s", plist->pl.param_type,
plist->pl.param_name);
}
} else {
f_print(fout, ", %s", plist->pl.param_name);
f_print(fout, " %s", plist->pl.param_name);
plist->pl.param_flag &= ~PROCESSED_PARAM;
}
}
@ -1735,17 +1740,22 @@ ucs_ProcName_setup(definition * defp, char *procheader, int split_flag)
if (!cflag) {
for (plist = defp->pc.plists; plist; plist = plist->next) {
if (plist->component_kind == DEF_PARAM) {
f_print(fout, ",");
if (ansic_flag) {
if (plist->pl.param_kind == DEF_INPARAM &&
strcmp(plist->pl.param_type, "char *") == 0) {
f_print(fout, "const ");
}
if (plist->pl.param_flag & OUT_STRING) {
f_print(fout, ",%s *%s", plist->pl.param_type,
f_print(fout, "%s *%s", plist->pl.param_type,
plist->pl.param_name);
} else {
f_print(fout, ",%s %s", plist->pl.param_type,
f_print(fout, "%s %s", plist->pl.param_type,
plist->pl.param_name);
}
} else {
plist->pl.param_flag &= ~PROCESSED_PARAM;
f_print(fout, ", %s", plist->pl.param_name);
f_print(fout, " %s", plist->pl.param_name);
}
}
}