From: Michael Wallner Date: Mon, 4 Jan 2016 16:38:15 +0000 (+0100) Subject: stdio vararg decls X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=0e6d6d0bdaf5cca59d04a8f4e9fcca8a65f341d8;p=m6w6%2Fext-psi stdio vararg decls --- diff --git a/config.m4 b/config.m4 index e7d1e1f..cce2aff 100644 --- a/config.m4 +++ b/config.m4 @@ -71,6 +71,8 @@ if test "$PHP_PSI" != no; then AC_DEFINE_UNQUOTED([PSI_MACROS], [$PSI_MACROS], [Redirected Macros]) AC_DEFINE_UNQUOTED([PSI_REDIRS], [$PSI_REDIRS], [Redirected functions]) AC_DEFINE_UNQUOTED([PSI_DECLS], [$PSI_DECLS], [Predefined functions]) + AC_DEFINE_UNQUOTED([PSI_VA_DECLS], [$PSI_VA_DECLS], [Predefined vararg functions]) + PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src) PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src) diff --git a/m4/psi.m4 b/m4/psi.m4 index ff483bf..4f09851 100644 --- a/m4/psi.m4 +++ b/m4/psi.m4 @@ -4,6 +4,7 @@ PSI_CONSTS= PSI_REDIRS= PSI_MACROS= PSI_DECLS= +PSI_VA_DECLS= psi_includes() { local have_ diff --git a/m4/psi_decl.m4 b/m4/psi_decl.m4 index 3bc2558..69f8edb 100644 --- a/m4/psi_decl.m4 +++ b/m4/psi_decl.m4 @@ -51,7 +51,7 @@ AC_DEFUN(PSI_DECL_ARG, [ psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]" ]) -dnl PSI_DECL(type func, args) +dnl PSI_DECL(type func, args, flags) AC_DEFUN(PSI_DECL, [ psi_decl_args= PSI_DECL_ARG($1) @@ -60,9 +60,14 @@ AC_DEFUN(PSI_DECL, [ [()], [], [m4_map_args_sep([PSI_DECL_ARG(m4_normalize(], [))], [], m4_bregexp([$2], [(\(.*\))], [\1]))]) PSI_FUNC(PSI_VAR_NAME($1), [ - PSI_DECLS="$psi_decl_args, {0}, $PSI_DECLS" + ifelse([$3], vararg, [ + PSI_VA_DECLS="$psi_decl_args, {0}, $PSI_VA_DECLS" + ], [ + PSI_DECLS="$psi_decl_args, {0}, $PSI_DECLS" + ]) ], [ PSI_MACRO($1, $2, [ + ifelse([$3], vararg, AC_MSG_ERROR(varargs macro support is not implemented),[]) PSI_DECLS="$psi_decl_args, {0}, $PSI_DECLS" ]) ]) diff --git a/m4/stdio.m4 b/m4/stdio.m4 index a6f8a2e..82aaa1b 100644 --- a/m4/stdio.m4 +++ b/m4/stdio.m4 @@ -71,5 +71,13 @@ AC_DEFUN(PSI_CHECK_STDIO, [ PSI_DECL(FILE *tmpfile, [(void)]) PSI_DECL(char *tmpnam, [(char *s)]) PSI_DECL(int ungetc, [(int c, FILE *stream)]) - + + PSI_DECL(int dprintf, [(int fd, char *fmt)], vararg) + PSI_DECL(int fprintf, [(FILE *stream, char *fmt)], vararg) + PSI_DECL(int fscanf, [(FILE *stream, char *fmt)], vararg) + PSI_DECL(int printf, [(char *fmt)], vararg) + PSI_DECL(int scanf, [(char *fmt)], vararg) + PSI_DECL(int snprintf, [(char *str, size_t size, char *fmt)], vararg) + PSI_DECL(int sprintf, [(char *str, char *fmt)], vararg) + PSI_DECL(int sscanf, [(char *str, char *fmt)], vararg) ]) diff --git a/psi.d/stdio.psi b/psi.d/stdio.psi index 1e136ce..0741874 100644 --- a/psi.d/stdio.psi +++ b/psi.d/stdio.psi @@ -65,7 +65,7 @@ function psi\rewind(object $stream) : void { return void(rewind); } -extern int printf(const char *fmt, ...); +//extern int printf(const char *fmt, ...); function psi\printf(string $fmt, mixed ...$args) : int { let fmt = strval($fmt); return to_int(printf); diff --git a/src/context.c b/src/context.c index b07b653..3b5c734 100644 --- a/src/context.c +++ b/src/context.c @@ -180,6 +180,10 @@ static struct psi_predef_decl { PSI_DECLS {0} }; +static struct psi_predef_decl psi_predef_vararg_decls[] = { + PSI_VA_DECLS + {0} +}; static struct psi_predef_struct { token_t type_tag; @@ -992,6 +996,24 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr decl_args *args = init_decl_args(NULL); decl *decl = init_decl(init_decl_abi("default"), func, args); + for (farg = &predef_decl[1]; farg->type_tag; ++farg) { + decl_type *arg_type = init_decl_type(farg->type_tag, farg->type_name); + decl_var *arg_var = init_decl_var(farg->var_name, farg->pointer_level, farg->array_size); + decl_arg *darg = init_decl_arg(arg_type, arg_var); + args = add_decl_arg(args, darg); + } + + T.decls = add_decl(T.decls, decl); + predef_decl = farg; + } + + for (predef_decl = &psi_predef_vararg_decls[0]; predef_decl->type_tag; ++predef_decl) { + struct psi_predef_decl *farg; + decl_type *ftype = init_decl_type(predef_decl->type_tag, predef_decl->type_name); + decl_var *fname = init_decl_var(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size); + decl_arg *func = init_decl_arg(ftype, fname); + decl_args *args = init_decl_args(NULL); + decl *decl = init_decl(init_decl_abi("default"), func, args); for (farg = &predef_decl[1]; farg->type_tag; ++farg) { decl_type *arg_type = init_decl_type(farg->type_tag, farg->type_name); @@ -999,6 +1021,7 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr decl_arg *darg = init_decl_arg(arg_type, arg_var); args = add_decl_arg(args, darg); } + args->varargs = 1; T.decls = add_decl(T.decls, decl); predef_decl = farg;