From b4508f6b917660970f887894a6aaed6c220a2c72 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 26 Nov 2015 08:33:09 +0100 Subject: [PATCH] flush --- config.m4 | 63 ++++-- config.psi_macro.m4 | 39 ---- config.psi_struct.m4 | 38 ---- .../ax_check_sign.m4 | 0 config.psi_errno.m4 => m4/errno.m4 | 4 +- config.psi_glob.m4 => m4/glob.m4 | 0 config.psi.m4 => m4/psi.m4 | 7 + config.psi_const.m4 => m4/psi_const.m4 | 1 - config.psi_decl.m4 => m4/psi_decl.m4 | 33 +-- m4/psi_macro.m4 | 26 +++ m4/psi_struct.m4 | 30 +++ config.psi_type.m4 => m4/psi_type.m4 | 11 +- config.psi_stddef.m4 => m4/stddef.m4 | 0 config.psi_stdint.m4 => m4/stdint.m4 | 0 config.psi_stdio.m4 => m4/stdio.m4 | 0 m4/stdlib.m4 | 60 ++++++ m4/sys_stat.m4 | 83 ++++++++ m4/sys_time.m4 | 26 +++ m4/sys_times.m4 | 12 ++ config.psi_sys_types.m4 => m4/sys_types.m4 | 0 m4/sys_uio.m4 | 11 + m4/time.m4 | 59 +++++ m4/wchar.m4 | 9 + php_psi.h | 5 + psi.d/glob.psi | 7 +- psi.d/stat.psi | 1 - psi.d/time.psi | 9 +- src/context.c | 201 +++++++++++------- src/module.c | 2 +- 29 files changed, 531 insertions(+), 206 deletions(-) delete mode 100644 config.psi_macro.m4 delete mode 100644 config.psi_struct.m4 rename config.ax_check_sign.m4 => m4/ax_check_sign.m4 (100%) rename config.psi_errno.m4 => m4/errno.m4 (98%) rename config.psi_glob.m4 => m4/glob.m4 (100%) rename config.psi.m4 => m4/psi.m4 (97%) rename config.psi_const.m4 => m4/psi_const.m4 (98%) rename config.psi_decl.m4 => m4/psi_decl.m4 (60%) create mode 100644 m4/psi_macro.m4 create mode 100644 m4/psi_struct.m4 rename config.psi_type.m4 => m4/psi_type.m4 (88%) rename config.psi_stddef.m4 => m4/stddef.m4 (100%) rename config.psi_stdint.m4 => m4/stdint.m4 (100%) rename config.psi_stdio.m4 => m4/stdio.m4 (100%) create mode 100644 m4/stdlib.m4 create mode 100644 m4/sys_stat.m4 create mode 100644 m4/sys_time.m4 create mode 100644 m4/sys_times.m4 rename config.psi_sys_types.m4 => m4/sys_types.m4 (100%) create mode 100644 m4/sys_uio.m4 create mode 100644 m4/time.m4 create mode 100644 m4/wchar.m4 diff --git a/config.m4 b/config.m4 index 1207c0c..c4eb578 100644 --- a/config.m4 +++ b/config.m4 @@ -7,21 +7,32 @@ if test "$PHP_PSI" != no; then PHP_PSI_SRCDIR=PHP_EXT_SRCDIR(psi) PHP_PSI_BUILDDIR=PHP_EXT_BUILDDIR(psi) - sinclude(config.ax_check_sign.m4) - sinclude(config.psi.m4) - sinclude(config.psi_type.m4) - sinclude(config.psi_const.m4) - sinclude(config.psi_decl.m4) - sinclude(config.psi_macro.m4) - sinclude(config.psi_struct.m4) - - sinclude(config.psi_errno.m4) - sinclude(config.psi_glob.m4) - sinclude(config.psi_stddef.m4) - sinclude(config.psi_stdio.m4) - sinclude(config.psi_stdint.m4) - sinclude(config.psi_sys_types.m4) - + m4_foreach(incfile, [ + [ax_check_sign.m4], + [psi.m4], + [psi_type.m4], + [psi_const.m4], + [psi_decl.m4], + [psi_macro.m4], + [psi_struct.m4], + [errno.m4], + [glob.m4], + [stddef.m4], + [stdio.m4], + [stdint.m4], + [stdlib.m4], + [sys_stat.m4], + [sys_time.m4], + [sys_times.m4], + [sys_types.m4], + [sys_uio.m4], + [time.m4], + [wchar.m4]], [ + dnl pecl build + sinclude([m4/]incfile) + dnl php-src build + sinclude([ext/psi/m4/]incfile) + ]) PSI_LEMON PSI_CHECK_LIBJIT PSI_CHECK_LIBFFI @@ -36,15 +47,25 @@ if test "$PHP_PSI" != no; then PSI_CHECK_ERRNO PSI_CHECK_GLOB PSI_CHECK_STDIO - - echo PSI_TYPES=$PSI_TYPES - echo PSI_MACROS=$PSI_MACROS - echo PSI_REDIRS=$PSI_REDIRS - echo PSI_DECLS=$PSI_DECLS - echo PSI_STRUCTS=$PSI_STRUCTS + PSI_CHECK_STDLIB + PSI_CHECK_TIME + PSI_CHECK_SYS_TIME + PSI_CHECK_SYS_TIMES + PSI_CHECK_SYS_STAT + PSI_CHECK_SYS_UIO + PSI_CHECK_WCHAR PHP_SUBST(PSI_SHARED_LIBADD) + AC_DEFINE_UNQUOTED(PHP_PSI_SHLIB_SUFFIX, ["$SHLIB_SUFFIX_NAME"], DL suffix) + + AC_DEFINE_UNQUOTED([PSI_TYPES], [$PSI_TYPES], [Predefined types]) + AC_DEFINE_UNQUOTED([PSI_STRUCTS], [$PSI_STRUCTS], [Predefined structs]) + AC_DEFINE_UNQUOTED([PSI_CONSTS], [$PSI_CONSTS], [Predefined constants]) + 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]) + PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src) PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src) diff --git a/config.psi_macro.m4 b/config.psi_macro.m4 deleted file mode 100644 index 88702a9..0000000 --- a/config.psi_macro.m4 +++ /dev/null @@ -1,39 +0,0 @@ -# arg_names(typed args) -arg_names() { - AS_ECHO_N([$1]) \ - | tr -cd '()' \ - | $AWK -F, '{for (i=1;imember_name - ) - PSI_CHECK_OFFSETOF($1, member_name) - m4_define([pointer_level], m4_len(m4_bpatsubst($2, [[^*]]))) - m4_define([array_size], m4_bregexp($2, [\[\([0-9]+\)\]], [\1])) - ifelse(array_size, [], - [m4_define([array_size], 0)], - [m4_define([pointer_level], m4_incr(pointer_level))] - ) - m4_define([member_size], PSI_TYPE_SIZE(member_type, pointer_level, array_size)) - if test -n "$psi_struct_members"; then - psi_struct_members="$psi_struct_members, " - fi - psi_struct_members="[$psi_struct_members{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\", $]AS_TR_SH([ac_cv_offsetof_]$1[_]member_name)[, ]member_size, pointer_level, array_size[}]" -]) - -AC_DEFUN(PSI_STRUCT, [ - AC_CHECK_SIZEOF($1, [], PSI_INCLUDES) - psi_struct_members= - ifelse([$2],[],[],[m4_map_args_sep([PSI_STRUCT_MEMBER($1,], [)], [], $2)]) - add_struct "$1" $AS_TR_SH([ac_cv_sizeof_]$1) "$psi_struct_members" -]) diff --git a/config.ax_check_sign.m4 b/m4/ax_check_sign.m4 similarity index 100% rename from config.ax_check_sign.m4 rename to m4/ax_check_sign.m4 diff --git a/config.psi_errno.m4 b/m4/errno.m4 similarity index 98% rename from config.psi_errno.m4 rename to m4/errno.m4 index 8f147e1..99311b7 100644 --- a/config.psi_errno.m4 +++ b/m4/errno.m4 @@ -1,6 +1,8 @@ AC_DEFUN(PSI_CHECK_ERRNO, [ AC_CHECK_HEADERS(errno.h) - PSI_EXTVAR(errno, int) + + PSI_EXTVAR(int errno) + PSI_CONST(E2BIG, int) PSI_CONST(EACCES, int) PSI_CONST(EADDRINUSE, int) diff --git a/config.psi_glob.m4 b/m4/glob.m4 similarity index 100% rename from config.psi_glob.m4 rename to m4/glob.m4 diff --git a/config.psi.m4 b/m4/psi.m4 similarity index 97% rename from config.psi.m4 rename to m4/psi.m4 index 09ca497..ea8d7fb 100644 --- a/config.psi.m4 +++ b/m4/psi.m4 @@ -1,3 +1,10 @@ +PSI_TYPES= +PSI_STRUCTS= +PSI_CONSTS= +PSI_REDIRS= +PSI_MACROS= +PSI_DECLS= + psi_includes() { local have_ have_=`AS_ECHO($ac_header) | $as_tr_cpp` diff --git a/config.psi_const.m4 b/m4/psi_const.m4 similarity index 98% rename from config.psi_const.m4 rename to m4/psi_const.m4 index db08f62..cea747e 100644 --- a/config.psi_const.m4 +++ b/m4/psi_const.m4 @@ -1,4 +1,3 @@ -PSI_CONSTS="" # add_str_const(name, value) add_str_const() { PSI_CONSTS="{PSI_T_STRING, \"string\", \"psi\\\\$1\", $2, PSI_T_QUOTED_STRING}, $PSI_CONSTS" diff --git a/config.psi_decl.m4 b/m4/psi_decl.m4 similarity index 60% rename from config.psi_decl.m4 rename to m4/psi_decl.m4 index 2a89205..9b2d3eb 100644 --- a/config.psi_decl.m4 +++ b/m4/psi_decl.m4 @@ -1,18 +1,28 @@ -PSI_REDIRS= AC_DEFUN(PSI_REDIR, [psi_symbol=ifelse([$2],[],[$1],[$2]) PSI_REDIRS="{\"$1\", (void(*)(void))$psi_symbol}, $PSI_REDIRS"]) -dnl PSI_FUNC(fn, action-if-yes, action-if-no) -AC_DEFUN(PSI_FUNC, [ +AC_DEFUN(PSI_FUNC_LIBC_MAIN, [ AC_REQUIRE([AC_PROG_NM]) AC_REQUIRE([AC_PROG_AWK]) + AC_CACHE_CHECK(for libc start main symbol, psi_cv_libc_main, [ + psi_libc_main= + AC_TRY_LINK(PSI_INCLUDES, [(void)0;], [ + psi_libc_main=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^\s+U / {print$[]3; exit}'` + ]) + psi_cv_libc_main=$psi_libc_main + ]) +]) + +dnl PSI_FUNC(fn, action-if-yes, action-if-no) +AC_DEFUN(PSI_FUNC, [ + AC_REQUIRE([PSI_FUNC_LIBC_MAIN]) psi_symbol=$1 AC_CACHE_CHECK(for $1, psi_cv_fn_$1, [ psi_symbol_redirect= AC_TRY_LINK(PSI_INCLUDES, [ void (*fn)(void) = (void (*)(void)) $psi_symbol; ], [ - psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/ U .*$1.*/ {print$[]3; exit}'` + psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^\s+U '$psi_cv_libc_main'/ {next} /^\s+U / {print$[]3; exit}'` ]) psi_cv_fn_$1=$psi_symbol_redirect ]) @@ -32,9 +42,9 @@ AC_DEFUN(PSI_FUNC, [ AC_DEFUN(PSI_DECL_ARG, [ m4_define([member_name], PSI_VAR_NAME($1)) - m4_define([member_type], PSI_TYPE_NAME($1)) - m4_define([pointer_level], m4_len(m4_bpatsubst($1, [[^*]]))) - m4_define([array_size], m4_bregexp($1, [\[\([0-9]+\)\]], [\1])) + m4_define([member_type], PSI_VAR_TYPE($1)) + m4_define([pointer_level], m4_len(m4_bpatsubst([$1], [[^*]]))) + m4_define([array_size], [m4_bregexp([$1], [@<:@\([0-9]+\)@:>@], [\1])]) ifelse(array_size, [], [m4_define([array_size], 0)], [m4_define([pointer_level], m4_incr(pointer_level))] @@ -52,13 +62,12 @@ AC_DEFUN(PSI_DECL, [ m4_case([$2], [(void)], [], [()], [], - [m4_map_args_sep([PSI_DECL_ARG(], [)], [], m4_bregexp($2, [(\(.*\))], [\1]))]) + [m4_map_args_sep([PSI_DECL_ARG(], [)], [], [m4_bregexp([$2], [(\(.*\))], [\1])])]) PSI_FUNC(PSI_VAR_NAME($1), [ - PSI_DECLS="{$psi_decl_args}, $PSI_DECLS" + PSI_DECLS="$psi_decl_args, {0}, $PSI_DECLS" ], [ - PSI_MACRO(PSI_VAR_NAME($1), $3, [ - add_macro "PSI_TYPE_NAME($1)" "PSI_VAR_NAME($1)" "$3" - PSI_DECLS="{$psi_decl_args}, $PSI_DECLS" + PSI_MACRO($1, $2, [ + PSI_DECLS="$psi_decl_args, {0}, $PSI_DECLS" ]) ]) ]) diff --git a/m4/psi_macro.m4 b/m4/psi_macro.m4 new file mode 100644 index 0000000..439098f --- /dev/null +++ b/m4/psi_macro.m4 @@ -0,0 +1,26 @@ +dnl PSI_MACRO(macro, decl args, action-if-true) +AC_DEFUN(PSI_MACRO, [ + AC_CHECK_DECL(PSI_VAR_NAME($1)$2, [ + $3 + macro_type=PSI_VAR_TYPE($1) + macro_name=PSI_VAR_NAME($1) + ifelse([$2], [], [ + macro_decl="()" + macro_call="" + ], [ + macro_decl="$2" + macro_call="(m4_map_args_sep([PSI_VAR_NAME(], [)], [, ], m4_bregexp($2, [(\(.*\))], [\1])))" + ]) + ifelse(PSI_VAR_TYPE($1), [void], [ + macro_body="$macro_name$macro_call;" + ], [ + macro_body="return $macro_name$macro_call;" + ]) + psi_macro="$macro_type psi_macro_$macro_name$macro_decl { $macro_body }" + PSI_MACROS="$PSI_MACROS $psi_macro" + PSI_REDIR($macro_name, psi_macro_$macro_name) + ], [], PSI_INCLUDES) +]) + +dnl PSI_EXTVAR(type var) +AC_DEFUN(PSI_EXTVAR, [PSI_MACRO($1)]) diff --git a/m4/psi_struct.m4 b/m4/psi_struct.m4 new file mode 100644 index 0000000..f0d273e --- /dev/null +++ b/m4/psi_struct.m4 @@ -0,0 +1,30 @@ +AC_DEFUN(PSI_STRUCT_MEMBER, [ + m4_define([member_name], PSI_VAR_NAME($2)) + m4_define([member_type], PSI_VAR_TYPE($2)) + AC_CHECK_SIZEOF(AS_TR_SH($1)[_]member_name, [], PSI_INCLUDES + [#define ]AS_TR_SH($1)[_]member_name (($1 *)0)->member_name + ) + if test -n "$AS_TR_SH([ac_cv_sizeof_$1][_]member_name)" \ + && test "$AS_TR_SH([ac_cv_sizeof_$1][_]member_name)" -gt 0; then + PSI_CHECK_OFFSETOF($1, member_name) + m4_define([pointer_level], m4_len(m4_bpatsubst([$2], [[^*]]))) + m4_define([array_size], [m4_bregexp([$2], [@<:@\([0-9]+\)@:>@], [\1])]) + ifelse(array_size, [], + [m4_define([array_size], 0)], + [m4_define([pointer_level], m4_incr(pointer_level))] + ) + m4_define([member_size], PSI_TYPE_SIZE(member_type, pointer_level, array_size)) + psi_struct_members="[$psi_struct_members, {]PSI_TYPE_PAIR(member_type)[, \"]member_name[\", $]AS_TR_SH([ac_cv_offsetof_]$1[_]member_name)[, ]member_size, pointer_level, array_size[}]" + fi +]) + +AC_DEFUN(PSI_STRUCT, [ + AC_CHECK_SIZEOF($1, [], PSI_INCLUDES) + psi_struct_name=m4_bregexp([$1], [^\(struct \)?\(\w+\)], [\2]) + psi_struct_members="{PSI_T_STRUCT, \"struct\", \"$psi_struct_name\", 0, $AS_TR_SH([ac_cv_sizeof_]$1), 0, 0}" + ifelse([$2],,,[m4_map_args_sep([PSI_STRUCT_MEMBER($1,], [)], [], $2)]) + PSI_STRUCTS="$psi_struct_members, {0}, $PSI_STRUCTS" + if test "$1" = "$psi_struct_name"; then + PSI_TYPES="{PSI_T_STRUCT, \"$1\", \"$1\"}, $PSI_TYPES" + fi +]) diff --git a/config.psi_type.m4 b/m4/psi_type.m4 similarity index 88% rename from config.psi_type.m4 rename to m4/psi_type.m4 index 4e9aa16..2cd9191 100644 --- a/config.psi_type.m4 +++ b/m4/psi_type.m4 @@ -6,7 +6,6 @@ psi_type_pair() { int*|uint*) local psi_type_upper=`tr a-z A-Z <<<$psi_type_name` local psi_type_bits=`expr $2 \* 8` - echo psi_type_bits=$psi_type_bits "expr $2 \* 8" "$@" >&2 echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\"" eval AS_TR_SH([psi_standard_type_]$1)="${psi_type_lower}${psi_type_bits}_t" ;; @@ -22,7 +21,6 @@ psi_type_pair() { esac } -PSI_TYPES="" dnl PSI_TYPE(type name, basic type, includes) AC_DEFUN(PSI_TYPE, [ ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1)) @@ -45,9 +43,9 @@ AC_DEFUN(PSI_TYPE, [ ]) dnl unsigned char* buf[16] -> char -AC_DEFUN(PSI_TYPE_NAME, [m4_bregexp([$1], [\(\(struct \)?[^ ]+\)[ *]+[^ ]+$], [\1])]) +AC_DEFUN(PSI_VAR_TYPE, [m4_bregexp([$1], [\(\(struct \)?[^ ]+\)[ *]+[^ ]+$], [\1])]) dnl unsigned char* buf[16] -> buf -AC_DEFUN(PSI_VAR_NAME, [m4_bregexp(m4_bregexp([$1], [[^ ]+$], [\&]), [\w+], [\&])]) +AC_DEFUN(PSI_VAR_NAME, [m4_bregexp(m4_bregexp([$1], [\([^ ]+\)$], [\1]), [\w+], [\&])]) dnl PSI_TYPE_SIZE(type, pointer level, array size) AC_DEFUN(PSI_TYPE_SIZE, [ifelse( [$3], 0, @@ -59,9 +57,8 @@ AC_DEFUN(PSI_TYPE_BITS, [`expr 8 \* $AS_TR_SH([ac_cv_sizeof_]$1)`]) AC_DEFUN(PSI_TYPE_PAIR, [m4_case(m4_bregexp([$1], [^\w+], [\&]), [void], [PSI_T_VOID, \"void\"], - [struct], [PSI_T_STRUCT, \"m4_bregexp($1, [^struct \(\w+\)], [\1])\"], - [PSI_T_NAME, \"$1\"] -)]) + [struct], [PSI_T_STRUCT, \"m4_bregexp([$1], [^struct \(\w+\)], [\1])\"], + [PSI_T_NAME, \"$1\"])]) AC_DEFUN(PSI_CHECK_STD_TYPES, [ AC_CHECK_HEADERS(stdint.h) diff --git a/config.psi_stddef.m4 b/m4/stddef.m4 similarity index 100% rename from config.psi_stddef.m4 rename to m4/stddef.m4 diff --git a/config.psi_stdint.m4 b/m4/stdint.m4 similarity index 100% rename from config.psi_stdint.m4 rename to m4/stdint.m4 diff --git a/config.psi_stdio.m4 b/m4/stdio.m4 similarity index 100% rename from config.psi_stdio.m4 rename to m4/stdio.m4 diff --git a/m4/stdlib.m4 b/m4/stdlib.m4 new file mode 100644 index 0000000..c84d44d --- /dev/null +++ b/m4/stdlib.m4 @@ -0,0 +1,60 @@ +AC_DEFUN(PSI_CHECK_STDLIB, [ + AC_CHECK_HEADERS(stdlib.h) + + PSI_CONST(EXIT_FAILURE, int) + PSI_CONST(EXIT_SUCCESS, int) + PSI_CONST(RAND_MAX, int) + PSI_CONST(MB_CUR_MAX, int) + + PSI_DECL(void _Exit, [(int status)]) + PSI_DECL(void abort, [()]) + PSI_DECL(int abs, [(int n)]) + PSI_DECL(double atof, [(char *str)]) + PSI_DECL(int atoi, [(char *str)]) + PSI_DECL(long atol, [(char *str)]) + PSI_DECL(div_t div, [(int numerator, int denominator)]) + PSI_DECL(double drand48, [()]) + PSI_DECL(double erand48, [(unsigned short xsubi@<:@3@:>@)]) + PSI_DECL(void exit, [(int status)]) + PSI_DECL(void free, [(void *ptr)]) + PSI_DECL(char *getenv, [(char *var)]) + PSI_DECL(int grantpt, [(int fd)]) + PSI_DECL(char *initstate, [(unsigned int seed, char *state, size_t n)]) + PSI_DECL(long jrand48, [(unsigned short xsubi@<:@3@:>@)]) + PSI_DECL(long labs, [(long l)]) + PSI_DECL(void lcong48, [(unsigned short param@<:@7@:>@)]) + PSI_DECL(long ldiv, [(long numerator, long denominator)]) + PSI_DECL(long lrand48, [()]) + PSI_DECL(int mblen, [(const char *s, size_t n)]) + PSI_DECL(size_t mbstowcs, [(wchar_t *dest, char *src, size_t n)]) + PSI_DECL(int mbtowc, [(wchar_t *pwc, char *s, size_t n)]) + PSI_DECL(char *mkdtemp, [(char *template)]) + PSI_DECL(char *mkdstemp, [(char *template)]) + PSI_DECL(long mrand48, [()]) + PSI_DECL(long nrand48, [(unsigned short xsubi@<:@3@:>@)]) + PSI_DECL(int posix_openpt, [(int flags)]) + PSI_DECL(char *ptsname, [(int fd)]) + PSI_DECL(char *pstname_r, [(int fd, char *buf, size_t buflen)]) + PSI_DECL(int putenv, [(char *var)]) + PSI_DECL(int rand, [()]) + PSI_DECL(int rand_r, [(unsigned *seed_p)]) + PSI_DECL(long random, [()]) + PSI_DECL(char *realpath, [(char *path, char *resolved)]) + PSI_DECL(unsigned short *seed48, [(unsigned short seed16v@<:@3@:>@)]) + PSI_DECL(int setenv, [(char *var)]) + PSI_DECL(void setkey, [(char *key)]) + PSI_DECL(char *setstate, [(char *state)]) + PSI_DECL(void srand, [(unsigned seed)]) + PSI_DECL(void srand48, [(long seed)]) + PSI_DECL(void srandom, [(unsigned seed)]) + PSI_DECL(double strtod, [(char *nptr, char **endptr)]) + PSI_DECL(float strtof, [(char *nptr, char **endptr)]) + PSI_DECL(long strtol, [(char *nptr, char **endptr)]) + PSI_DECL(unsigned long strtoul, [(char *nptr, char **endptr)]) + PSI_DECL(int system, [(char *command)]) + PSI_DECL(int unlockpt, [(int fd)]) + PSI_DECL(int unsetenv, [(char *var)]) + PSI_DECL(size_t wcstombs, [(char *dest, wchar_t *src, size_t n)]) + PSI_DECL(int wctomb, [(char *s, wchar_t wc)]) +]) + diff --git a/m4/sys_stat.m4 b/m4/sys_stat.m4 new file mode 100644 index 0000000..1d8e52c --- /dev/null +++ b/m4/sys_stat.m4 @@ -0,0 +1,83 @@ +AC_DEFUN(PSI_CHECK_SYS_STAT, [ + AC_CHECK_HEADERS([sys/stat.h]) + + PSI_STRUCT(struct stat, [ + dev_t st_dev, + ino_t st_ino, + mode_t st_mode, + nlink_t st_nlink, + uid_t st_uid, + gid_t st_gid, + dev_t st_rdev, + off_t st_size, + blksize_t st_blksize, + blkcnt_t st_blocks, + time_t st_atime, + time_t st_mtime, + time_t st_ctime, + struct timespec st_atim, + struct timespec st_mtim, + struct timespec st_ctim, + struct timespec st_atimespec, + struct timespec st_mtimespec, + struct timespec st_ctimespec, + struct timespec st_birthtimespec, + time_t st_birthtime, + int st_flags] + ) + + PSI_CONST(S_IFMT, int) + PSI_CONST(S_IFBLK, int) + PSI_CONST(S_IFCHR, int) + PSI_CONST(S_IFIFO, int) + PSI_CONST(S_IFREG, int) + PSI_CONST(S_IFDIR, int) + PSI_CONST(S_IFLNK, int) + PSI_CONST(S_IFSOCK, int) + PSI_CONST(S_IRWXU, int) + PSI_CONST(S_IRUSR, int) + PSI_CONST(S_IWUSR, int) + PSI_CONST(S_IXUSR, int) + PSI_CONST(S_IRWXG, int) + PSI_CONST(S_IRGRP, int) + PSI_CONST(S_IWGRP, int) + PSI_CONST(S_IXGRP, int) + PSI_CONST(S_IRWXO, int) + PSI_CONST(S_IROTH, int) + PSI_CONST(S_IWOTH, int) + PSI_CONST(S_IXOTH, int) + PSI_CONST(S_ISUID, int) + PSI_CONST(S_ISGID, int) + PSI_CONST(UTIME_NOW, int) + PSI_CONST(UTIME_OMIT, int) + + PSI_MACRO(int S_ISBLK, [(mode_t m)]) + PSI_MACRO(int S_ISCHR, [(mode_t m)]) + PSI_MACRO(int S_ISDIR, [(mode_t m)]) + PSI_MACRO(int S_ISFIFO, [(mode_t m)]) + PSI_MACRO(int S_ISREG, [(mode_t m)]) + PSI_MACRO(int S_ISLNK, [(mode_t m)]) + PSI_MACRO(int S_ISSOCK, [(mode_t m)]) + + PSI_MACRO(int S_TYPEISMQ, [(struct stat *s)]) + PSI_MACRO(int S_TYPEISSEM, [(struct stat *s)]) + PSI_MACRO(int S_TYPEISSHM, [(struct stat *s)]) + PSI_MACRO(int S_TYPEISTMO, [(struct stat *s)]) + + PSI_DECL(int chmod, [(char *path, mode_t mode)]) + PSI_DECL(int fchmod, [(int fd, mode_t mode)]) + PSI_DECL(int fchmodat, [(int fd, char *path, mode_t mode, int flag)]) + PSI_DECL(int fstat, [(int fd, struct stat *buf)]) + PSI_DECL(int fstatat, [(int fd, char *path, struct stat *buf, int flag)]) + PSI_DECL(int futimens, [(int fd, struct timespec times@<:@2@:>@)]) + PSI_DECL(int lstat, [(char *path, struct stat *buf)]) + PSI_DECL(int mkdir, [(char *path, mode_t mode)]) + PSI_DECL(int mkdirat, [(int fd, char *path, mode_t mode)]) + PSI_DECL(int mkfifo, [(char *path, mode_t mode)]) + PSI_DECL(int mkfifoat, [(int fd, char *path, mode_t mode)]) + PSI_DECL(int mknod, [(char *path, mode_t mode, dev_t dev)]) + PSI_DECL(int mknodat, [(int fd, char *path, mode_t mode, dev_t dev)]) + PSI_DECL(int stat, [(char *path, struct stat *buf)]) + PSI_DECL(mode_t umask, [(mode_t mode)]) + PSI_DECL(int utimensat, [(int fd, char *path, struct timespec times@<:@2@:>@, int flag)]) +]) diff --git a/m4/sys_time.m4 b/m4/sys_time.m4 new file mode 100644 index 0000000..861fa41 --- /dev/null +++ b/m4/sys_time.m4 @@ -0,0 +1,26 @@ +AC_DEFUN(PSI_CHECK_SYS_TIME, [ + AC_CHECK_HEADERS(sys/time.h) + + PSI_CONST(ITIMER_REAL, int) + PSI_CONST(ITIMER_VIRTUAL, int) + PSI_CONST(ITIMER_PROF, int) + + PSI_STRUCT(struct timeval, [ + time_t tv_sec, + suseconds_t tv_usec] + ) + PSI_STRUCT(struct itimerval, [ + struct timeval it_interval, + struct timeval it_value] + ) + PSI_STRUCT(struct timezone, [ + int tz_minuteswest, + int tz_dsttime] + ) + + PSI_DECL(int getitimer, [(int which, struct itimerval *value)]) + PSI_DECL(int setitimer, [(int which struct itimerval *value, struct itimerval *ovalue)]) + PSI_DECL(int gettimeofday, [(struct timeval *tp, struct timezone *tz)]) + PSI_DECL(int utimes, [(char *path, struct timeval times@<:@2@:>@)]) + PSI_DECL(int utimensat, [(int fd, char *path, struct timespec times@<:@2@:>@)]) +]) diff --git a/m4/sys_times.m4 b/m4/sys_times.m4 new file mode 100644 index 0000000..cbaa6fe --- /dev/null +++ b/m4/sys_times.m4 @@ -0,0 +1,12 @@ +AC_DEFUN(PSI_CHECK_SYS_TIMES, [ + AC_CHECK_HEADERS(sys/times.h) + + PSI_STRUCT(struct tms, [ + clock_t tms_utime, + clock_t tms_stime, + clock_t tms_cutime, + clock_t tms_cstime] + ) + + PSI_DECL(clock_t times, [(struct tms *buf)]) +]) diff --git a/config.psi_sys_types.m4 b/m4/sys_types.m4 similarity index 100% rename from config.psi_sys_types.m4 rename to m4/sys_types.m4 diff --git a/m4/sys_uio.m4 b/m4/sys_uio.m4 new file mode 100644 index 0000000..d57f901 --- /dev/null +++ b/m4/sys_uio.m4 @@ -0,0 +1,11 @@ +AC_DEFUN(PSI_CHECK_SYS_UIO, [ + AC_CHECK_HEADERS(sys/uio.h) + + PSI_STRUCT(struct iovec, [ + void *iov_base, + size_t iov_len] + ) + + PSI_DECL(ssize_t readv, [(int fd, struct iovec *iov, int iovcnt)]) + PSI_DECL(ssize_t writev, [(int fd, struct iovec *iov, int iovcnt)]) +]) diff --git a/m4/time.m4 b/m4/time.m4 new file mode 100644 index 0000000..3d50e69 --- /dev/null +++ b/m4/time.m4 @@ -0,0 +1,59 @@ +AC_DEFUN(PSI_CHECK_TIME, [ + AC_CHECK_HEADERS(time.h) + + PSI_CONST(CLOCKS_PER_SEC, int) + PSI_CONST(CLOCK_MONOTONIC, int) + PSI_CONST(CLOCK_PROCESS_CPUTIME_ID, int) + PSI_CONST(CLOCK_REALTIME, int) + PSI_CONST(CLOCK_THREAD_CPUTIME_ID, int) + PSI_CONST(TIMER_ABSTIME, int) + + PSI_STRUCT(struct tm, [ + int tm_sec, + int tm_min, + int tm_hour, + int tm_mday, + int tm_mon, + int tm_year, + int tm_wday, + int tm_yday, + int tm_isdst] + ) + PSI_STRUCT(struct timespec, [ + time_t tv_sec, + long tv_nsec] + ) + PSI_STRUCT(struct itimerspec, [ + struct timespec it_interval, + struct timespec it_value] + ) + + PSI_DECL(char *asctime, [(struct tm *tm)]) + PSI_DECL(char *asctime_r, [(struct tm *tm, char *buf)]) + PSI_DECL(clock_t clock, [()]) + PSI_DECL(int clock_getcpuclockid, [(pid_t pid, clockid_t *clock_id)]) + PSI_DECL(int clock_getres, [(clockid_t clk_id, struct timespec *res)]) + PSI_DECL(int clock_gettime, [(clockid_t clk_id, struct timespec *tp)]) + PSI_DECL(int clock_nanosleep, [(clockid_t clk_id, int flags, struct timespec *rqtp, struct timespec *rmtp)]) + PSI_DECL(int clock_settime, [(clockid_t clk_id, struct timespec *tp)]) + PSI_DECL(char *ctime, [(time_t *t)]) + PSI_DECL(char *ctime_r, [(time_t *t, char *buf)]) + PSI_DECL(double difftime, [(time_t time1, time_t time0)]) + PSI_DECL(struct tm *getdate, [(char *string)]) + PSI_DECL(struct tm *gmtime, [(time_t *t)]) + PSI_DECL(struct tm *gmtime_r, [(time_t *t, struct tm *buf)]) + PSI_DECL(struct tm *localtime, [(time_t *t)]) + PSI_DECL(struct tm *localtime_r, [(time_t *t, struct tm *buf)]) + PSI_DECL(time_t mktime, [(struct tm *tm)]) + PSI_DECL(int nanosleep, [(struct timespec *rqts, struct timespec *rmts)]) + PSI_DECL(size_t strftime, [(char *s, size_t max, char *fmt, struct tm *tm)]) + dnl PSI_DECL(size_t strftime_l, [(char *s, size_t max, char *fmt, struct tm *tm, locale_t l)]) + PSI_DECL(char *strptime, [(char *s, char *fmt, struct tm *tm)]) + PSI_DECL(time_t time, [(time_t *t)]) + dnl PSI_DECL(int timer_create, [(clockid_t clk_id, struct sigevent *se, timer_t *t)]) + PSI_DECL(int timer_delete, [(timer_t t)]) + PSI_DECL(int timer_getoverrun, [(timer_t t)]) + PSI_DECL(int timer_gettime, [(timer_t t, struct itimerspec *ts)]) + PSI_DECL(int timer_settime, [(timer_t t, struct itimerspec *value, struct itimerspec *ovalue)]) + PSI_DECL(void tzset, [()]) +]) diff --git a/m4/wchar.m4 b/m4/wchar.m4 new file mode 100644 index 0000000..97a0b9e --- /dev/null +++ b/m4/wchar.m4 @@ -0,0 +1,9 @@ +AC_DEFUN(PSI_CHECK_WCHAR, [ + AC_CHECK_HEADERS(wchar.h) + + PSI_TYPE(wint_t, int) + + PSI_CONST(WINT_MIN, int) + PSI_CONST(WINT_MAX, int) + PSI_CONST(WEOF, int) +]) diff --git a/php_psi.h b/php_psi.h index 066d9d6..84b73c2 100644 --- a/php_psi.h +++ b/php_psi.h @@ -24,6 +24,11 @@ extern zend_module_entry psi_module_entry; void psi_error(int type, const char *msg, ...); +static inline int psi_check_env(const char *var) { + char *set = getenv(var); + return (set && *set && '0' != *set); +} + size_t psi_t_alignment(token_t t); size_t psi_t_size(token_t t); size_t psi_t_align(token_t t, size_t s); diff --git a/psi.d/glob.psi b/psi.d/glob.psi index 3f8ee1e..2bb952e 100644 --- a/psi.d/glob.psi +++ b/psi.d/glob.psi @@ -1,8 +1,5 @@ -extern void globfree(glob_t *buf); - -extern int glob(char *pat, int flags, void *err, glob_t *buf); function psi\glob(string $pattern, int $flags, array &$glob = NULL) : int { - let pat = strval($pattern); + let path = strval($pattern); let flags = intval($flags); let err = NULL; let buf = arrval($glob); @@ -14,5 +11,5 @@ function psi\glob(string $pattern, int $flags, array &$glob = NULL) : int { to_int(gl_flags), to_array(**gl_pathv, gl_pathc, gl_offs, to_string(*gl_pathv)) ); - //free globfree(buf); + free globfree(buf); } diff --git a/psi.d/stat.psi b/psi.d/stat.psi index 0b22225..82d6249 100644 --- a/psi.d/stat.psi +++ b/psi.d/stat.psi @@ -1,4 +1,3 @@ -extern int stat(char *path, struct stat *buf); function psi\stat(string $path, array &$buf = NULL) : int { let path = strval($path); let buf = calloc(1, struct stat); diff --git a/psi.d/time.psi b/psi.d/time.psi index 1281c51..e01bd1b 100644 --- a/psi.d/time.psi +++ b/psi.d/time.psi @@ -1,4 +1,3 @@ -extern time_t time(time_t *t); function psi\time() : int { let t = NULL; return to_int(time); @@ -9,11 +8,11 @@ function psi\gettimeofday(array &$tv = NULL, array &$tz = NULL) : int { let tv = calloc(1, struct timeval); let tz = calloc(1, struct timezone); return to_int(gettimeofday); - set $tv = to_array(*tv, - to_int(tv_sec), + set $tv = to_array(*tv, + to_int(tv_sec), to_int(tv_usec)); - set $tz = to_array(*tz, - to_int(tz_minuteswest), + set $tz = to_array(*tz, + to_int(tz_minuteswest), to_int(tz_dsttime)); } diff --git a/src/context.c b/src/context.c index 727388b..5e66a45 100644 --- a/src/context.c +++ b/src/context.c @@ -111,59 +111,76 @@ #include "libjit.h" #include "libffi.h" -#define psi_predef_count(of) ((sizeof(psi_predef ##of## s)/sizeof(psi_predef ##of))-1) -typedef struct psi_predef_type { +static struct psi_std_type { + token_t type_tag; + const char *type_name; +} psi_std_types[] = { + {PSI_T_FLOAT, "float"}, + {PSI_T_DOUBLE, "double"}, + {PSI_T_INT8, "int8_t"}, + {PSI_T_INT16, "int16_t"}, + {PSI_T_INT32, "int32_t"}, + {PSI_T_INT64, "int64_t"}, + {PSI_T_UINT8, "uint8_t"}, + {PSI_T_UINT16, "uint16_t"}, + {PSI_T_UINT32, "uint32_t"}, + {PSI_T_UINT64, "uint64_t"}, + {0} +}; + +static struct psi_predef_type { token_t type_tag; const char *type_name; const char *alias; -} psi_predef_type; -static const psi_predef_type psi_predef_types[] = { - PHP_PSI_TYPES{0} +} psi_predef_types[] = { + PSI_TYPES + {0} }; -#define psi_predef_type_count() psi_predef_count(_type) -typedef struct psi_predef_const { +static struct psi_predef_const { token_t type_tag; const char *type_name; - const char *name; + const char *var_name; const char *val_text; token_t val_type_tag; -} psi_predef_const; -static const psi_predef_const psi_predef_consts[] = { - PHP_PSI_CONSTS{0} +} psi_predef_consts[] = { + PSI_CONSTS + {0} }; -#define psi_predef_const_count() psi_predef_count(_const) -typedef struct psi_predef_struct_member { +PSI_MACROS + +static struct psi_func_redir { + const char *name; + void (*func)(void); +} psi_func_redirs[] = { + PSI_REDIRS + {0} +}; + +static struct psi_predef_decl { token_t type_tag; const char *type_name; - const char *name; - size_t off; - size_t len; + const char *var_name; size_t pointer_level; size_t array_size; -} psi_predef_struct_member; -#define PSI_PREDEF_STRUCT_MEMBERS 32 -typedef struct psi_predef_struct { - const char *name; - size_t size; - psi_predef_struct_member members[PSI_PREDEF_STRUCT_MEMBERS]; -} psi_predef_struct; -static const psi_predef_struct psi_predef_structs[] = { - PHP_PSI_STRUCTS{0} +} psi_predef_decls[] = { + PSI_DECLS + {0} }; -#define psi_predef_struct_count() psi_predef_count(_struct) -PHP_PSI_MACROS - -typedef struct psi_predef_func { - const char *name; - void (*func)(void); -} psi_predef_func; -static psi_predef_func psi_predef_funcs[] = { - PHP_PSI_FUNCS{0} +static struct psi_predef_struct { + token_t type_tag; + const char *type_name; + const char *var_name; + size_t offset; + size_t size; + size_t pointer_level; + size_t array_size; +} psi_predef_structs[] = { + PSI_STRUCTS + {0} }; -#define psi_predef_func_count() psi_predef_count(_func) static int validate_lib(PSI_Data *data, void **dlopened) { char lib[MAXPATHLEN]; @@ -191,16 +208,26 @@ static int validate_lib(PSI_Data *data, void **dlopened) { static inline int locate_decl_type_alias(decl_typedefs *defs, decl_type *type) { size_t i; + struct psi_std_type *stdtyp; if (type->real) { return 1; } for (i = 0; i < defs->count; ++i) { - if (!strcmp(defs->list[i]->alias, type->name)) { - type->real = defs->list[i]->type; + decl_typedef *def = defs->list[i]; + + if (def->type->type != type->type && !strcmp(def->alias, type->name)) { + type->real = def->type; return 1; } } + for (stdtyp = &psi_std_types[0]; stdtyp->type_tag; ++stdtyp) { + if (!strcmp(type->name, stdtyp->type_name)) { + type->type = stdtyp->type_tag; + } + return 1; + } + return 0; } static inline int locate_decl_type_struct(decl_structs *structs, decl_type *type) { @@ -221,10 +248,13 @@ static inline int locate_decl_type_struct(decl_structs *structs, decl_type *type static inline int validate_decl_type(PSI_Data *data, decl_type *type) { switch (type->type) { case PSI_T_NAME: - if (!data->defs |!locate_decl_type_alias(data->defs, type)) { + if (!data->defs || !locate_decl_type_alias(data->defs, type)) { return 0; } - return validate_decl_type(data, type->real); + if (type->real) { + return validate_decl_type(data, type->real); + } + return 1; case PSI_T_STRUCT: if (!data->structs || !locate_decl_type_struct(data->structs, type)) { return 0; @@ -235,8 +265,8 @@ static inline int validate_decl_type(PSI_Data *data, decl_type *type) { } static inline int validate_decl_typedef(PSI_Data *data, decl_typedef *def) { if (!validate_decl_type(data, def->type)) { - data->error(PSI_WARNING, "Type '%s' cannot be aliased to '%s'", - def->type->name, def->alias); + data->error(PSI_WARNING, "Type '%s' cannot be aliased to %s'%s'", + def->type->name, def->type->type == PSI_T_STRUCT?"struct ":"",def->alias); return 0; } /* FIXME: check def->alias */ @@ -321,7 +351,7 @@ static inline int validate_decl_abi(PSI_Data *data, decl_abi *abi) { } static inline int validate_decl_func(PSI_Data *data, void *dl, decl *decl, decl_arg *func) { - size_t i; + struct psi_func_redir *redir; if (!strcmp(func->var->name, "dlsym")) { data->error(PSI_WARNING, "Cannot dlsym dlsym (sic!)"); @@ -331,12 +361,9 @@ static inline int validate_decl_func(PSI_Data *data, void *dl, decl *decl, decl_ if (!validate_decl_arg(data, func)) { return 0; } - for (i = 0; i < psi_predef_func_count(); ++i) { - psi_predef_func *pre = &psi_predef_funcs[i]; - - if (!strcmp(func->var->name, pre->name)) { - decl->call.sym = pre->func; - break; + for (redir = &psi_func_redirs[0]; redir->name; ++redir) { + if (!strcmp(func->var->name, redir->name)) { + decl->call.sym = redir->func; } } if (!decl->call.sym) { @@ -703,8 +730,12 @@ static inline int validate_impl_stmts(PSI_Data *data, impl *impl) { PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErrorFunc error) { - size_t i, j; + size_t i; PSI_Data T; + struct psi_predef_type *predef_type; + struct psi_predef_const *predef_const; + struct psi_predef_struct *predef_struct; + struct psi_predef_decl *predef_decl; if (!C) { C = malloc(sizeof(*C)); @@ -725,49 +756,61 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr memset(&T, 0, sizeof(T)); T.error = error; - for (i = 0; i < psi_predef_type_count(); ++i) { - const psi_predef_type *pre = &psi_predef_types[i]; - decl_type *type = init_decl_type(pre->type_tag, pre->type_name); - decl_typedef *def = init_decl_typedef(pre->alias, type); + for (predef_type = &psi_predef_types[0]; predef_type->type_tag; ++predef_type) { + decl_type *type = init_decl_type(predef_type->type_tag, predef_type->type_name); + decl_typedef *def = init_decl_typedef(predef_type->alias, type); T.defs = add_decl_typedef(T.defs, def); } - for (i = 0; i < psi_predef_const_count(); ++i) { - const psi_predef_const *pre = &psi_predef_consts[i]; - impl_def_val *val = init_impl_def_val(pre->val_type_tag, pre->val_text); - const_type *type = init_const_type(pre->type_tag, pre->type_name); - constant *constant = init_constant(type, pre->name, val); + for (predef_const = &psi_predef_consts[0]; predef_const->type_tag; ++predef_const) { + impl_def_val *val = init_impl_def_val(predef_const->val_type_tag, predef_const->val_text); + const_type *type = init_const_type(predef_const->type_tag, predef_const->type_name); + constant *constant = init_constant(type, predef_const->var_name, val); T.consts = add_constant(T.consts, constant); } - for (i = 0; i < psi_predef_struct_count(); ++i) { - const psi_predef_struct *pre = &psi_predef_structs[i]; + for (predef_struct = &psi_predef_structs[0]; predef_struct->type_tag; ++predef_struct) { + struct psi_predef_struct *member; decl_args *dargs = init_decl_args(NULL); - decl_struct *dstruct; + decl_struct *dstruct = init_decl_struct(predef_struct->var_name, dargs); - for (j = 0; j < PSI_PREDEF_STRUCT_MEMBERS; ++j) { - const psi_predef_struct_member *member = &pre->members[j]; + dstruct->size = predef_struct->size; + for (member = &predef_struct[1]; member->type_tag; ++member) { decl_type *type; decl_var *dvar; decl_arg *darg; - if (!member->name) { - break; - } - type = init_decl_type(member->type_tag, member->type_name); - dvar = init_decl_var(member->name, member->pointer_level, member->array_size); + dvar = init_decl_var(member->var_name, member->pointer_level, member->array_size); darg = init_decl_arg(type, dvar); - darg->layout = init_decl_struct_layout(member->off, member->len); + darg->layout = init_decl_struct_layout(member->offset, member->size); dargs = add_decl_arg(dargs, darg); } - dstruct = init_decl_struct(pre->name, dargs); - dstruct->size = pre->size; T.structs = add_decl_struct(T.structs, dstruct); + predef_struct = member; + } + for (predef_decl = &psi_predef_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); + 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 (i = 0; i < psi_predef_type_count(); ++i) { + for (i = 0; i < T.defs->count; ++i) { decl_typedef *def = T.defs->list[i]; if (validate_decl_typedef(&T, def)) { @@ -775,7 +818,7 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr } } - for (i = 0; i < psi_predef_const_count(); ++i) { + for (i = 0; i < T.consts->count; ++i) { constant *constant = T.consts->list[i]; if (validate_constant(&T, constant)) { @@ -783,7 +826,7 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr } } - for (i = 0; i < psi_predef_struct_count(); ++i) { + for (i = 0; i < T.structs->count; ++i) { decl_struct *dstruct = T.structs->list[i]; if (validate_decl_struct(&T, dstruct)) { @@ -791,6 +834,14 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr } } + for (i = 0; i < T.decls->count; ++i) { + decl *decl = T.decls->list[i]; + + if (validate_decl(&T, NULL, decl)) { + C->decls = add_decl(C->decls, decl); + } + } + C->count = 1; C->data = malloc(sizeof(*C->data)); PSI_DataExchange(C->data, &T); @@ -873,7 +924,7 @@ static int psi_select_dirent(const struct dirent *entry) void PSI_ContextBuild(PSI_Context *C, const char *paths) { - int i, n, flags = getenv("PSI_DEBUG") ? PSI_PARSER_DEBUG : 0; + int i, n, flags = psi_check_env("PSI_DEBUG") ? PSI_PARSER_DEBUG : 0; char *sep = NULL, *cpy = strdup(paths), *ptr = cpy; struct dirent **entries = NULL; diff --git a/src/module.c b/src/module.c index 0994630..469fb4d 100644 --- a/src/module.c +++ b/src/module.c @@ -740,7 +740,7 @@ PHP_MINIT_FUNCTION(psi) PSI_ContextInit(&PSI_G(context), ops, psi_error); PSI_ContextBuild(&PSI_G(context), PSI_G(directory)); - if (getenv("PSI_DUMP")) { + if (psi_check_env("PSI_DUMP")) { PSI_ContextDump(&PSI_G(context), STDOUT_FILENO); } -- 2.30.2