aboutsummaryrefslogtreecommitdiff
path: root/c/pl.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-06-02 11:58:14 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-06-02 11:58:14 +0200
commitabb7f3552bf4d4f7ceecd27a1acd344b45ec2454 (patch)
treebd0f8bc12e800956f5cc3c29301dfb43fb1e93cc /c/pl.c
parent3468c68f65e58a65b3c3ec74d73c6c20c2b33a3a (diff)
downloadEpisodeBrowser-abb7f3552bf4d4f7ceecd27a1acd344b45ec2454.tar.gz
Fix va_list bug.
Diffstat (limited to 'c/pl.c')
-rw-r--r--c/pl.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/c/pl.c b/c/pl.c
index 6f7a07d..9a5baee 100644
--- a/c/pl.c
+++ b/c/pl.c
@@ -7,9 +7,10 @@ Pl(char *szMod, char *szPred, char *szFmt, ...)
{
int i, iArity;
term_t t;
- va_list vl;
+ va_list vl, vl2;
va_start(vl, szFmt);
+ va_copy(vl2, vl);
iArity = strlen(szFmt);
t = PL_new_term_refs(iArity);
@@ -19,14 +20,7 @@ Pl(char *szMod, char *szPred, char *szFmt, ...)
{
int x;
x = va_arg(vl, int);
- if (!PL_put_integer(t+i, x)) return 0;
- break;
- }
- case 'A':
- {
- atom_t x;
- x = va_arg(vl, atom_t);
- if (!PL_put_atom(t+i, x)) return 0;
+ if (!PL_put_integer(t+i, x)) goto f;
break;
}
case 'S':
@@ -35,42 +29,51 @@ Pl(char *szMod, char *szPred, char *szFmt, ...)
char *x;
x = va_arg(vl, char *);
a = PL_new_atom(x);
- if (!PL_put_atom(t+i, a)) return 0;
+ if (!PL_put_atom(t+i, a)) goto f;
break;
}
+ case 'i':
+ va_arg(vl, int *);
+ break;
+ case 's':
+ va_arg(vl, char **);
+ break;
}
}
if (!PL_call_predicate(NULL, PL_Q_NORMAL,
PL_predicate(szPred, iArity, szMod), t))
- return 0;
+ goto f;
for (i = 0; szFmt[i]; i++) {
switch (szFmt[i]) {
case 'i':
{
int *lp;
- lp = va_arg(vl, int *);
- if (!PL_get_integer(t+i, lp)) return 0;
- break;
- }
- case 'a':
- {
- atom_t *lp;
- lp = va_arg(vl, atom_t *);
- if (!PL_get_atom(t+i, lp)) return 0;
+ lp = va_arg(vl2, int *);
+ if (!PL_get_integer(t+i, lp)) goto f;
break;
}
case 's':
{
char **lp;
- lp = va_arg(vl, char **);
- if (!PL_get_atom_chars(t+i, lp)) return 0;
+ lp = va_arg(vl2, char **);
+ if (!PL_get_atom_chars(t+i, lp)) goto f;
break;
}
+ case 'I':
+ va_arg(vl2, int);
+ break;
+ case 'S':
+ va_arg(vl2, char *);
+ break;
}
}
va_end(vl);
+ va_end(vl2);
return 1;
+f: va_end(vl);
+ va_end(vl2);
+ return 0;
}