This commit is contained in:
CismonX 2019-03-25 15:14:53 +08:00
parent a8bed9729a
commit c4bb5767ed
9 changed files with 73 additions and 15 deletions

View File

@ -8,11 +8,17 @@ php:
- 7.2
- 7.3
env:
global:
- ARMA_VERSION="9.300.2"
- ARMA_SRC="http://sourceforge.net/projects/arma/files/armadillo-${ARMA_VERSION}.tar.xz"
matrix:
- OPERATOR_OVERLOADING=yes
- OPERATOR_OVERLOADING=no
before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- export ARMA_VERSION="9.300.2"
- export ARMA_SRC="http://sourceforge.net/projects/arma/files/armadillo-${ARMA_VERSION}.tar.xz"
- wget $ARMA_SRC -O arma_src.tar.xz
- tar -Jxvf arma_src.tar.xz
@ -24,6 +30,6 @@ install:
script:
- phpize
- ./configure
- ./configure --enable-arma-operator=$OPERATOR_OVERLOADING
- make
- make test

View File

@ -1,6 +1,9 @@
PHP_ARG_ENABLE(arma, for armadillo support,
PHP_ARG_ENABLE(arma, for armadillo support,
[ --enable-arma Enable armadillo support])
PHP_ARG_ENABLE(arma-operator, for operator overloading support in armadillo,
[ --enable-arma-operator Enable operator overloading for armadillo ], no, no)
if test "$PHP_ARMA" != "no"; then
PHP_REQUIRE_CXX()
@ -9,7 +12,14 @@ if test "$PHP_ARMA" != "no"; then
src/interfaces.cc \
src/constants.cc \
src/complex.cc \
src/mapval.cc"
src/mapval.cc \
"
if test "$PHP_ARMA_OPERATOR" != "no"; then
AC_DEFINE(PHP_ARMA_OPERATOR, 1, [ Defined if operator overloading is enabled for armadillo. ])
ARMA_SRC+="src/operator.cc"
fi
PHP_NEW_EXTENSION(arma, $ARMA_SRC, $ext_shared, , -std=c++17)
PHP_ADD_LIBRARY(armadillo, 1, ARMA_SHARED_LIBADD)

View File

@ -80,4 +80,4 @@ namespace php_arma
}
}
#endif //!PHP_ARMA_COMPLEX_HH
#endif // !PHP_ARMA_COMPLEX_HH

View File

@ -36,4 +36,4 @@ namespace php_arma
inline zend_class_entry *scalar_ce;
}
#endif //!PHP_ARMA_INTERFACES_HH
#endif // !PHP_ARMA_INTERFACES_HH

View File

@ -16,7 +16,7 @@ namespace php_arma
zend_always_inline
T mapval<T, IsSparse, B>::get_val(zend_object *zobj)
{
if constexpr(IsSparse) {
if constexpr (IsSparse) {
return *to_native_object<native_t>(zobj);
} else {
return **to_native_object<native_t>(zobj);

View File

@ -34,7 +34,7 @@ namespace php_arma
zend_always_inline
static void set_val(zend_object *zobj, T val)
{
if constexpr(IsSparse) {
if constexpr (IsSparse) {
*to_native_object<native_t>(zobj) = val;
} else {
**to_native_object<native_t>(zobj) = val;
@ -44,7 +44,7 @@ namespace php_arma
zend_always_inline
static zend_object *create(native_t init_val)
{
if constexpr(IsSparse) {
if constexpr (IsSparse) {
return object_create<native_t>(ce, [&init_val](native_t *obj) {
memcpy(obj, &init_val, sizeof(native_t));
return &handlers;
@ -68,19 +68,19 @@ namespace php_arma
static void ce_init(const char*, zend_class_entry*);
PHP_ARMA_START_ME()
PHP_ARMA_ME(val, ZEND_ACC_PUBLIC)
PHP_ARMA_ME(val, ZEND_ACC_PUBLIC)
PHP_ARMA_ME(setTo, ZEND_ACC_PUBLIC)
PHP_ARMA_END_ME();
};
template <typename T>
using mapval_dense = mapval<T, false, false>;
using mapval_dense = mapval<T, false, false>;
template <typename T>
using mapval_spmat = mapval<T, true, false>;
using mapval_spmat = mapval<T, true, false>;
template <typename T>
using mapval_sp_subview = mapval<T, true, true>;
using mapval_sp_subview = mapval<T, true, true>;
void mapval_init();
@ -89,4 +89,4 @@ namespace php_arma
inline zend_class_entry *spsv_mapval_ce;
}
#endif //!PHP_ARMA_MAPVAL_HH
#endif // !PHP_ARMA_MAPVAL_HH

20
src/operator.cc Normal file
View File

@ -0,0 +1,20 @@
//
// php-armadillo/operator.cc
//
// @Author CismonX
//
#include "php_arma.hh"
namespace php_arma
{
int assign_handler(zend_execute_data *ex)
{
return ZEND_USER_OPCODE_DISPATCH;
}
void operator_init()
{
zend_set_user_opcode_handler(ZEND_ASSIGN, assign_handler);
}
}

15
src/operator.hh Normal file
View File

@ -0,0 +1,15 @@
//
// php-armadillo/operator.hh
//
// @Author CismonX
//
#ifndef PHP_ARMA_OPERATOR_HH
#define PHP_ARMA_OPERATOR_HH
namespace php_arma
{
void operator_init();
}
#endif // !PHP_ARMA_OPERATOR_HH

View File

@ -10,6 +10,10 @@
#include "complex.hh"
#include "mapval.hh"
#ifdef PHP_ARMA_OPERATOR
#include "operator.hh"
#endif // PHP_ARMA_OPERATOR
#include <ext/standard/info.h>
PHP_MINIT_FUNCTION(arma)
@ -19,6 +23,9 @@ PHP_MINIT_FUNCTION(arma)
php_arma::complex_init();
php_arma::mapval_init();
#ifdef PHP_ARMA_OPERATOR
php_arma::operator_init();
#endif // PHP_ARMA_OPERATOR
return SUCCESS;
}