summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-25 10:35:12 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-25 10:35:12 +0100
commitaf85f97c832ba318373db3ad6df72ebedbad1a1d (patch)
treee5beabe1756207893b869c5213a02f98a50d25d6
parent811c83de9e6410435b6b9c10b058b04b2fcae5c3 (diff)
ZTS thread safety is now automatically detected when PHP-CPP is installed
-rw-r--r--.gitignore1
-rw-r--r--Makefile45
-rw-r--r--config/config.cpp28
-rw-r--r--include/value.h3
-rw-r--r--phpcpp.h28
5 files changed, 82 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index 9c94db3..09f31d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
*.o
*.so
*.txt
+create_config
diff --git a/Makefile b/Makefile
index 304ca56..7941dc8 100644
--- a/Makefile
+++ b/Makefile
@@ -47,14 +47,14 @@ INSTALL_LIB = ${INSTALL_PREFIX}/lib
#
-# Name of the target library name
+# Name of the target library name and config-generator
#
# The PHP-CPP library will be installed on your system as libphpcpp.so.
# This is a brilliant name. If you want to use a different name for it,
-# you can change that here
+# you can change that here.
#
-RESULT = libphpcpp.so
+LIBRARY = libphpcpp.so
#
@@ -85,7 +85,6 @@ LINKER = g++
COMPILER_FLAGS = -Wall -c `php-config --includes` -g -std=c++11 -fpic -o
-
#
# Linker flags
#
@@ -118,7 +117,7 @@ MKDIR = mkdir -p
# src/ directory for all *.cpp files. No changes are probably necessary here
#
-SOURCES = $(wildcard src/*.cpp)
+LIBRARY_SOURCES = $(wildcard src/*.cpp)
#
@@ -129,7 +128,19 @@ SOURCES = $(wildcard src/*.cpp)
# We also use a Makefile function here that takes all source files.
#
-OBJECTS = $(SOURCES:%.cpp=%.o)
+LIBRARY_OBJECTS = $(LIBRARY_SOURCES:%.cpp=%.o)
+
+
+#
+# Configuration program
+#
+# During installation, a configuration utility will be installed. It is
+# compiled with the following instructions
+#
+
+CONFIG_UTILITY = ./create_config
+CONFIG_SOURCES = $(wildcard config/*.cpp)
+CONFIG_FLAGS = `php-config --includes` -o
#
@@ -137,27 +148,27 @@ OBJECTS = $(SOURCES:%.cpp=%.o)
# dependencies that are used by the compiler.
#
-all: ${OBJECTS} ${RESULT}
-# Before offering to run the tests, we need to write more tests
-# @echo
-# @echo "Build complete."
-# @echo "Don't forget to run 'make test'."
-# @echo
+all: ${LIBRARY_OBJECTS} ${LIBRARY} ${CONFIG_UTILITY}
-${RESULT}: ${OBJECTS}
- ${LINKER} ${LINKER_FLAGS} -o $@ ${OBJECTS}
+${LIBRARY}: ${LIBRARY_OBJECTS}
+ ${LINKER} ${LINKER_FLAGS} -o $@ ${LIBRARY_OBJECTS}
+
+${CONFIG_UTILITY}:
+ ${COMPILER} ${CONFIG_FLAGS} $@ ${CONFIG_SOURCES}
clean:
- ${RM} ${OBJECTS} ${RESULT}
+ ${RM} ${LIBRARY_OBJECTS} ${LIBRARY} ${CONFIG_UTILITY}
-${OBJECTS}:
+${LIBRARY_OBJECTS}:
${COMPILER} ${COMPILER_FLAGS} $@ ${@:%.o=%.cpp}
install:
${MKDIR} ${INSTALL_HEADERS}/phpcpp
${CP} phpcpp.h ${INSTALL_HEADERS}
${CP} include/*.h ${INSTALL_HEADERS}/phpcpp
- ${CP} ${RESULT} ${INSTALL_LIB}
+ ${CP} ${LIBRARY} ${INSTALL_LIB}
+ ${CONFIG_UTILITY} > ${INSTALL_HEADERS}/phpcpp/config.h
+
test:
cd tests && ./test.sh -p ${PHP_BIN}
diff --git a/config/config.cpp b/config/config.cpp
new file mode 100644
index 0000000..2fcd5ad
--- /dev/null
+++ b/config/config.cpp
@@ -0,0 +1,28 @@
+/**
+ * Config.cpp
+ *
+ * Simple programs that creates the config file for PHP-CPP. PHP-CPP needs
+ * a different config file when it is installed on a system with multi-threaded
+ * PHP, and on a system with single threaded PHP.
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2014 Copernica BV
+ */
+#include <iostream>
+#include <php_config.h>
+
+/**
+ * Main procedure
+ * @return int
+ */
+int main()
+{
+#ifdef ZTS
+ // also define ZTS in the config file
+ std::cout << "#define ZTS" << std::endl;
+#endif
+
+ // done
+ return 0;
+}
+
diff --git a/include/value.h b/include/value.h
index 1878390..47cebcf 100644
--- a/include/value.h
+++ b/include/value.h
@@ -109,8 +109,9 @@ public:
* Wrap object around zval
* @param zval Zval to wrap
* @param ref Force this to be a reference
+ * @param tsrm_ls Optional pointer to thread safe data
*/
- Value(struct _zval_struct *zval, bool ref = false);
+ Value(struct _zval_struct *zval, bool ref=false);
/**
* Wrap around an object implemented by us
diff --git a/phpcpp.h b/phpcpp.h
index 17778f4..86828a4 100644
--- a/phpcpp.h
+++ b/phpcpp.h
@@ -23,12 +23,30 @@
#include <map>
/**
- * Disable TSRM for now
+ * Include PHP config
*/
-#define TSRMLS_C
-#define TSRMLS_CC
-#define TSRMLS_D
-#define TSRMLS_DC
+#include <phpcpp/config.h>
+
+/**
+ * Is ZTS enabled?
+ */
+#ifdef ZTS
+
+ // enable TSRM
+# define TSRMLS_C tsrm_ls
+# define TSRMLS_CC ,tsrm_ls
+# define TSRMLS_D void ***tsrm_ls
+# define TSRMLS_DC ,void ***tsrm_ls
+
+#else
+
+ // disable TSRM
+# define TSRMLS_C
+# define TSRMLS_CC
+# define TSRMLS_D
+# define TSRMLS_DC
+
+#endif
/**
* Include all headers files that are related to this library