From b66b59e993d9feab6630386140ca178d6e750e52 Mon Sep 17 00:00:00 2001 From: DontCryAndPlay Keikira Date: Tue, 18 Jun 2019 18:59:32 +0200 Subject: [PATCH 1/6] New config file for phpize fixing common bugs. Still there's work in progress... --- config.m4 | 81 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 11 deletions(-) diff --git a/config.m4 b/config.m4 index 18d4bdb..16f7f37 100644 --- a/config.m4 +++ b/config.m4 @@ -1,20 +1,79 @@ -PHP_ARG_WITH(phplpsolve55,[lpsolve 5.5] -[ with-phplpsolve55=[Insert path to lp_solve here] Include lpsolve Support]) +PHP_ARG_WITH(phplpsolve55, for liblpsolve55, +[ --with-phplpsolve55=DIR Installation prefix of liblpsolve55. + If DIR is not specified, use the system library.]) if test $PHP_PHPLPSOLVE55 != "no"; then - if test -f "$PHP_PHPLPSOLVE55/lp_lib.h"; then - PHP_CHECK_LIBRARY(lpsolve55, make_lp,,[AC_MSG_ERROR([Invalid phplpsolve55 library, make_lp() not found])],-L/usr/lib) - else - dnl This will cancel configuration if the required headers aren't found - AC_MSG_ERROR([lp_lib.h not found]) +# if test -f "$PHP_PHPLPSOLVE55/lp_lib.h"; then +# PHP_CHECK_LIBRARY(lpsolve55, make_lp,,[AC_MSG_ERROR([Invalid phplpsolve55 library, make_lp() not found])]) +# else +# dnl This will cancel configuration if the required headers aren't found +# AC_MSG_ERROR([lp_lib.h not found]) +# fi + +# PHP_ADD_LIBRARY_WITH_PATH(lpsolve55, /usr/local/lib, PHPLPSOLVE55_SHARED_LIBADD) + #PHP_ADD_LIBRARY(lpsolve55,, PHPLPSOLVE55_SHARED_LIBADD) + #PHP_ADD_LIBRARY(lpsolve55) + EXTRA_LIBS="-lm" + #AC_MSG_ERROR($LDFLAGS) + AC_CHECK_LIB(dl, dlopen, [ + EXTRA_LIBS="$EXTRA_LIBS -ldl" + PHP_ADD_LIBRARY(dl, 1, PHPLPSOLVE55_SHARED_LIBADD) + ]) + AC_CHECK_LIB(colamd, colamd, [ + EXTRA_LIBS="$EXTRA_LIBS -lcolamd" + ]) + dnl Find the header file: + AC_MSG_CHECKING([for lp_lib.h]) + for i in $PHP_PHPLPSOLVE55 /usr/include/lpsolve /usr/local/include/lpsolve; do + if test -r "$i/lp_lib.h"; then + LIBLPSOLVE_INCDIR="$i" + AC_MSG_RESULT($i) + break + fi + done + + if test -z "$LIBLPSOLVE_INCDIR"; then + AC_MSG_RESULT([not found]) + AC_MSG_ERROR([Could not find lp_lib.h]) fi - PHP_ADD_LIBRARY_WITH_PATH(lpsolve55, /usr/local/lib, PHPLPSOLVE55_SHARED_LIBADD) - PHP_ADD_INCLUDE($PHP_PHPLPSOLVE55) - AC_MSG_RESULT([lpsolve in $PHP_PHPLPSOLVE55]) - AC_DEFINE(PHP,1,[liblpsolve55 found and included]) + dnl Find the shared library: + LDFLAGS="-Wl,--no-as-needed" + for i in /usr/local/lib /usr/lib /lib; do + if test -r "$i/liblpsolve55.so"; then + PHP_CHECK_LIBRARY(lpsolve55, make_lp,[ + #AC_DEFINE([HAVE_LIBLPSOLVE55], 1, [liblpsolve55 found and included]) + PHP_ADD_LIBRARY_WITH_PATH(lpsolve55, $i, PHPLPSOLVE55_SHARED_LIBADD) + PHP_ADD_INCLUDE($LIBLPSOLVE_INCDIR) + LIBLPSOLVE_LIBDIR="$i" + break + ],[ + continue + ],[ + -L$i $EXTRA_LIBS + ] + ) + fi + done + + if test -z "$LIBLPSOLVE_LIBDIR"; then + PHP_CHECK_LIBRARY(lpsolve55, make_lp,[ + #AC_DEFINE([HAVE_LIBLPSOLVE55], 1, [liblpsolve55 found and included]) + PHP_ADD_LIBRARY(lpsolve55, 1, PHPLPSOLVE55_SHARED_LIBADD) + PHP_ADD_INCLUDE($LIBLPSOLVE_INCDIR) + LIBLPSOLVE_LIBDIR="$i" + ],[ + AC_MSG_ERROR([Could not find liblpsolve55.so or symbol make_lp. Check version and config.log for more information.]) + ],[ + $EXTRA_LIBS + ] + ) + fi + LDFLAGS="" AC_DEFINE(DEMO,1,[DEMO code in lpsolve]) + AC_DEFINE(PHP,1,[liblpsolve55 found and included]) PHP_NEW_EXTENSION(phplpsolve55, PHPmod.c hash.c lpsolve.c, $ext_shared) + #AC_MSG_ERROR($PHPLPSOLVE55_SHARED_LIBADD) PHP_SUBST(PHPLPSOLVE55_SHARED_LIBADD) fi From 1648567c6863585c4782b8ad4ccdd9a59c397812 Mon Sep 17 00:00:00 2001 From: DontCryAndPlay Keikira Date: Tue, 18 Jun 2019 19:04:15 +0200 Subject: [PATCH 2/6] Fix compilation issue on FreeBSD --- hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hash.c b/hash.c index b990f3f..d642b1c 100644 --- a/hash.c +++ b/hash.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include "hash.h" From 2085cd5ec4144ae07753efc5906f45ff4cd1495a Mon Sep 17 00:00:00 2001 From: DontCryAndPlay Keikira Date: Tue, 18 Jun 2019 19:18:35 +0200 Subject: [PATCH 3/6] Cleanup and fix on some GNU/Linux systems --- config.m4 | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/config.m4 b/config.m4 index 16f7f37..fbb2e93 100644 --- a/config.m4 +++ b/config.m4 @@ -3,18 +3,7 @@ PHP_ARG_WITH(phplpsolve55, for liblpsolve55, If DIR is not specified, use the system library.]) if test $PHP_PHPLPSOLVE55 != "no"; then -# if test -f "$PHP_PHPLPSOLVE55/lp_lib.h"; then -# PHP_CHECK_LIBRARY(lpsolve55, make_lp,,[AC_MSG_ERROR([Invalid phplpsolve55 library, make_lp() not found])]) -# else -# dnl This will cancel configuration if the required headers aren't found -# AC_MSG_ERROR([lp_lib.h not found]) -# fi - -# PHP_ADD_LIBRARY_WITH_PATH(lpsolve55, /usr/local/lib, PHPLPSOLVE55_SHARED_LIBADD) - #PHP_ADD_LIBRARY(lpsolve55,, PHPLPSOLVE55_SHARED_LIBADD) - #PHP_ADD_LIBRARY(lpsolve55) EXTRA_LIBS="-lm" - #AC_MSG_ERROR($LDFLAGS) AC_CHECK_LIB(dl, dlopen, [ EXTRA_LIBS="$EXTRA_LIBS -ldl" PHP_ADD_LIBRARY(dl, 1, PHPLPSOLVE55_SHARED_LIBADD) @@ -42,7 +31,6 @@ if test $PHP_PHPLPSOLVE55 != "no"; then for i in /usr/local/lib /usr/lib /lib; do if test -r "$i/liblpsolve55.so"; then PHP_CHECK_LIBRARY(lpsolve55, make_lp,[ - #AC_DEFINE([HAVE_LIBLPSOLVE55], 1, [liblpsolve55 found and included]) PHP_ADD_LIBRARY_WITH_PATH(lpsolve55, $i, PHPLPSOLVE55_SHARED_LIBADD) PHP_ADD_INCLUDE($LIBLPSOLVE_INCDIR) LIBLPSOLVE_LIBDIR="$i" @@ -58,7 +46,6 @@ if test $PHP_PHPLPSOLVE55 != "no"; then if test -z "$LIBLPSOLVE_LIBDIR"; then PHP_CHECK_LIBRARY(lpsolve55, make_lp,[ - #AC_DEFINE([HAVE_LIBLPSOLVE55], 1, [liblpsolve55 found and included]) PHP_ADD_LIBRARY(lpsolve55, 1, PHPLPSOLVE55_SHARED_LIBADD) PHP_ADD_INCLUDE($LIBLPSOLVE_INCDIR) LIBLPSOLVE_LIBDIR="$i" @@ -73,7 +60,4 @@ if test $PHP_PHPLPSOLVE55 != "no"; then AC_DEFINE(DEMO,1,[DEMO code in lpsolve]) AC_DEFINE(PHP,1,[liblpsolve55 found and included]) PHP_NEW_EXTENSION(phplpsolve55, PHPmod.c hash.c lpsolve.c, $ext_shared) - #AC_MSG_ERROR($PHPLPSOLVE55_SHARED_LIBADD) - PHP_SUBST(PHPLPSOLVE55_SHARED_LIBADD) -fi - +fi \ No newline at end of file From 4eb7c77ff357a0e679df9e396693e582e2e56242 Mon Sep 17 00:00:00 2001 From: DontCryAndPlay Keikira Date: Tue, 18 Jun 2019 20:43:27 +0200 Subject: [PATCH 4/6] Some fixes for FreeBSD and GNU/Linux --- config.m4 | 43 ++++++++++++++++++++++++------------------- hash.h | 15 ++++++++------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/config.m4 b/config.m4 index fbb2e93..060f84f 100644 --- a/config.m4 +++ b/config.m4 @@ -29,35 +29,40 @@ if test $PHP_PHPLPSOLVE55 != "no"; then dnl Find the shared library: LDFLAGS="-Wl,--no-as-needed" for i in /usr/local/lib /usr/lib /lib; do - if test -r "$i/liblpsolve55.so"; then - PHP_CHECK_LIBRARY(lpsolve55, make_lp,[ - PHP_ADD_LIBRARY_WITH_PATH(lpsolve55, $i, PHPLPSOLVE55_SHARED_LIBADD) + for j in lpsolve55_pic lpsolve55; do + if test -r "$i/lib$j.so"; then + PHP_CHECK_LIBRARY($j, make_lp,[ + PHP_ADD_LIBRARY_WITH_PATH($j, $i, PHPLPSOLVE55_SHARED_LIBADD) + PHP_ADD_INCLUDE($LIBLPSOLVE_INCDIR) + LIBLPSOLVE_LIBDIR="$i" + break 2 + ],[ + continue + ],[ + -L$i $EXTRA_LIBS + ] + ) + fi + done + done + + for i in lpsolve55_pic lpsolve55; do + if test -z "$LIBLPSOLVE_LIBDIR"; then + PHP_CHECK_LIBRARY($i, make_lp,[ + PHP_ADD_LIBRARY($i, 1, PHPLPSOLVE55_SHARED_LIBADD) PHP_ADD_INCLUDE($LIBLPSOLVE_INCDIR) LIBLPSOLVE_LIBDIR="$i" - break ],[ - continue + AC_MSG_ERROR([Could not find liblpsolve55.so or symbol make_lp. Check version and config.log for more information.]) ],[ - -L$i $EXTRA_LIBS + $EXTRA_LIBS ] ) fi done - - if test -z "$LIBLPSOLVE_LIBDIR"; then - PHP_CHECK_LIBRARY(lpsolve55, make_lp,[ - PHP_ADD_LIBRARY(lpsolve55, 1, PHPLPSOLVE55_SHARED_LIBADD) - PHP_ADD_INCLUDE($LIBLPSOLVE_INCDIR) - LIBLPSOLVE_LIBDIR="$i" - ],[ - AC_MSG_ERROR([Could not find liblpsolve55.so or symbol make_lp. Check version and config.log for more information.]) - ],[ - $EXTRA_LIBS - ] - ) - fi LDFLAGS="" AC_DEFINE(DEMO,1,[DEMO code in lpsolve]) AC_DEFINE(PHP,1,[liblpsolve55 found and included]) + PHP_SUBST(PHPLPSOLVE55_SHARED_LIBADD) PHP_NEW_EXTENSION(phplpsolve55, PHPmod.c hash.c lpsolve.c, $ext_shared) fi \ No newline at end of file diff --git a/hash.h b/hash.h index b783068..caa823c 100644 --- a/hash.h +++ b/hash.h @@ -23,13 +23,14 @@ typedef struct _hashtable extern "C" { #endif -hashtable *create_hash_table(int size, int base); -void free_hash_table(hashtable *ht); -hashelem *findhash(const char *name, hashtable *ht); -hashelem *puthash(const char *name, int index, hashelem **list, hashtable *ht); -void drophash(const char *name, hashelem **list, hashtable *ht); -void free_hash_item(hashelem **hp); -hashtable *copy_hash_table(hashtable *ht, hashelem **list, int newsize); +static inline hashtable *create_hash_table(int size, int base); +static inline void free_hash_table(hashtable *ht); +static inline hashelem *findhash(const char *name, hashtable *ht); +static inline hashelem *puthash(const char *name, int index, hashelem **list, hashtable *ht); +static inline void drophash(const char *name, hashelem **list, hashtable *ht); +static inline void free_hash_item(hashelem **hp); +static inline hashtable *copy_hash_table(hashtable *ht, hashelem **list, int newsize); +static inline int hashval(const char *string, int size); #ifdef __cplusplus } From 75f77e4a354c191a92ecf814af538887b47fcb53 Mon Sep 17 00:00:00 2001 From: DontCryAndPlay Keikira Date: Tue, 18 Jun 2019 20:43:50 +0200 Subject: [PATCH 5/6] First quick test --- tests/01-empty.phpt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/01-empty.phpt diff --git a/tests/01-empty.phpt b/tests/01-empty.phpt new file mode 100644 index 0000000..a68b0ba --- /dev/null +++ b/tests/01-empty.phpt @@ -0,0 +1,12 @@ +--TEST-- +Empty test +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(0) \ No newline at end of file From 75f101d2ae5adf6ffd9bc7498646a44f9625d2c3 Mon Sep 17 00:00:00 2001 From: DontCryAndPlay Keikira Date: Tue, 18 Jun 2019 23:47:38 +0200 Subject: [PATCH 6/6] Removed redundant include --- hash.c | 1 - 1 file changed, 1 deletion(-) diff --git a/hash.c b/hash.c index d642b1c..6296b98 100644 --- a/hash.c +++ b/hash.c @@ -8,7 +8,6 @@ #include #include -#include #include #include "hash.h"