From: Simon Wilkinson Date: Wed, 30 May 2012 17:25:51 +0000 (+0100) Subject: rxgen: Make input strings const X-Git-Tag: upstream/1.8.0_pre1^2~2331 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=ed02c6ff8a4bc2cc82876a4b1736a8985548a71c;p=packages%2Fo%2Fopenafs.git 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 Reviewed-by: Derrick Brashear --- diff --git a/src/libadmin/bos/afs_bosAdmin.c b/src/libadmin/bos/afs_bosAdmin.c index 3d7cf5878..7057d2e9c 100644 --- a/src/libadmin/bos/afs_bosAdmin.c +++ b/src/libadmin/bos/afs_bosAdmin.c @@ -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; diff --git a/src/rxgen/rpc_cout.c b/src/rxgen/rpc_cout.c index 3d8f47578..0ea37744b 100644 --- a/src/rxgen/rpc_cout.c +++ b/src/rxgen/rpc_cout.c @@ -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) { diff --git a/src/rxgen/rpc_hout.c b/src/rxgen/rpc_hout.c index 9df8cf7f8..386db3b03 100644 --- a/src/rxgen/rpc_hout.c +++ b/src/rxgen/rpc_hout.c @@ -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); } diff --git a/src/rxgen/rpc_parse.c b/src/rxgen/rpc_parse.c index 8f73265d3..6e5b93dd8 100644 --- a/src/rxgen/rpc_parse.c +++ b/src/rxgen/rpc_parse.c @@ -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); } } }