+++ /dev/null
-AC_DEFUN([AX_CHECK_SIGN], [
- typename=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g"`
- AC_CACHE_CHECK([whether $1 is signed], ax_cv_decl_${typename}_signed, [
- AC_TRY_COMPILE([$4],
- [ int foo @<:@ 1 - 2 * !((($1) -1) < 0) @:>@ ],
- [ eval "ax_cv_decl_${typename}_signed=\"yes\"" ],
- [ eval "ax_cv_decl_${typename}_signed=\"no\"" ])])
- symbolname=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g" | tr "a-z" "A-Z"`
- if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then
- $2
- elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then
- $3
- fi
-])
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
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)
+++ /dev/null
-psi_includes() {
- local have_
- have_=`AS_ECHO($ac_header) | $as_tr_cpp`
- cat <<EOF
-#ifdef HAVE_$have_
-# include <$ac_header>
-#endif
-EOF
-}
-
-AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT()
-`psi_includes`])
-
-AC_DEFUN(PSI_LEMON, [
- AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
- AC_PATH_PROG(LEMON, lemon, ./lemon)
- PHP_SUBST(LEMON)
-])
-
-AC_DEFUN([PSI_PKG_CONFIG], [
- if test -z "$PKG_CONFIG"
- then
- AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
- fi
- export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
-])
-
-AC_DEFUN(PSI_CHECK_OFFSETOF, [
- _AC_CACHE_CHECK_INT(
- [offset of $2 in $1],
- [AS_TR_SH([ac_cv_offsetof_$1_$2])],
- [(long int) (offsetof ($1, $2))],
- [PSI_INCLUDES],
- [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
- )
- AC_DEFINE_UNQUOTED(
- AS_TR_CPP(offsetof_$1_$2),
- $AS_TR_SH([ac_cv_offsetof_$1_$2]),
- [The offset of `$2' in `$1', as computed by offsetof.]
- )
-])
-
-AC_DEFUN(PSI_CHECK_LIBJIT, [
- PHP_ARG_WITH(psi-libjit, where to find libjit,
- [ --with-psi-libjit=DIR PSI: path to libjit], [ ], [ ])
- AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
- for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
- do
- if test -e $psi_cv_libjit_dir/include/jit/jit.h
- then
- break
- fi
- psi_cv_libjit_dir=
- done
- ])
- if test -n "$psi_cv_libjit_dir"
- then
- PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
- PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
- AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
- else
- AC_MSG_WARN([Could not find libjit, please provide the base install path])
- fi
-])
-
-AC_DEFUN(PSI_CHECK_LIBFFI, [
- AC_REQUIRE([PSI_PKG_CONFIG])dnl
- PHP_ARG_WITH(psi-libffi, where to find libffi,
- [ --with-psi-libffi=DIR PSI: path to libffi], [ ], [ ])
-
- AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
- if $PKG_CONFIG --exists libffi
- then
- psi_cv_libffi=true
- else
- psi_cv_libffi=false
- fi])
- if $psi_cv_libffi
- then
- AC_MSG_CHECKING(for libffi)
- psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
- AC_MSG_RESULT($psi_cv_libffi_dir)
- PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
- PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
- AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
- else
- AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
- for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
- do
- if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
- then
- break
- fi
- psi_cv_libffi_dir=
- done])
- if test -n "$psi_cv_libffi_dir"
- then
- PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
- PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
- AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
- else
- AC_MSG_WARN([Could not find libffi, please provide the base install path])
- fi
- fi
- PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
- PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
- AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
- ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
- AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
- ], [
- PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
- AC_CHECK_HEADERS(sys/mman.h)
- PHP_CHECK_FUNC(mmap)
- AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
- ], [
- ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
- ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
-])
-
-dnl PSI_COMPUTE_STR(variable, string or expression)
-AC_DEFUN(PSI_COMPUTE_STR, [
- AC_TRY_RUN(
- PSI_INCLUDES
- [int main() {
- return EOF == fputs($2, fopen("conftest.out", "w"));
- }
- ], [
- eval $1=\\\"`cat conftest.out`\\\"
- ])
-])
+++ /dev/null
-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"
-}
-# add_int_const(name, value)
-add_int_const() {
- PSI_CONSTS="{PSI_T_INT, \"int\", \"psi\\\\$1\", \"$2\", PSI_T_NUMBER}, $PSI_CONSTS"
-}
-dnl PSI_CONST(const name, type)
-AC_DEFUN(PSI_CONST, [
- AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [
- psi_const_val=
- case $2 in
- str*)
- if test "$cross_compiling" = "yes"
- then
- AC_TRY_CPP(PSI_INCLUDES $1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=)
- else
- PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES)
- fi
- ;;
- int)
- AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES)
- ;;
- esac
- psi_cv_const_$1=$psi_const_val
- ])
- if test "$psi_cv_const_$1"
- then
- case $2 in
- str*)
- add_str_const "$1" "$psi_cv_const_$1"
- ;;
- int)
- add_int_const "$1" "$psi_cv_const_$1"
- ;;
- esac
- fi
-])
+++ /dev/null
-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_REQUIRE([AC_PROG_NM])
- AC_REQUIRE([AC_PROG_AWK])
- 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_cv_fn_$1=$psi_symbol_redirect
- ])
- case "$psi_cv_fn_$1" in
- "")
- $3
- ;;
- "$psi_symbol"|"_$psi_symbol")
- $2
- ;;
- *)
- $2
- PSI_REDIR($1)
- ;;
- esac
-])
-
-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]))
- ifelse(array_size, [],
- [m4_define([array_size], 0)],
- [m4_define([pointer_level], m4_incr(pointer_level))]
- )
- if test -n "$psi_decl_args"; then
- psi_decl_args="$psi_decl_args, "
- fi
- psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] pointer_level, array_size[}]"
-])
-
-dnl PSI_DECL(type func, args)
-AC_DEFUN(PSI_DECL, [
- psi_decl_args=
- PSI_DECL_ARG($1)
- m4_case([$2],
- [(void)], [],
- [()], [],
- [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_MACRO(PSI_VAR_NAME($1), $3, [
- add_macro "PSI_TYPE_NAME($1)" "PSI_VAR_NAME($1)" "$3"
- PSI_DECLS="{$psi_decl_args}, $PSI_DECLS"
- ])
- ])
-])
+++ /dev/null
-AC_DEFUN(PSI_CHECK_ERRNO, [
- AC_CHECK_HEADERS(errno.h)
- PSI_EXTVAR(errno, int)
- PSI_CONST(E2BIG, int)
- PSI_CONST(EACCES, int)
- PSI_CONST(EADDRINUSE, int)
- PSI_CONST(EADDRNOTAVAIL, int)
- PSI_CONST(EAFNOSUPPORT, int)
- PSI_CONST(EAGAIN, int)
- PSI_CONST(EALREADY, int)
- PSI_CONST(EBADF, int)
- PSI_CONST(EBADMSG, int)
- PSI_CONST(EBUSY, int)
- PSI_CONST(ECANCELED, int)
- PSI_CONST(ECHILD, int)
- PSI_CONST(ECONNABORTED, int)
- PSI_CONST(ECONNREFUSED, int)
- PSI_CONST(ECONNRESET, int)
- PSI_CONST(EDEADLK, int)
- PSI_CONST(EDESTADDRREQ, int)
- PSI_CONST(EDOM, int)
- PSI_CONST(EDQUOT, int)
- PSI_CONST(EEXIST, int)
- PSI_CONST(EFAULT, int)
- PSI_CONST(EFBIG, int)
- PSI_CONST(EHOSTUNREACH, int)
- PSI_CONST(EIDRM, int)
- PSI_CONST(EILSEQ, int)
- PSI_CONST(EINPROGRESS, int)
- PSI_CONST(EINTR, int)
- PSI_CONST(EINVAL, int)
- PSI_CONST(EIO, int)
- PSI_CONST(EISCONN, int)
- PSI_CONST(EISDIR, int)
- PSI_CONST(ELOOP, int)
- PSI_CONST(EMFILE, int)
- PSI_CONST(EMLINK, int)
- PSI_CONST(EMSGSIZE, int)
- PSI_CONST(EMULTIHOP, int)
- PSI_CONST(ENAMETOOLONG, int)
- PSI_CONST(ENETDOWN, int)
- PSI_CONST(ENETRESET, int)
- PSI_CONST(ENETUNREACH, int)
- PSI_CONST(ENFILE, int)
- PSI_CONST(ENOBUFS, int)
- PSI_CONST(ENODATA, int)
- PSI_CONST(ENODEV, int)
- PSI_CONST(ENOENT, int)
- PSI_CONST(ENOEXEC, int)
- PSI_CONST(ENOLCK, int)
- PSI_CONST(ENOLINK, int)
- PSI_CONST(ENOMEM, int)
- PSI_CONST(ENOMSG, int)
- PSI_CONST(ENOPROTOOPT, int)
- PSI_CONST(ENOSPC, int)
- PSI_CONST(ENOSR, int)
- PSI_CONST(ENOSTR, int)
- PSI_CONST(ENOSYS, int)
- PSI_CONST(ENOTCONN, int)
- PSI_CONST(ENOTDIR, int)
- PSI_CONST(ENOTEMPTY, int)
- PSI_CONST(ENOTRECOVERABLE, int)
- PSI_CONST(ENOTSOCK, int)
- PSI_CONST(ENOTSUP, int)
- PSI_CONST(ENOTTY, int)
- PSI_CONST(ENXIO, int)
- PSI_CONST(EOPNOTSUPP, int)
- PSI_CONST(EOVERFLOW, int)
- PSI_CONST(EOWNERDEAD, int)
- PSI_CONST(EPERM, int)
- PSI_CONST(EPIPE, int)
- PSI_CONST(EPROTO, int)
- PSI_CONST(EPROTONOSUPPORT, int)
- PSI_CONST(EPROTOTYPE, int)
- PSI_CONST(ERANGE, int)
- PSI_CONST(EROFS, int)
- PSI_CONST(ESPIPE, int)
- PSI_CONST(ESRCH, int)
- PSI_CONST(ESTALE, int)
- PSI_CONST(ETIME, int)
- PSI_CONST(ETIMEDOUT, int)
- PSI_CONST(ETXTBSY, int)
- PSI_CONST(EWOULDBLOCK, int)
- PSI_CONST(EXDEV, int)
-])
+++ /dev/null
-AC_DEFUN(PSI_CHECK_GLOB, [
- AC_CHECK_HEADERS(glob.h)
- PSI_STRUCT(glob_t, [
- size_t gl_pathc,
- int gl_matchc,
- size_t gl_offs,
- int gl_flags,
- char **gl_pathv])
-
- PSI_DECL(int glob, [(char *path, int flags, void *err, glob_t *buf)])
- PSI_DECL(void globfree, [(glob_t *buf)])
-
- PSI_CONST(GLOB_APPEND, int)
- PSI_CONST(GLOB_BRACE, int)
- PSI_CONST(GLOB_DOOFFS, int)
- PSI_CONST(GLOB_ERR, int)
- PSI_CONST(GLOB_MARK, int)
- PSI_CONST(GLOB_NOCHECK, int)
- PSI_CONST(GLOB_NOESCAPE, int)
- PSI_CONST(GLOB_NOMAGIC, int)
- PSI_CONST(GLOB_NOSORT, int)
- PSI_CONST(GLOB_ONLYDIR, int)
- PSI_CONST(GLOB_PERIOD, int)
- PSI_CONST(GLOB_TILDE, int)
- PSI_CONST(GLOB_TILDE_CHECK, int)
- PSI_CONST(GLOB_ABORTED, int)
- PSI_CONST(GLOB_NOMATCH, int)
- PSI_CONST(GLOB_NOSPACE, int)
-])
+++ /dev/null
-# arg_names(typed args)
-arg_names() {
- AS_ECHO_N([$1]) \
- | tr -cd '()' \
- | $AWK -F, '{for (i=1;i<NF;++i) print $i ","; print $NF}' \
- | $AWK '{print $NF}' \
- | xargs
-}
-PSI_MACROS=
-# gen_macro(ret type, symbol, args)
-gen_macro() {
- local dargs="$3"
- test -z "$3" && dargs="()"
- AS_ECHO_N(["static $1 psi_macro_$2$dargs {"])
- if test "$1" != "void"; then
- AS_ECHO_N(["return "])
- fi
- arg_names "$3"
- AS_ECHO_N(["$2`arg_names \"$3\"`;}"])
-}
-# add_macro(ret type, symbol, args)
-add_macro() {
- local psi_macro
- psi_macro=`gen_macro "$1" "$2" "$3"`
- PSI_MACROS="$psi_macro $PSI_MACROS"
- PSI_REDIR([$2], [psi_macro_$2])
-}
-
-dnl PSI_MACRO(macro, decl args, action-if-true)
-AC_DEFUN(PSI_MACRO, [
- AC_CHECK_DECL($1$2, $3, [], PSI_INCLUDES)
-])
-
-dnl PSI_EXTVAR(var, type)
-AC_DEFUN(PSI_EXTVAR, [
- AC_CHECK_DECL($1, [
- add_macro "$2" "$1"
- ], [], PSI_INCLUDES)
-])
+++ /dev/null
-AC_DEFUN(PSI_CHECK_STDDEF, [
- AC_CHECK_HEADERS(stddef.h)
- PSI_TYPE(ptrdiff_t, int)
- PSI_CONST(PTRDIFF_MIN, int)
- PSI_CONST(PTRDIFF_MAX, int)
- PSI_TYPE(size_t, uint)
- PSI_CONST(SIZE_MAX, int)
- PSI_TYPE(wchar_t, int)
- PSI_CONST(WCHAR_MIN, int)
- PSI_CONST(WCHAR_MAX, int)
-])
+++ /dev/null
-AC_DEFUN(PSI_CHECK_STDINT, [
- AC_CHECK_HEADERS(stdint.h)
-
- PSI_TYPE(int_least8_t, int)
- PSI_TYPE(int_least16_t, int)
- PSI_TYPE(int_least32_t, int)
- PSI_TYPE(int_least64_t, int)
- PSI_TYPE(uint_least8_t, uint)
- PSI_TYPE(uint_least16_t, uint)
- PSI_TYPE(uint_least32_t, uint)
- PSI_TYPE(uint_least64_t, uint)
- PSI_TYPE(int_fast8_t, int)
- PSI_TYPE(int_fast16_t, int)
- PSI_TYPE(int_fast32_t, int)
- PSI_TYPE(int_fast64_t, int)
- PSI_TYPE(uint_fast8_t, uint)
- PSI_TYPE(uint_fast16_t, uint)
- PSI_TYPE(uint_fast32_t, uint)
- PSI_TYPE(uint_fast64_t, uint)
- PSI_TYPE(intptr_t, int)
- PSI_TYPE(uintptr_t, uint)
- PSI_TYPE(intmax_t, int)
- PSI_TYPE(uintmax_t, uint)
-
- PSI_CONST(INT8_MIN, int)
- PSI_CONST(INT8_MAX, int)
- PSI_CONST(UINT8_MAX, int)
- PSI_CONST(INT16_MIN, int)
- PSI_CONST(INT16_MAX, int)
- PSI_CONST(UINT16_MAX, int)
- PSI_CONST(INT32_MIN, int)
- PSI_CONST(INT32_MAX, int)
- PSI_CONST(UINT32_MAX, int)
- PSI_CONST(INT64_MIN, int)
- PSI_CONST(INT64_MAX, int)
- PSI_CONST(UINT64_MAX, int)
-
- PSI_CONST(INT_LEAST8_MIN, int)
- PSI_CONST(INT_LEAST8_MAX, int)
- PSI_CONST(UINT_LEAST8_MAX, int)
- PSI_CONST(INT_LEAST16_MIN, int)
- PSI_CONST(INT_LEAST16_MAX, int)
- PSI_CONST(UINT_LEAST16_MAX, int)
- PSI_CONST(INT_LEAST32_MIN, int)
- PSI_CONST(INT_LEAST32_MAX, int)
- PSI_CONST(UINT_LEAST32_MAX, int)
- PSI_CONST(INT_LEAST64_MIN, int)
- PSI_CONST(INT_LEAST64_MAX, int)
- PSI_CONST(UINT_LEAST64_MAX, int)
-
- PSI_CONST(INT_FAST8_MIN, int)
- PSI_CONST(INT_FAST8_MAX, int)
- PSI_CONST(UINT_FAST8_MAX, int)
- PSI_CONST(INT_FAST16_MIN, int)
- PSI_CONST(INT_FAST16_MAX, int)
- PSI_CONST(UINT_FAST16_MAX, int)
- PSI_CONST(INT_FAST32_MIN, int)
- PSI_CONST(INT_FAST32_MAX, int)
- PSI_CONST(UINT_FAST32_MAX, int)
- PSI_CONST(INT_FAST64_MIN, int)
- PSI_CONST(INT_FAST64_MAX, int)
- PSI_CONST(UINT_FAST64_MAX, int)
-
- PSI_CONST(INTPTR_MIN, int)
- PSI_CONST(INTPTR_MAX, int)
- PSI_CONST(UINTPTR_MAX, int)
- PSI_CONST(INTMAX_MIN, int)
- PSI_CONST(INTMAX_MAX, int)
- PSI_CONST(UINTMAX_MAX, int)
-])
+++ /dev/null
-AC_DEFUN(PSI_CHECK_STDIO, [
- AC_CHECK_HEADER(stdio.h)
-
- PSI_STRUCT(FILE)
- PSI_STRUCT(fpos_t)
-
- PSI_CONST(BUFSIZ, int)
- PSI_CONST(_IOFBF, int)
- PSI_CONST(_IOLBF, int)
- PSI_CONST(_IONBF, int)
- PSI_CONST(SEEK_CUR, int)
- PSI_CONST(SEEK_END, int)
- PSI_CONST(SEEK_SET, int)
- PSI_CONST(FILENAME_MAX, int)
- PSI_CONST(FOPEN_MAX, int)
- PSI_CONST(TMP_MAX, int)
- PSI_CONST(EOF, int)
- PSI_CONST(P_tmpdir, string)
- PSI_CONST(L_ctermid, int)
- PSI_CONST(L_tmpnam, int)
-
- PSI_DECL(void clearerr, [(FILE *stream)])
- PSI_DECL(char *ctermid, [(char *s)])
- PSI_DECL(int fclose, [(FILE *stream)])
- PSI_DECL(FILE *fdopen, [(int fd, char *mode)])
- PSI_DECL(int feof, [(FILE *stream)])
- PSI_DECL(int ferror, [(FILE *stream)])
- PSI_DECL(int fflush, [(FILE *stream)])
- PSI_DECL(int fgetc, [(FILE *stream)])
- PSI_DECL(int fgetpos, [(FILE *stream, fpos_t *pos)])
- PSI_DECL(char *fgets, [(char *buf, int len, FILE *stream)])
- PSI_DECL(int fileno, [(FILE *stream)])
- PSI_DECL(void flockfile, [(FILE *stream)])
- PSI_DECL(FILE *fmemopen, [(void *buf, size_t len, char *mode)])
- PSI_DECL(FILE *fopen, [(char *path, char *mode)])
- PSI_DECL(int fputc, [(int c, FILE *stream)])
- PSI_DECL(int fputs, [(char *s, FILE *stream)])
- PSI_DECL(size_t fread, [(void *buf, size_t len, size_t n, FILE *stream)])
- PSI_DECL(FILE *freopen, [(char *path, char *mode, FILE *stream)])
- PSI_DECL(int fseek, [(FILE *stream, long offset, int whence)])
- PSI_DECL(int fseeko, [(FILE *stream, off_t offset, int whence)])
- PSI_DECL(int fsetpos, [(FILE *stream, fpos_t *pos)])
- PSI_DECL(long ftell, [(FILE *stream)])
- PSI_DECL(off_t ftello, [(FILE *stream)])
- PSI_DECL(int ftrylockfile, [(FILE *stream)])
- PSI_DECL(void funlockfile, [(FILE *stream)])
- PSI_DECL(size_t fwrite, [(void *buf, size_t len, size_t n, FILE *stream)])
- PSI_DECL(int getc, [(FILE *stream)])
- PSI_DECL(int getchar, [(void)])
- PSI_DECL(int getc_unlocked, [(FILE *stream)])
- PSI_DECL(int getchar_unlocked, [(void)])
- PSI_DECL(ssize_t getdelim, [(char **lineptr, size_t *n, int delim, FILE *stream)])
- PSI_DECL(ssize_t getline, [(char **lineptr, size_t *n, FILE *stream)])
- PSI_DECL(char *gets, [(char *buf)])
- PSI_DECL(FILE *open_memstream, [(char **ptr, size_t *sizeloc)])
- PSI_DECL(int pclose, [(FILE *stream)])
- PSI_DECL(void perror, [(char *s)])
- PSI_DECL(FILE *popen, [(char *command, char *type)])
- PSI_DECL(int putc, [(int c, FILE *stream)])
- PSI_DECL(int putchar, [(int c)])
- PSI_DECL(int putc_unlocked, [(int c, FILE *stream)])
- PSI_DECL(int putchar_unlocked, [(int c)])
- PSI_DECL(int puts, [(char *s)])
- PSI_DECL(int remove, [(char *path)])
- PSI_DECL(int rename, [(char *old, char *new)])
- PSI_DECL(int renameat, [(int oldfd, char *oldpath, int newfd, char *newpath)])
- PSI_DECL(void rewind, [(FILE *stream)])
- PSI_DECL(void setbuf, [(FILE *stream, char *buf)])
- PSI_DECL(int setvbuf, [(FILE *stream, char *buf, int mode, size_t size)])
- PSI_DECL(char *tempnam, [(char *dir, char *prefix)])
- PSI_DECL(FILE *tmpfile, [(void)])
- PSI_DECL(char *tmpnam, [(char *s)])
- PSI_DECL(int ungetc, [(int c, FILE *stream)])
-
-])
+++ /dev/null
-PSI_STRUCTS=
-# add_struct(name, size, members)
-add_struct() {
- local members="$3"
- if test -z "$members"; then
- members="{0}"
- else
- members="$members, {0}"
- fi
- PSI_STRUCTS="{\"$1\", $2, {$members}}, $PSI_STRUCTS"
-}
-
-AC_DEFUN(PSI_STRUCT_MEMBER, [
- m4_define([member_name], PSI_VAR_NAME($2))
- m4_define([member_type], PSI_TYPE_NAME($2))
- AC_CHECK_SIZEOF(AS_TR_SH($1)[_]member_name, [], PSI_INCLUDES
- [#define ]AS_TR_SH($1)[_]member_name (($1 *)0)->member_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"
-])
+++ /dev/null
-AC_DEFUN(PSI_CHECK_SYS_TYPES, [
- AC_CHECK_HEADERS(sys/types.h)
-
- PSI_TYPE(blkcnt_t, int)
- PSI_TYPE(blksize_t, int)
- PSI_TYPE(clock_t, int)
- PSI_TYPE(clockid_t, int)
- PSI_TYPE(dev_t, int)
- PSI_TYPE(fsblkcnt_t, uint)
- PSI_TYPE(fsfilcnt_t, uint)
- PSI_TYPE(gid_t, int)
- PSI_TYPE(id_t, int)
- PSI_TYPE(ino_t, uint)
- PSI_TYPE(key_t, int)
- PSI_TYPE(mode_t, int)
- PSI_TYPE(nlink_t, int)
- PSI_TYPE(off_t, int)
- PSI_TYPE(pid_t, int)
- PSI_TYPE(ssize_t, int)
- PSI_TYPE(suseconds_t, int)
- PSI_TYPE(time_t, int)
- PSI_TYPE(timer_t, int)
- PSI_TYPE(uid_t, int)
-])
+++ /dev/null
-# psi_type_pair(type, size)
-psi_type_pair() {
- local psi_type_name=`tr -cd A-Za-z0-9_ <<<$1`
- local psi_type_lower=`tr A-Z a-z <<<$psi_type_name`
- case $psi_type_lower in
- 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"
- ;;
- struct*)
- echo "PSI_T_STRUCT, \"$2\""
- ;;
- void)
- echo "PSI_T_VOID, \"void\""
- ;;
- *)
- echo "PSI_T_NAME, \"$psi_type_name\""
- ;;
- 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))
- AC_CHECK_SIZEOF($1, [], PSI_INCLUDES)
- psi_basic_type=$2
- case $psi_basic_type in
- int)
- AX_CHECK_SIGN($1, :, [
- psi_basic_type=uint
- ], $psi_header)
- ;;
- sint)
- psi_basic_type=int
- ;;
- esac
- if test "$2" && test "$AS_TR_SH([ac_cv_sizeof_]$1)" -gt 0; then
- AS_TR_SH(psi_basic_type_$1)=$psi_basic_type
- PSI_TYPES="{`psi_type_pair $psi_basic_type $AS_TR_SH([ac_cv_sizeof_]$1)`, \"$1\"}, $PSI_TYPES"
- fi
-])
-
-dnl unsigned char* buf[16] -> char
-AC_DEFUN(PSI_TYPE_NAME, [m4_bregexp([$1], [\(\(struct \)?[^ ]+\)[ *]+[^ ]+$], [\1])])
-dnl unsigned char* buf[16] -> buf
-AC_DEFUN(PSI_VAR_NAME, [m4_bregexp(m4_bregexp([$1], [[^ ]+$], [\&]), [\w+], [\&])])
-dnl PSI_TYPE_SIZE(type, pointer level, array size)
-AC_DEFUN(PSI_TYPE_SIZE, [ifelse(
- [$3], 0,
- [ifelse([$2], 0, $AS_TR_SH([ac_cv_sizeof_]$1), $ac_cv_sizeof_void_p)],
- [ifelse([$2], 1, [`expr $3 \* $AS_TR_SH([ac_cv_sizeof_]$1)`], $ac_cv_sizeof_void_p)]
-)])
-dnl PSI_TYPE_BITS(type)
-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\"]
-)])
-
-AC_DEFUN(PSI_CHECK_STD_TYPES, [
- AC_CHECK_HEADERS(stdint.h)
-
- AC_TYPE_INT8_T
- AC_CHECK_SIZEOF(int8_t)
- AC_CHECK_ALIGNOF(int8_t)
- AC_TYPE_UINT8_T
- AC_CHECK_SIZEOF(uint8_t)
- AC_CHECK_ALIGNOF(uint8_t)
- AC_TYPE_INT16_T
- AC_CHECK_SIZEOF(int16_t)
- AC_CHECK_ALIGNOF(int16_t)
- AC_TYPE_UINT16_T
- AC_CHECK_SIZEOF(uint16_t)
- AC_CHECK_ALIGNOF(uint16_t)
- AC_TYPE_INT32_T
- AC_CHECK_SIZEOF(int32_t)
- AC_CHECK_ALIGNOF(int32_t)
- AC_TYPE_UINT32_T
- AC_CHECK_SIZEOF(uint32_t)
- AC_CHECK_ALIGNOF(uint32_t)
- AC_TYPE_INT64_T
- AC_CHECK_SIZEOF(int64_t)
- AC_CHECK_ALIGNOF(int64_t)
- AC_TYPE_UINT64_T
- AC_CHECK_SIZEOF(uint64_t)
- AC_CHECK_ALIGNOF(uint64_t)
-
- PSI_TYPE(float)
- AC_CHECK_ALIGNOF(float)
- PSI_TYPE(double)
- AC_CHECK_ALIGNOF(double)
- PSI_TYPE(void *)
- AC_CHECK_ALIGNOF(void *)
-
- PSI_TYPE(char, int)
- PSI_TYPE(unsigned char, uint)
- PSI_TYPE(short, int)
- PSI_TYPE(unsigned short, uint)
- PSI_TYPE(int, int)
- PSI_TYPE(unsigned int, uint)
- PSI_TYPE(unsigned, uint)
- PSI_TYPE(long, int)
- PSI_TYPE(unsigned long, uint)
-])
--- /dev/null
+AC_DEFUN([AX_CHECK_SIGN], [
+ typename=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g"`
+ AC_CACHE_CHECK([whether $1 is signed], ax_cv_decl_${typename}_signed, [
+ AC_TRY_COMPILE([$4],
+ [ int foo @<:@ 1 - 2 * !((($1) -1) < 0) @:>@ ],
+ [ eval "ax_cv_decl_${typename}_signed=\"yes\"" ],
+ [ eval "ax_cv_decl_${typename}_signed=\"no\"" ])])
+ symbolname=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g" | tr "a-z" "A-Z"`
+ if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then
+ $2
+ elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then
+ $3
+ fi
+])
--- /dev/null
+AC_DEFUN(PSI_CHECK_ERRNO, [
+ AC_CHECK_HEADERS(errno.h)
+
+ PSI_EXTVAR(int errno)
+
+ PSI_CONST(E2BIG, int)
+ PSI_CONST(EACCES, int)
+ PSI_CONST(EADDRINUSE, int)
+ PSI_CONST(EADDRNOTAVAIL, int)
+ PSI_CONST(EAFNOSUPPORT, int)
+ PSI_CONST(EAGAIN, int)
+ PSI_CONST(EALREADY, int)
+ PSI_CONST(EBADF, int)
+ PSI_CONST(EBADMSG, int)
+ PSI_CONST(EBUSY, int)
+ PSI_CONST(ECANCELED, int)
+ PSI_CONST(ECHILD, int)
+ PSI_CONST(ECONNABORTED, int)
+ PSI_CONST(ECONNREFUSED, int)
+ PSI_CONST(ECONNRESET, int)
+ PSI_CONST(EDEADLK, int)
+ PSI_CONST(EDESTADDRREQ, int)
+ PSI_CONST(EDOM, int)
+ PSI_CONST(EDQUOT, int)
+ PSI_CONST(EEXIST, int)
+ PSI_CONST(EFAULT, int)
+ PSI_CONST(EFBIG, int)
+ PSI_CONST(EHOSTUNREACH, int)
+ PSI_CONST(EIDRM, int)
+ PSI_CONST(EILSEQ, int)
+ PSI_CONST(EINPROGRESS, int)
+ PSI_CONST(EINTR, int)
+ PSI_CONST(EINVAL, int)
+ PSI_CONST(EIO, int)
+ PSI_CONST(EISCONN, int)
+ PSI_CONST(EISDIR, int)
+ PSI_CONST(ELOOP, int)
+ PSI_CONST(EMFILE, int)
+ PSI_CONST(EMLINK, int)
+ PSI_CONST(EMSGSIZE, int)
+ PSI_CONST(EMULTIHOP, int)
+ PSI_CONST(ENAMETOOLONG, int)
+ PSI_CONST(ENETDOWN, int)
+ PSI_CONST(ENETRESET, int)
+ PSI_CONST(ENETUNREACH, int)
+ PSI_CONST(ENFILE, int)
+ PSI_CONST(ENOBUFS, int)
+ PSI_CONST(ENODATA, int)
+ PSI_CONST(ENODEV, int)
+ PSI_CONST(ENOENT, int)
+ PSI_CONST(ENOEXEC, int)
+ PSI_CONST(ENOLCK, int)
+ PSI_CONST(ENOLINK, int)
+ PSI_CONST(ENOMEM, int)
+ PSI_CONST(ENOMSG, int)
+ PSI_CONST(ENOPROTOOPT, int)
+ PSI_CONST(ENOSPC, int)
+ PSI_CONST(ENOSR, int)
+ PSI_CONST(ENOSTR, int)
+ PSI_CONST(ENOSYS, int)
+ PSI_CONST(ENOTCONN, int)
+ PSI_CONST(ENOTDIR, int)
+ PSI_CONST(ENOTEMPTY, int)
+ PSI_CONST(ENOTRECOVERABLE, int)
+ PSI_CONST(ENOTSOCK, int)
+ PSI_CONST(ENOTSUP, int)
+ PSI_CONST(ENOTTY, int)
+ PSI_CONST(ENXIO, int)
+ PSI_CONST(EOPNOTSUPP, int)
+ PSI_CONST(EOVERFLOW, int)
+ PSI_CONST(EOWNERDEAD, int)
+ PSI_CONST(EPERM, int)
+ PSI_CONST(EPIPE, int)
+ PSI_CONST(EPROTO, int)
+ PSI_CONST(EPROTONOSUPPORT, int)
+ PSI_CONST(EPROTOTYPE, int)
+ PSI_CONST(ERANGE, int)
+ PSI_CONST(EROFS, int)
+ PSI_CONST(ESPIPE, int)
+ PSI_CONST(ESRCH, int)
+ PSI_CONST(ESTALE, int)
+ PSI_CONST(ETIME, int)
+ PSI_CONST(ETIMEDOUT, int)
+ PSI_CONST(ETXTBSY, int)
+ PSI_CONST(EWOULDBLOCK, int)
+ PSI_CONST(EXDEV, int)
+])
--- /dev/null
+AC_DEFUN(PSI_CHECK_GLOB, [
+ AC_CHECK_HEADERS(glob.h)
+ PSI_STRUCT(glob_t, [
+ size_t gl_pathc,
+ int gl_matchc,
+ size_t gl_offs,
+ int gl_flags,
+ char **gl_pathv])
+
+ PSI_DECL(int glob, [(char *path, int flags, void *err, glob_t *buf)])
+ PSI_DECL(void globfree, [(glob_t *buf)])
+
+ PSI_CONST(GLOB_APPEND, int)
+ PSI_CONST(GLOB_BRACE, int)
+ PSI_CONST(GLOB_DOOFFS, int)
+ PSI_CONST(GLOB_ERR, int)
+ PSI_CONST(GLOB_MARK, int)
+ PSI_CONST(GLOB_NOCHECK, int)
+ PSI_CONST(GLOB_NOESCAPE, int)
+ PSI_CONST(GLOB_NOMAGIC, int)
+ PSI_CONST(GLOB_NOSORT, int)
+ PSI_CONST(GLOB_ONLYDIR, int)
+ PSI_CONST(GLOB_PERIOD, int)
+ PSI_CONST(GLOB_TILDE, int)
+ PSI_CONST(GLOB_TILDE_CHECK, int)
+ PSI_CONST(GLOB_ABORTED, int)
+ PSI_CONST(GLOB_NOMATCH, int)
+ PSI_CONST(GLOB_NOSPACE, int)
+])
--- /dev/null
+PSI_TYPES=
+PSI_STRUCTS=
+PSI_CONSTS=
+PSI_REDIRS=
+PSI_MACROS=
+PSI_DECLS=
+
+psi_includes() {
+ local have_
+ have_=`AS_ECHO($ac_header) | $as_tr_cpp`
+ cat <<EOF
+#ifdef HAVE_$have_
+# include <$ac_header>
+#endif
+EOF
+}
+
+AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT()
+`psi_includes`])
+
+AC_DEFUN(PSI_LEMON, [
+ AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
+ AC_PATH_PROG(LEMON, lemon, ./lemon)
+ PHP_SUBST(LEMON)
+])
+
+AC_DEFUN([PSI_PKG_CONFIG], [
+ if test -z "$PKG_CONFIG"
+ then
+ AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
+ fi
+ export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
+])
+
+AC_DEFUN(PSI_CHECK_OFFSETOF, [
+ _AC_CACHE_CHECK_INT(
+ [offset of $2 in $1],
+ [AS_TR_SH([ac_cv_offsetof_$1_$2])],
+ [(long int) (offsetof ($1, $2))],
+ [PSI_INCLUDES],
+ [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
+ )
+ AC_DEFINE_UNQUOTED(
+ AS_TR_CPP(offsetof_$1_$2),
+ $AS_TR_SH([ac_cv_offsetof_$1_$2]),
+ [The offset of `$2' in `$1', as computed by offsetof.]
+ )
+])
+
+AC_DEFUN(PSI_CHECK_LIBJIT, [
+ PHP_ARG_WITH(psi-libjit, where to find libjit,
+ [ --with-psi-libjit=DIR PSI: path to libjit], [ ], [ ])
+ AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
+ for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
+ do
+ if test -e $psi_cv_libjit_dir/include/jit/jit.h
+ then
+ break
+ fi
+ psi_cv_libjit_dir=
+ done
+ ])
+ if test -n "$psi_cv_libjit_dir"
+ then
+ PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
+ PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
+ AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
+ else
+ AC_MSG_WARN([Could not find libjit, please provide the base install path])
+ fi
+])
+
+AC_DEFUN(PSI_CHECK_LIBFFI, [
+ AC_REQUIRE([PSI_PKG_CONFIG])dnl
+ PHP_ARG_WITH(psi-libffi, where to find libffi,
+ [ --with-psi-libffi=DIR PSI: path to libffi], [ ], [ ])
+
+ AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
+ if $PKG_CONFIG --exists libffi
+ then
+ psi_cv_libffi=true
+ else
+ psi_cv_libffi=false
+ fi])
+ if $psi_cv_libffi
+ then
+ AC_MSG_CHECKING(for libffi)
+ psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
+ AC_MSG_RESULT($psi_cv_libffi_dir)
+ PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
+ PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
+ AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
+ else
+ AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
+ for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
+ do
+ if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
+ then
+ break
+ fi
+ psi_cv_libffi_dir=
+ done])
+ if test -n "$psi_cv_libffi_dir"
+ then
+ PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
+ PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
+ AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
+ else
+ AC_MSG_WARN([Could not find libffi, please provide the base install path])
+ fi
+ fi
+ PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
+ PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
+ AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
+ ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
+ AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
+ ], [
+ PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
+ AC_CHECK_HEADERS(sys/mman.h)
+ PHP_CHECK_FUNC(mmap)
+ AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
+ ], [
+ ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
+ ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
+])
+
+dnl PSI_COMPUTE_STR(variable, string or expression)
+AC_DEFUN(PSI_COMPUTE_STR, [
+ AC_TRY_RUN(
+ PSI_INCLUDES
+ [int main() {
+ return EOF == fputs($2, fopen("conftest.out", "w"));
+ }
+ ], [
+ eval $1=\\\"`cat conftest.out`\\\"
+ ])
+])
--- /dev/null
+# add_str_const(name, value)
+add_str_const() {
+ PSI_CONSTS="{PSI_T_STRING, \"string\", \"psi\\\\$1\", $2, PSI_T_QUOTED_STRING}, $PSI_CONSTS"
+}
+# add_int_const(name, value)
+add_int_const() {
+ PSI_CONSTS="{PSI_T_INT, \"int\", \"psi\\\\$1\", \"$2\", PSI_T_NUMBER}, $PSI_CONSTS"
+}
+dnl PSI_CONST(const name, type)
+AC_DEFUN(PSI_CONST, [
+ AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [
+ psi_const_val=
+ case $2 in
+ str*)
+ if test "$cross_compiling" = "yes"
+ then
+ AC_TRY_CPP(PSI_INCLUDES $1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=)
+ else
+ PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES)
+ fi
+ ;;
+ int)
+ AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES)
+ ;;
+ esac
+ psi_cv_const_$1=$psi_const_val
+ ])
+ if test "$psi_cv_const_$1"
+ then
+ case $2 in
+ str*)
+ add_str_const "$1" "$psi_cv_const_$1"
+ ;;
+ int)
+ add_int_const "$1" "$psi_cv_const_$1"
+ ;;
+ esac
+ fi
+])
--- /dev/null
+AC_DEFUN(PSI_REDIR, [psi_symbol=ifelse([$2],[],[$1],[$2])
+ PSI_REDIRS="{\"$1\", (void(*)(void))$psi_symbol}, $PSI_REDIRS"])
+
+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" *|@" '/^\s+U '$psi_cv_libc_main'/ {next} /^\s+U / {print$[]3; exit}'`
+ ])
+ psi_cv_fn_$1=$psi_symbol_redirect
+ ])
+ case "$psi_cv_fn_$1" in
+ "")
+ $3
+ ;;
+ "$psi_symbol"|"_$psi_symbol")
+ $2
+ ;;
+ *)
+ $2
+ PSI_REDIR($1)
+ ;;
+ esac
+])
+
+AC_DEFUN(PSI_DECL_ARG, [
+ m4_define([member_name], PSI_VAR_NAME($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))]
+ )
+ if test -n "$psi_decl_args"; then
+ psi_decl_args="$psi_decl_args, "
+ fi
+ psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] pointer_level, array_size[}]"
+])
+
+dnl PSI_DECL(type func, args)
+AC_DEFUN(PSI_DECL, [
+ psi_decl_args=
+ PSI_DECL_ARG($1)
+ m4_case([$2],
+ [(void)], [],
+ [()], [],
+ [m4_map_args_sep([PSI_DECL_ARG(], [)], [], [m4_bregexp([$2], [(\(.*\))], [\1])])])
+ PSI_FUNC(PSI_VAR_NAME($1), [
+ PSI_DECLS="$psi_decl_args, {0}, $PSI_DECLS"
+ ], [
+ PSI_MACRO($1, $2, [
+ PSI_DECLS="$psi_decl_args, {0}, $PSI_DECLS"
+ ])
+ ])
+])
--- /dev/null
+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)])
--- /dev/null
+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
+])
--- /dev/null
+# psi_type_pair(type, size)
+psi_type_pair() {
+ local psi_type_name=`tr -cd A-Za-z0-9_ <<<$1`
+ local psi_type_lower=`tr A-Z a-z <<<$psi_type_name`
+ case $psi_type_lower in
+ int*|uint*)
+ local psi_type_upper=`tr a-z A-Z <<<$psi_type_name`
+ local psi_type_bits=`expr $2 \* 8`
+ 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"
+ ;;
+ struct*)
+ echo "PSI_T_STRUCT, \"$2\""
+ ;;
+ void)
+ echo "PSI_T_VOID, \"void\""
+ ;;
+ *)
+ echo "PSI_T_NAME, \"$psi_type_name\""
+ ;;
+ esac
+}
+
+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))
+ AC_CHECK_SIZEOF($1, [], PSI_INCLUDES)
+ psi_basic_type=$2
+ case $psi_basic_type in
+ int)
+ AX_CHECK_SIGN($1, :, [
+ psi_basic_type=uint
+ ], $psi_header)
+ ;;
+ sint)
+ psi_basic_type=int
+ ;;
+ esac
+ if test "$2" && test "$AS_TR_SH([ac_cv_sizeof_]$1)" -gt 0; then
+ AS_TR_SH(psi_basic_type_$1)=$psi_basic_type
+ PSI_TYPES="{`psi_type_pair $psi_basic_type $AS_TR_SH([ac_cv_sizeof_]$1)`, \"$1\"}, $PSI_TYPES"
+ fi
+])
+
+dnl unsigned char* buf[16] -> char
+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], [\([^ ]+\)$], [\1]), [\w+], [\&])])
+dnl PSI_TYPE_SIZE(type, pointer level, array size)
+AC_DEFUN(PSI_TYPE_SIZE, [ifelse(
+ [$3], 0,
+ [ifelse([$2], 0, $AS_TR_SH([ac_cv_sizeof_]$1), $ac_cv_sizeof_void_p)],
+ [ifelse([$2], 1, [`expr $3 \* $AS_TR_SH([ac_cv_sizeof_]$1)`], $ac_cv_sizeof_void_p)]
+)])
+dnl PSI_TYPE_BITS(type)
+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\"])])
+
+AC_DEFUN(PSI_CHECK_STD_TYPES, [
+ AC_CHECK_HEADERS(stdint.h)
+
+ AC_TYPE_INT8_T
+ AC_CHECK_SIZEOF(int8_t)
+ AC_CHECK_ALIGNOF(int8_t)
+ AC_TYPE_UINT8_T
+ AC_CHECK_SIZEOF(uint8_t)
+ AC_CHECK_ALIGNOF(uint8_t)
+ AC_TYPE_INT16_T
+ AC_CHECK_SIZEOF(int16_t)
+ AC_CHECK_ALIGNOF(int16_t)
+ AC_TYPE_UINT16_T
+ AC_CHECK_SIZEOF(uint16_t)
+ AC_CHECK_ALIGNOF(uint16_t)
+ AC_TYPE_INT32_T
+ AC_CHECK_SIZEOF(int32_t)
+ AC_CHECK_ALIGNOF(int32_t)
+ AC_TYPE_UINT32_T
+ AC_CHECK_SIZEOF(uint32_t)
+ AC_CHECK_ALIGNOF(uint32_t)
+ AC_TYPE_INT64_T
+ AC_CHECK_SIZEOF(int64_t)
+ AC_CHECK_ALIGNOF(int64_t)
+ AC_TYPE_UINT64_T
+ AC_CHECK_SIZEOF(uint64_t)
+ AC_CHECK_ALIGNOF(uint64_t)
+
+ PSI_TYPE(float)
+ AC_CHECK_ALIGNOF(float)
+ PSI_TYPE(double)
+ AC_CHECK_ALIGNOF(double)
+ PSI_TYPE(void *)
+ AC_CHECK_ALIGNOF(void *)
+
+ PSI_TYPE(char, int)
+ PSI_TYPE(unsigned char, uint)
+ PSI_TYPE(short, int)
+ PSI_TYPE(unsigned short, uint)
+ PSI_TYPE(int, int)
+ PSI_TYPE(unsigned int, uint)
+ PSI_TYPE(unsigned, uint)
+ PSI_TYPE(long, int)
+ PSI_TYPE(unsigned long, uint)
+])
--- /dev/null
+AC_DEFUN(PSI_CHECK_STDDEF, [
+ AC_CHECK_HEADERS(stddef.h)
+ PSI_TYPE(ptrdiff_t, int)
+ PSI_CONST(PTRDIFF_MIN, int)
+ PSI_CONST(PTRDIFF_MAX, int)
+ PSI_TYPE(size_t, uint)
+ PSI_CONST(SIZE_MAX, int)
+ PSI_TYPE(wchar_t, int)
+ PSI_CONST(WCHAR_MIN, int)
+ PSI_CONST(WCHAR_MAX, int)
+])
--- /dev/null
+AC_DEFUN(PSI_CHECK_STDINT, [
+ AC_CHECK_HEADERS(stdint.h)
+
+ PSI_TYPE(int_least8_t, int)
+ PSI_TYPE(int_least16_t, int)
+ PSI_TYPE(int_least32_t, int)
+ PSI_TYPE(int_least64_t, int)
+ PSI_TYPE(uint_least8_t, uint)
+ PSI_TYPE(uint_least16_t, uint)
+ PSI_TYPE(uint_least32_t, uint)
+ PSI_TYPE(uint_least64_t, uint)
+ PSI_TYPE(int_fast8_t, int)
+ PSI_TYPE(int_fast16_t, int)
+ PSI_TYPE(int_fast32_t, int)
+ PSI_TYPE(int_fast64_t, int)
+ PSI_TYPE(uint_fast8_t, uint)
+ PSI_TYPE(uint_fast16_t, uint)
+ PSI_TYPE(uint_fast32_t, uint)
+ PSI_TYPE(uint_fast64_t, uint)
+ PSI_TYPE(intptr_t, int)
+ PSI_TYPE(uintptr_t, uint)
+ PSI_TYPE(intmax_t, int)
+ PSI_TYPE(uintmax_t, uint)
+
+ PSI_CONST(INT8_MIN, int)
+ PSI_CONST(INT8_MAX, int)
+ PSI_CONST(UINT8_MAX, int)
+ PSI_CONST(INT16_MIN, int)
+ PSI_CONST(INT16_MAX, int)
+ PSI_CONST(UINT16_MAX, int)
+ PSI_CONST(INT32_MIN, int)
+ PSI_CONST(INT32_MAX, int)
+ PSI_CONST(UINT32_MAX, int)
+ PSI_CONST(INT64_MIN, int)
+ PSI_CONST(INT64_MAX, int)
+ PSI_CONST(UINT64_MAX, int)
+
+ PSI_CONST(INT_LEAST8_MIN, int)
+ PSI_CONST(INT_LEAST8_MAX, int)
+ PSI_CONST(UINT_LEAST8_MAX, int)
+ PSI_CONST(INT_LEAST16_MIN, int)
+ PSI_CONST(INT_LEAST16_MAX, int)
+ PSI_CONST(UINT_LEAST16_MAX, int)
+ PSI_CONST(INT_LEAST32_MIN, int)
+ PSI_CONST(INT_LEAST32_MAX, int)
+ PSI_CONST(UINT_LEAST32_MAX, int)
+ PSI_CONST(INT_LEAST64_MIN, int)
+ PSI_CONST(INT_LEAST64_MAX, int)
+ PSI_CONST(UINT_LEAST64_MAX, int)
+
+ PSI_CONST(INT_FAST8_MIN, int)
+ PSI_CONST(INT_FAST8_MAX, int)
+ PSI_CONST(UINT_FAST8_MAX, int)
+ PSI_CONST(INT_FAST16_MIN, int)
+ PSI_CONST(INT_FAST16_MAX, int)
+ PSI_CONST(UINT_FAST16_MAX, int)
+ PSI_CONST(INT_FAST32_MIN, int)
+ PSI_CONST(INT_FAST32_MAX, int)
+ PSI_CONST(UINT_FAST32_MAX, int)
+ PSI_CONST(INT_FAST64_MIN, int)
+ PSI_CONST(INT_FAST64_MAX, int)
+ PSI_CONST(UINT_FAST64_MAX, int)
+
+ PSI_CONST(INTPTR_MIN, int)
+ PSI_CONST(INTPTR_MAX, int)
+ PSI_CONST(UINTPTR_MAX, int)
+ PSI_CONST(INTMAX_MIN, int)
+ PSI_CONST(INTMAX_MAX, int)
+ PSI_CONST(UINTMAX_MAX, int)
+])
--- /dev/null
+AC_DEFUN(PSI_CHECK_STDIO, [
+ AC_CHECK_HEADER(stdio.h)
+
+ PSI_STRUCT(FILE)
+ PSI_STRUCT(fpos_t)
+
+ PSI_CONST(BUFSIZ, int)
+ PSI_CONST(_IOFBF, int)
+ PSI_CONST(_IOLBF, int)
+ PSI_CONST(_IONBF, int)
+ PSI_CONST(SEEK_CUR, int)
+ PSI_CONST(SEEK_END, int)
+ PSI_CONST(SEEK_SET, int)
+ PSI_CONST(FILENAME_MAX, int)
+ PSI_CONST(FOPEN_MAX, int)
+ PSI_CONST(TMP_MAX, int)
+ PSI_CONST(EOF, int)
+ PSI_CONST(P_tmpdir, string)
+ PSI_CONST(L_ctermid, int)
+ PSI_CONST(L_tmpnam, int)
+
+ PSI_DECL(void clearerr, [(FILE *stream)])
+ PSI_DECL(char *ctermid, [(char *s)])
+ PSI_DECL(int fclose, [(FILE *stream)])
+ PSI_DECL(FILE *fdopen, [(int fd, char *mode)])
+ PSI_DECL(int feof, [(FILE *stream)])
+ PSI_DECL(int ferror, [(FILE *stream)])
+ PSI_DECL(int fflush, [(FILE *stream)])
+ PSI_DECL(int fgetc, [(FILE *stream)])
+ PSI_DECL(int fgetpos, [(FILE *stream, fpos_t *pos)])
+ PSI_DECL(char *fgets, [(char *buf, int len, FILE *stream)])
+ PSI_DECL(int fileno, [(FILE *stream)])
+ PSI_DECL(void flockfile, [(FILE *stream)])
+ PSI_DECL(FILE *fmemopen, [(void *buf, size_t len, char *mode)])
+ PSI_DECL(FILE *fopen, [(char *path, char *mode)])
+ PSI_DECL(int fputc, [(int c, FILE *stream)])
+ PSI_DECL(int fputs, [(char *s, FILE *stream)])
+ PSI_DECL(size_t fread, [(void *buf, size_t len, size_t n, FILE *stream)])
+ PSI_DECL(FILE *freopen, [(char *path, char *mode, FILE *stream)])
+ PSI_DECL(int fseek, [(FILE *stream, long offset, int whence)])
+ PSI_DECL(int fseeko, [(FILE *stream, off_t offset, int whence)])
+ PSI_DECL(int fsetpos, [(FILE *stream, fpos_t *pos)])
+ PSI_DECL(long ftell, [(FILE *stream)])
+ PSI_DECL(off_t ftello, [(FILE *stream)])
+ PSI_DECL(int ftrylockfile, [(FILE *stream)])
+ PSI_DECL(void funlockfile, [(FILE *stream)])
+ PSI_DECL(size_t fwrite, [(void *buf, size_t len, size_t n, FILE *stream)])
+ PSI_DECL(int getc, [(FILE *stream)])
+ PSI_DECL(int getchar, [(void)])
+ PSI_DECL(int getc_unlocked, [(FILE *stream)])
+ PSI_DECL(int getchar_unlocked, [(void)])
+ PSI_DECL(ssize_t getdelim, [(char **lineptr, size_t *n, int delim, FILE *stream)])
+ PSI_DECL(ssize_t getline, [(char **lineptr, size_t *n, FILE *stream)])
+ PSI_DECL(char *gets, [(char *buf)])
+ PSI_DECL(FILE *open_memstream, [(char **ptr, size_t *sizeloc)])
+ PSI_DECL(int pclose, [(FILE *stream)])
+ PSI_DECL(void perror, [(char *s)])
+ PSI_DECL(FILE *popen, [(char *command, char *type)])
+ PSI_DECL(int putc, [(int c, FILE *stream)])
+ PSI_DECL(int putchar, [(int c)])
+ PSI_DECL(int putc_unlocked, [(int c, FILE *stream)])
+ PSI_DECL(int putchar_unlocked, [(int c)])
+ PSI_DECL(int puts, [(char *s)])
+ PSI_DECL(int remove, [(char *path)])
+ PSI_DECL(int rename, [(char *old, char *new)])
+ PSI_DECL(int renameat, [(int oldfd, char *oldpath, int newfd, char *newpath)])
+ PSI_DECL(void rewind, [(FILE *stream)])
+ PSI_DECL(void setbuf, [(FILE *stream, char *buf)])
+ PSI_DECL(int setvbuf, [(FILE *stream, char *buf, int mode, size_t size)])
+ PSI_DECL(char *tempnam, [(char *dir, char *prefix)])
+ PSI_DECL(FILE *tmpfile, [(void)])
+ PSI_DECL(char *tmpnam, [(char *s)])
+ PSI_DECL(int ungetc, [(int c, FILE *stream)])
+
+])
--- /dev/null
+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)])
+])
+
--- /dev/null
+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)])
+])
--- /dev/null
+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@:>@)])
+])
--- /dev/null
+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)])
+])
--- /dev/null
+AC_DEFUN(PSI_CHECK_SYS_TYPES, [
+ AC_CHECK_HEADERS(sys/types.h)
+
+ PSI_TYPE(blkcnt_t, int)
+ PSI_TYPE(blksize_t, int)
+ PSI_TYPE(clock_t, int)
+ PSI_TYPE(clockid_t, int)
+ PSI_TYPE(dev_t, int)
+ PSI_TYPE(fsblkcnt_t, uint)
+ PSI_TYPE(fsfilcnt_t, uint)
+ PSI_TYPE(gid_t, int)
+ PSI_TYPE(id_t, int)
+ PSI_TYPE(ino_t, uint)
+ PSI_TYPE(key_t, int)
+ PSI_TYPE(mode_t, int)
+ PSI_TYPE(nlink_t, int)
+ PSI_TYPE(off_t, int)
+ PSI_TYPE(pid_t, int)
+ PSI_TYPE(ssize_t, int)
+ PSI_TYPE(suseconds_t, int)
+ PSI_TYPE(time_t, int)
+ PSI_TYPE(timer_t, int)
+ PSI_TYPE(uid_t, int)
+])
--- /dev/null
+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)])
+])
--- /dev/null
+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, [()])
+])
--- /dev/null
+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)
+])
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);
-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);
to_int(gl_flags),
to_array(**gl_pathv, gl_pathc, gl_offs, to_string(*gl_pathv))
);
- //free globfree(buf);
+ free globfree(buf);
}
-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);
-extern time_t time(time_t *t);
function psi\time() : int {
let t = NULL;
return to_int(time);
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));
}
#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];
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) {
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;
}
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 */
}
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!)");
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) {
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));
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)) {
}
}
- 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)) {
}
}
- 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)) {
}
}
+ 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);
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;
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);
}