From: Michael Wallner Date: Mon, 23 Nov 2015 13:42:41 +0000 (+0100) Subject: flush X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3137da963d298c73ce3bc858874fdfc87fa941b7;p=m6w6%2Fext-psi flush --- diff --git a/config.m4 b/config.m4 index c05ed05..1207c0c 100644 --- a/config.m4 +++ b/config.m4 @@ -9,12 +9,18 @@ if test "$PHP_PSI" != no; then 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) - sinclude(config.psi_type.m4) PSI_LEMON PSI_CHECK_LIBJIT @@ -29,11 +35,13 @@ if test "$PHP_PSI" != no; then PSI_CHECK_SYS_TYPES PSI_CHECK_ERRNO PSI_CHECK_GLOB + PSI_CHECK_STDIO echo PSI_TYPES=$PSI_TYPES echo PSI_MACROS=$PSI_MACROS - echo PSI_REDIR=$PSI_REDIR + echo PSI_REDIRS=$PSI_REDIRS echo PSI_DECLS=$PSI_DECLS + echo PSI_STRUCTS=$PSI_STRUCTS PHP_SUBST(PSI_SHARED_LIBADD) diff --git a/config.psi.m4 b/config.psi.m4 index d64846a..09ca497 100644 --- a/config.psi.m4 +++ b/config.psi.m4 @@ -8,7 +8,8 @@ psi_includes() { EOF } -AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT([`psi_includes`])]) +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) diff --git a/config.psi_const.m4 b/config.psi_const.m4 new file mode 100644 index 0000000..db08f62 --- /dev/null +++ b/config.psi_const.m4 @@ -0,0 +1,40 @@ +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 +]) diff --git a/config.psi_decl.m4 b/config.psi_decl.m4 new file mode 100644 index 0000000..2a89205 --- /dev/null +++ b/config.psi_decl.m4 @@ -0,0 +1,64 @@ +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" + ]) + ]) +]) diff --git a/config.psi_glob.m4 b/config.psi_glob.m4 index 26896e3..fbb036e 100644 --- a/config.psi_glob.m4 +++ b/config.psi_glob.m4 @@ -6,8 +6,10 @@ AC_DEFUN(PSI_CHECK_GLOB, [ 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_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) diff --git a/config.psi_macro.m4 b/config.psi_macro.m4 new file mode 100644 index 0000000..88702a9 --- /dev/null +++ b/config.psi_macro.m4 @@ -0,0 +1,39 @@ +# 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.psi_type.m4 b/config.psi_type.m4 index 99dbb24..4e9aa16 100644 --- a/config.psi_type.m4 +++ b/config.psi_type.m4 @@ -1,11 +1,14 @@ -psi_type_pair() { # (type, size) - local psi_type_name=`tr -cd A-Za-z <<<$1` +# 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\"" @@ -35,154 +38,30 @@ AC_DEFUN(PSI_TYPE, [ psi_basic_type=int ;; esac - if test "$2" && test "$ac_cv_sizeof_[]$1" -gt 0; then + 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 $ac_cv_sizeof_[]$1`, \""$1"\"}, $PSI_TYPES" + PSI_TYPES="{`psi_type_pair $psi_basic_type $AS_TR_SH([ac_cv_sizeof_]$1)`, \"$1\"}, $PSI_TYPES" fi ]) -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 -]) - -PSI_DECLS= -# add_decl(ret type, symbol, args) -add_decl() { - local size - eval size=\$ac_cv_sizeof_$1 - PSI_DECLS="{`psi_type_pair \"$1\" \"$size\"`, \"$2\"}, $PSI_DECLS" -} -PSI_REDIR= -# add_redir(symbol, macro=symbol) -add_redir() { - local sym=$2 - test -z "$sym" && sym=$1 - PSI_REDIR="{\"$1\", (void (*)(void)) $sym}, $PSI_REDIR" -} -# arg_names(typed args) -arg_names() { - AS_ECHO_N([$1]) \ - | tr -cd '()' \ - | $AWK -F, '{for (i=1;i 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)`]) -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 ;; - *) add_redir "$psi_symbol"; $2 ;; - esac -]) - -dnl PSI_EXTVAR(var, type) -AC_DEFUN(PSI_EXTVAR, [ - AC_CHECK_DECL($1, [ - add_macro "$2" "$1" - ], [], PSI_INCLUDES) -]) - - -dnl PSI_DECL(ret type, func, args) -AC_DEFUN(PSI_DECL, [ - PSI_FUNC($2, [ - add_decl "$1" "$2" "$3" - ], [ - PSI_MACRO($2, $3, [ - add_macro "$1" "$2" "$3" - add_decl "$1" "$2" "$3" - ]) - ]) -]) - -AC_DEFUN(PSI_STRUCT_MEMBER, [ - psi_member_name= - psi_member_type= - m4_map_args_w([$1], [ - psi_member_type="$psi_member_type $psi_member_name" - psi_member_name=], [ - ]) - AC_MSG_RESULT([member=$psi_member_name - $psi_member_type]) -]) - -AC_DEFUN(PSI_STRUCT, [ - AC_CHECK_SIZEOF($1, [], PSI_INCLUDES) - m4_map_args([PSI_STRUCT_MEMBER], $2) - exit -]) +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) @@ -220,7 +99,12 @@ AC_DEFUN(PSI_CHECK_STD_TYPES, [ 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) ])