[geos-commits] r3007 - in trunk: . php php/test
svn_geos at osgeo.org
svn_geos at osgeo.org
Fri Jun 18 10:20:42 EDT 2010
Author: strk
Date: 2010-06-18 14:20:42 +0000 (Fri, 18 Jun 2010)
New Revision: 3007
Added:
trunk/php/
trunk/php/Makefile.am
trunk/php/README
trunk/php/TODO
trunk/php/geos.c
trunk/php/php_geos.h
trunk/php/test/
trunk/php/test/Makefile.am
trunk/php/test/crashme.php
trunk/php/test/test.php
Modified:
trunk/Makefile.am
trunk/configure.in
Log:
Initial go at PHP5 bindings. Can only read and write WKT so far.
Modified: trunk/Makefile.am
===================================================================
--- trunk/Makefile.am 2010-06-18 10:29:31 UTC (rev 3006)
+++ trunk/Makefile.am 2010-06-18 14:20:42 UTC (rev 3007)
@@ -16,6 +16,7 @@
doc \
macros \
swig \
+ php \
tests \
tools
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2010-06-18 10:29:31 UTC (rev 3006)
+++ trunk/configure.in 2010-06-18 14:20:42 UTC (rev 3007)
@@ -230,13 +230,27 @@
[use_ruby=false]
)
+dnl --------------------------------------------------------------------
+dnl - check whether php is required for the build
+dnl --------------------------------------------------------------------
+AC_ARG_ENABLE([php], [ --enable-php Enable build of php module],
+ [case "${enableval}" in
+ yes) use_php=true ;;
+ no) use_php=false ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-php) ;;
+ esac],
+ [use_php=false]
+)
+
+
dnl --------------------------------------------------------------------
-dnl - check for swig if python or ruby are enabled
+dnl - check for swig if python, ruby or php are enabled
dnl --------------------------------------------------------------------
use_swig=false
-if test x"$use_python" = xtrue || test x"$use_ruby" = xtrue; then
+if test x"$use_python" = xtrue ||
+ test x"$use_ruby" = xtrue; then
AC_PROG_SWIG(1.3.28)
if test x"$SWIG" != "x"; then
SWIG_ENABLE_CXX
@@ -283,7 +297,25 @@
fi
AM_CONDITIONAL(ENABLE_RUBY, [ test x"$use_ruby" = xtrue ])
+dnl --------------------------------------------------------------------
+dnl - check for php if enabled
+dnl --------------------------------------------------------------------
+if test x"$use_php" = xtrue; then
+ dnl Check for PHP
+ AC_PATH_PROG(PHP_CONFIG, php-config)
+ dnl TODO: AC_SUBST ?
+
+ if test x"$PHP_CONFIG" = x; then
+ use_php=false
+ fi
+
+ dnl TODO: check for version, we want PHP5 dev files
+
+fi
+AM_CONDITIONAL(ENABLE_PHP, [ test x"$use_php" = xtrue ])
+
+
dnl --------------------------------------------------------------------
dnl - do operating-system specific things
dnl --------------------------------------------------------------------
@@ -452,6 +484,8 @@
swig/python/tests/Makefile
swig/ruby/Makefile
swig/ruby/test/Makefile
+ php/Makefile
+ php/test/Makefile
tests/Makefile
tests/bigtest/Makefile
tests/unit/Makefile
@@ -470,4 +504,5 @@
echo "Swig: $use_swig"
echo "Python: $use_python"
echo "Ruby: $use_ruby"
+echo "PHP: $use_php"
dnl -- echo "---------------------------------------"
Added: trunk/php/Makefile.am
===================================================================
--- trunk/php/Makefile.am (rev 0)
+++ trunk/php/Makefile.am 2010-06-18 14:20:42 UTC (rev 3007)
@@ -0,0 +1,46 @@
+#######################################################################
+#
+# GEOS - Geometry Engine Open Source
+# http://trac.osgeo.org/geos
+#
+# Copyright (C) 2010 Sandro Santilli <strk at keybit.net>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA
+#
+#######################################################################
+
+
+if ENABLE_PHP
+
+SUBDIRS = test
+
+EXTRA_DIST = README
+
+pkglib_LTLIBRARIES = geos.la
+geos_la_SOURCES = geos.c php_geos.h
+geos_la_LIBADD = $(top_builddir)/capi/libgeos_c.la
+# TODO: check if -no-undefined should be added
+geos_la_LDFLAGS = -module -avoid-version
+# TODO: drop conditionals from geos.c and let it bound to current code
+geos_la_CFLAGS = $(AM_CFLAGS) `$(PHP_CONFIG) --includes` \
+ -DCOMPILE_DL_GEOS \
+ -std=c99
+
+install: all
+ $(INSTALL) -d "$(DESTDIR)"/`$(PHP_CONFIG) --extension-dir`
+ $(INSTALL) -m 755 .libs/geos.so "$(DESTDIR)"/`php-config --extension-dir`
+
+endif
Added: trunk/php/README
===================================================================
--- trunk/php/README (rev 0)
+++ trunk/php/README 2010-06-18 14:20:42 UTC (rev 3007)
@@ -0,0 +1,43 @@
+PHP module for GEOS
+===================
+
+ Date: Fri Jun 18 15:52:57 CEST 2010
+ Author: Sandro Santilli <strk at keybit.net>
+
+The code in this directory provides a PHP module to
+make use of functionalities of the GEOS library.
+The bindings are linked to the C-API, for betters stability.
+
+REQUIREMENTS
+------------
+
+You need php5 development tools, often found in
+packages named something like 'php5-dev'.
+
+BUILD
+-----
+
+Just add --enable-php to your GEOS configure line
+and run 'make'.
+
+TESTING
+-------
+
+Automated testing should be executed on 'make check'
+togheter with the rest of the GEOS testsuite.
+You can still run 'make check' from this dir for
+localized (php-only) testing.
+
+INSTALL
+-------
+
+As root (or owner with write access to the directory
+returned by php-config --extension-dir),
+run 'make install'
+
+USAGE
+-----
+
+ ... TODO ...
+ (reference some automatically built doc?)
+
Added: trunk/php/TODO
===================================================================
--- trunk/php/TODO (rev 0)
+++ trunk/php/TODO 2010-06-18 14:20:42 UTC (rev 3007)
@@ -0,0 +1,7 @@
+In order of priority
+
+- Complete all interfaces for WKTReader/WKTWriter/Geometry
+- Doxygen based documentation
+- Proper automated testing
+
+- Add interfaces for WKBReader/WKBWriter ?
Added: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c (rev 0)
+++ trunk/php/geos.c 2010-06-18 14:20:42 UTC (rev 3007)
@@ -0,0 +1,416 @@
+/***********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://trac.osgeo.org/geos
+ *
+ * Copyright (C) 2010 Sandro Santilli <strk at keybit.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ ***********************************************************************/
+
+/* PHP stuff */
+#include "php.h"
+#include "ext/standard/info.h" /* for php_info_... */
+#include "Zend/zend_exceptions.h" /* for zend_throw_exception_object */
+
+/* GEOS stuff */
+#include <geos_c.h>
+
+/* Own stuff */
+#include "php_geos.h"
+
+PHP_MINIT_FUNCTION(geos);
+PHP_RINIT_FUNCTION(geos);
+PHP_RSHUTDOWN_FUNCTION(geos);
+PHP_MINFO_FUNCTION(geos);
+PHP_FUNCTION(GEOSVersion);
+/*PHP_METHOD(WKTReader, write);*/
+
+static function_entry geos_functions[] = {
+ PHP_FE(GEOSVersion, NULL)
+ {NULL, NULL, NULL}
+};
+
+zend_module_entry geos_module_entry = {
+ STANDARD_MODULE_HEADER,
+ PHP_GEOS_EXTNAME,
+ geos_functions,
+ PHP_MINIT(geos), /* module init function */
+ NULL, /* module shutdown function */
+ PHP_RINIT(geos), /* request init function */
+ PHP_RSHUTDOWN(geos), /* request shutdown function */
+ PHP_MINFO(geos), /* module info function */
+ PHP_GEOS_VERSION,
+ STANDARD_MODULE_PROPERTIES
+};
+
+#ifdef COMPILE_DL_GEOS
+ZEND_GET_MODULE(geos)
+#endif
+
+/* -- Utility functions ---------------------- */
+
+static void noticeHandler(const char *fmt, ...)
+{
+ char message[256];
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(message, sizeof(message) - 1, fmt, args);
+ va_end(args);
+
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", message);
+}
+
+static void errorHandler(const char *fmt, ...)
+{
+ char message[256];
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(message, sizeof(message) - 1, fmt, args);
+ va_end(args);
+
+ /* TODO: use a GEOSException ? */
+ zend_throw_exception_ex(zend_exception_get_default(TSRMLS_CC),
+ 1 TSRMLS_CC, "%s", message);
+
+}
+
+typedef struct Proxy_t {
+ zend_object std;
+ void* relay;
+} Proxy;
+
+static void
+setRelay(zval* val, void* obj) {
+ Proxy* proxy = (Proxy*)zend_object_store_get_object(val TSRMLS_CC);
+ proxy->relay = obj;
+}
+
+static inline void *
+getRelay(zval* val, zend_class_entry* ce) {
+ Proxy *proxy = (Proxy*)zend_object_store_get_object(val TSRMLS_CC);
+ if ( proxy->std.ce != ce ) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
+ "Relay object is not an %s", ce->name);
+ }
+ if ( ! proxy->relay ) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
+ "Relay object for object of type %s is not set", ce->name);
+ }
+ return proxy->relay;
+}
+
+static zend_object_value
+Gen_create_obj (zend_class_entry *type TSRMLS_DC,
+ zend_objects_free_object_storage_t st, zend_object_handlers* handlers)
+{
+ zval *tmp;
+ zend_object_value retval;
+
+ Proxy *obj = (Proxy *)emalloc(sizeof(Proxy));
+ memset(obj, 0, sizeof(Proxy));
+ obj->std.ce = type;
+
+ ALLOC_HASHTABLE(obj->std.properties);
+ zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_copy(obj->std.properties, &type->default_properties,
+ (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));
+
+ retval.handle = zend_objects_store_put(obj, NULL, st, NULL TSRMLS_CC);
+ retval.handlers = handlers;
+
+ return retval;
+}
+
+
+/* -- Free functions ------------------------- */
+
+PHP_FUNCTION(GEOSVersion)
+{
+ char *str;
+
+ str = estrdup(GEOSversion());
+ RETURN_STRING(str, 0);
+}
+
+/* -- class GEOSGeometry -------------------- */
+
+PHP_METHOD(Geometry, __construct);
+PHP_METHOD(Geometry, numGeometries);
+
+static function_entry Geometry_methods[] = {
+ PHP_ME(Geometry, __construct, NULL, 0)
+ PHP_ME(Geometry, numGeometries, NULL, 0)
+ {NULL, NULL, NULL}
+};
+
+static zend_class_entry *Geometry_ce_ptr;
+
+static zend_object_handlers Geometry_object_handlers;
+
+static void
+Geometry_dtor (void *object TSRMLS_DC)
+{
+ Proxy *obj = (Proxy *)object;
+ GEOSGeom_destroy((GEOSGeometry*)obj->relay);
+
+ zend_hash_destroy(obj->std.properties);
+ FREE_HASHTABLE(obj->std.properties);
+
+ efree(obj);
+}
+
+static zend_object_value
+Geometry_create_obj (zend_class_entry *type TSRMLS_DC)
+{
+ return Gen_create_obj(type, Geometry_dtor, &Geometry_object_handlers);
+}
+
+
+PHP_METHOD(Geometry, __construct)
+{
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
+ "GEOSGeometry can't be constructed using new, check WKTReader");
+
+}
+
+PHP_METHOD(Geometry, numGeometries)
+{
+ GEOSGeometry *geom;
+ long int ret;
+
+ geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+ ret = GEOSGetNumGeometries(geom);
+ if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
+
+ RETURN_LONG(ret);
+}
+
+/* -- class GEOSWKTReader -------------------- */
+
+PHP_METHOD(WKTReader, __construct);
+PHP_METHOD(WKTReader, read);
+
+static function_entry WKTReader_methods[] = {
+ PHP_ME(WKTReader, __construct, NULL, 0)
+ PHP_ME(WKTReader, read, NULL, 0)
+ {NULL, NULL, NULL}
+};
+
+static zend_class_entry *WKTReader_ce_ptr;
+
+static zend_object_handlers WKTReader_object_handlers;
+
+static void
+WKTReader_dtor (void *object TSRMLS_DC)
+{
+ Proxy *obj = (Proxy *)object;
+ GEOSWKTReader_destroy((GEOSWKTReader*)obj->relay);
+
+ zend_hash_destroy(obj->std.properties);
+ FREE_HASHTABLE(obj->std.properties);
+
+ efree(obj);
+}
+
+static zend_object_value
+WKTReader_create_obj (zend_class_entry *type TSRMLS_DC)
+{
+ return Gen_create_obj(type, WKTReader_dtor, &WKTReader_object_handlers);
+}
+
+
+PHP_METHOD(WKTReader, __construct)
+{
+ GEOSWKTReader* obj;
+ zval *object = getThis();
+
+ obj = GEOSWKTReader_create();
+ if ( ! obj ) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
+ "GEOSWKTReader_create() failed (didn't initGEOS?)");
+ }
+
+ setRelay(object, obj);
+}
+
+PHP_METHOD(WKTReader, read)
+{
+ GEOSWKTReader *reader;
+ GEOSGeometry *geom;
+ char* wkt;
+ int wktlen;
+
+ reader = (GEOSWKTReader*)getRelay(getThis(), WKTReader_ce_ptr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ &wkt, &wktlen) == FAILURE)
+ {
+ RETURN_NULL();
+ }
+
+ geom = GEOSWKTReader_read(reader, wkt);
+ /* we'll probably get an exception if geom is null */
+ if ( ! geom ) RETURN_NULL();
+
+ /* return_value is a zval */
+ object_init_ex(return_value, Geometry_ce_ptr);
+ setRelay(return_value, geom);
+
+}
+
+/* -- class GEOSWKTWriter -------------------- */
+
+PHP_METHOD(WKTWriter, __construct);
+PHP_METHOD(WKTWriter, write);
+
+static function_entry WKTWriter_methods[] = {
+ PHP_ME(WKTWriter, __construct, NULL, 0)
+ PHP_ME(WKTWriter, write, NULL, 0)
+ {NULL, NULL, NULL}
+};
+
+static zend_class_entry *WKTWriter_ce_ptr;
+
+static zend_object_handlers WKTWriter_object_handlers;
+
+static void
+WKTWriter_dtor (void *object TSRMLS_DC)
+{
+ Proxy *obj = (Proxy *)object;
+ GEOSWKTWriter_destroy((GEOSWKTWriter*)obj->relay);
+
+ zend_hash_destroy(obj->std.properties);
+ FREE_HASHTABLE(obj->std.properties);
+
+ efree(obj);
+}
+
+static zend_object_value
+WKTWriter_create_obj (zend_class_entry *type TSRMLS_DC)
+{
+ return Gen_create_obj(type, WKTWriter_dtor, &WKTWriter_object_handlers);
+}
+
+
+PHP_METHOD(WKTWriter, __construct)
+{
+ GEOSWKTWriter* obj;
+ zval *object = getThis();
+
+ obj = GEOSWKTWriter_create();
+ if ( ! obj ) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
+ "GEOSWKTWriter_create() failed (didn't initGEOS?)");
+ }
+
+ setRelay(object, obj);
+}
+
+PHP_METHOD(WKTWriter, write)
+{
+ GEOSWKTWriter *writer;
+ zval *zobj;
+ GEOSGeometry *geom;
+ char* wkt;
+ char* retstr;
+
+ writer = (GEOSWKTWriter*)getRelay(getThis(), WKTWriter_ce_ptr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
+ == FAILURE)
+ {
+ RETURN_NULL();
+ }
+
+ geom = getRelay(zobj, Geometry_ce_ptr);
+
+ wkt = GEOSWKTWriter_write(writer, geom);
+ /* we'll probably get an exception if wkt is null */
+ if ( ! wkt ) RETURN_NULL();
+
+ retstr = estrdup(wkt);
+ GEOSFree(wkt);
+
+ RETURN_STRING(retstr, 0);
+
+ /* return_value is a zval */
+ object_init_ex(return_value, Geometry_ce_ptr);
+ setRelay(return_value, geom);
+
+}
+
+/* ------ Initialization / Deinitialization / Meta ------------------ */
+
+/* per-module initialization */
+PHP_MINIT_FUNCTION(geos)
+{
+ zend_class_entry ce;
+
+ /* WKTReader */
+ INIT_CLASS_ENTRY(ce, "GEOSWKTReader", WKTReader_methods);
+ WKTReader_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
+ WKTReader_ce_ptr->create_object = WKTReader_create_obj;
+ memcpy(&WKTReader_object_handlers,
+ zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ WKTReader_object_handlers.clone_obj = NULL;
+
+ /* WKTWriter */
+ INIT_CLASS_ENTRY(ce, "GEOSWKTWriter", WKTWriter_methods);
+ WKTWriter_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
+ WKTWriter_ce_ptr->create_object = WKTWriter_create_obj;
+ memcpy(&WKTWriter_object_handlers,
+ zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ WKTWriter_object_handlers.clone_obj = NULL;
+
+ /* Geometry */
+ INIT_CLASS_ENTRY(ce, "GEOSGeometry", Geometry_methods);
+ Geometry_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
+ Geometry_ce_ptr->create_object = Geometry_create_obj;
+ memcpy(&Geometry_object_handlers,
+ zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ Geometry_object_handlers.clone_obj = NULL;
+
+ return SUCCESS;
+}
+
+/* per-request initialization */
+PHP_RINIT_FUNCTION(geos)
+{
+ initGEOS(noticeHandler, errorHandler);
+ return SUCCESS;
+}
+
+/* pre-request destruction */
+PHP_RSHUTDOWN_FUNCTION(geos)
+{
+ finishGEOS();
+ return SUCCESS;
+}
+
+/* module info */
+PHP_MINFO_FUNCTION(geos)
+{
+ php_info_print_table_start();
+ php_info_print_table_row(2,
+ "GEOS - Geometry Engine Open Source", "enabled");
+ php_info_print_table_row(2,
+ "Version", PHP_GEOS_VERSION);
+ php_info_print_table_end();
+}
+
Added: trunk/php/php_geos.h
===================================================================
--- trunk/php/php_geos.h (rev 0)
+++ trunk/php/php_geos.h 2010-06-18 14:20:42 UTC (rev 3007)
@@ -0,0 +1,41 @@
+/***********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://trac.osgeo.org/geos
+ *
+ * Copyright (C) 2010 Sandro Santilli <strk at keybit.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ ***********************************************************************/
+
+#ifndef PHP_GEOS_H
+#define PHP_GEOS_H
+
+/* TODO: generate from ./configure ? */
+#define PHP_GEOS_VERSION "0.0"
+#define PHP_GEOS_EXTNAME "geos"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+
+extern zend_module_entry geos_module_entry;
+#define phpext_geos_ptr &geos_module_entry;
+
+#endif /* PHP_GEOS_H */
Added: trunk/php/test/Makefile.am
===================================================================
--- trunk/php/test/Makefile.am (rev 0)
+++ trunk/php/test/Makefile.am 2010-06-18 14:20:42 UTC (rev 3007)
@@ -0,0 +1,35 @@
+#######################################################################
+#
+# GEOS - Geometry Engine Open Source
+# http://trac.osgeo.org/geos
+#
+# Copyright (C) 2010 Sandro Santilli <strk at keybit.net>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA
+#
+#######################################################################
+
+EXTRA_DIST = test.php crashme.php
+
+if ENABLE_PHP
+
+check:
+ php -n -d enable_dl=On -d extension_dir=../.libs test.php
+
+crashtest:
+ php -n -d enable_dl=On -d extension_dir=../.libs crashme.php
+
+endif
Added: trunk/php/test/crashme.php
===================================================================
--- trunk/php/test/crashme.php (rev 0)
+++ trunk/php/test/crashme.php 2010-06-18 14:20:42 UTC (rev 3007)
@@ -0,0 +1,25 @@
+<?php
+
+#
+# This file contains code attempting to segfault the extension
+#
+# Run with:
+# php -n -d enable_dl=On -d extension_dir=.. test.php
+#
+
+dl("geos.so");
+
+class Point extends GEOSWKTReader {
+ public function __construct()
+ {
+ parent::__construct();
+ }
+ public function test() {
+ return GEOSGeometry::numGeometries();
+ }
+};
+
+$p = new Point();
+$p->test();
+
+
Added: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php (rev 0)
+++ trunk/php/test/test.php 2010-06-18 14:20:42 UTC (rev 3007)
@@ -0,0 +1,35 @@
+<?php
+
+# Run with:
+# php -n -d enable_dl=On -d extension_dir=.. test.php
+
+dl("geos.so");
+
+echo "\n";
+echo "Geos version is: " . GEOSVersion() . "\n";
+echo "\n";
+
+$reader = new GEOSWKTReader();
+$writer = new GEOSWKTWriter();
+
+
+/* BOGUS WKT */
+try {
+ $geom = $reader->read("ciao");
+} catch (Exception $e) {
+ echo 'EXPECTED [WKTReader::read("ciao")]: ' . $e->getMessage() . "\n";
+}
+
+$geom = $reader->read("POINT(0 0)");
+$num = $geom->numGeometries();
+echo 'Geom has ' . $num . " geometries, WKT follows:\n";
+echo $writer->write($geom) . "\n";
+
+$geom = $reader->read("MULTIPOINT(0 0, 1 1)");
+$num = $geom->numGeometries();
+echo 'Geom has ' . $num . " geometries. WKT follows:\n";
+echo $writer->write($geom) . "\n";
+
+echo "\n";
+echo "\n";
+
More information about the geos-commits
mailing list