Skip to content

Commit da04eaf

Browse files
committed
Add development image Dockerfile. Fix memory leak in Map::load* methods.
1 parent 3cc3618 commit da04eaf

File tree

7 files changed

+51
-11
lines changed

7 files changed

+51
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ build
2121
config.guess
2222
config.h
2323
config.h.in
24+
config.h.in~
2425
config.log
2526
config.nice
2627
config.status

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:xenial
2+
3+
ENV DEBIAN_FRONTEND noninteractive
4+
5+
RUN apt-get update && apt-get -y install \
6+
build-essential \
7+
libmapnik-dev \
8+
mapnik-utils \
9+
php-dev \
10+
php-gd \
11+
python-software-properties \
12+
valgrind
13+
14+
RUN mkdir /opt/php7-mapnik
15+
WORKDIR /opt/php7-mapnik

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,11 @@ $image->saveToFile('my_awesome_map.png');
8585

8686
See the [API Documentation](http://garrettrayj.github.io/php7-mapnik/api/) for a complete list of
8787
available objects and methods.
88+
89+
Dev Container
90+
-------------
91+
92+
The included Dockerfile builds an image with all the dependencies need for extension development and testing, including testing for memory leaks.
93+
94+
docker build -t php7-mapnik-dev .
95+
docker run -it --mount type=bind,source=$(pwd),target=/opt/php7-mapnik php7-mapnik-dev:latest

mem_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22

3-
# Hijack PHP_TEST_SHARED_EXTENSIONS variable to inject run-tests.php valgrind options.
3+
# Override PHP_TEST_SHARED_EXTENSIONS variable to inject run-tests.php valgrind options.
44
make PHP_TEST_SHARED_EXTENSIONS='-m --show-diff ` if test "x$(PHP_MODULES)" != "x"; then for i in $(PHP_MODULES)""; do . $$i; $(top_srcdir)/build/shtool echo -n -- " -d extension=$$dlname"; done; fi; if test "x$(PHP_ZEND_EX)" != "x"; then for i in $(PHP_ZEND_EX)""; do . $$i; $(top_srcdir)/build/shtool echo -n -- " -d $(ZEND_EXT_TYPE)=$(top_builddir)/modules/$$dlname"; done; fi`' test

src/map.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ PHP_METHOD(Map, loadXmlString)
4949
{
5050
map_object *obj = Z_PHP_MAPNIK_MAP_P(getThis());
5151

52-
zend_string *xml, *base_path;
52+
zend_string *xml;
53+
zend_string *base_path;
5354
zend_bool strict = false;
5455

5556
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 3)
@@ -59,10 +60,15 @@ PHP_METHOD(Map, loadXmlString)
5960
Z_PARAM_STR(base_path)
6061
ZEND_PARSE_PARAMETERS_END();
6162

63+
std::string xml_str(ZSTR_VAL(xml), ZSTR_LEN(xml));
64+
6265
try {
63-
std::string xml_str(ZSTR_VAL(xml), ZSTR_LEN(xml));
64-
std::string base_path_str(ZSTR_VAL(base_path), ZSTR_LEN(base_path));
65-
mapnik::load_map_string(*obj->map, xml_str, strict, base_path_str);
66+
if (ZEND_NUM_ARGS() > 2) {
67+
std::string base_path_str(ZSTR_VAL(base_path), ZSTR_LEN(base_path));
68+
mapnik::load_map_string(*obj->map, xml_str, strict, base_path_str);
69+
} else {
70+
mapnik::load_map_string(*obj->map, xml_str, strict);
71+
}
6672
} catch (const mapnik::proj_init_error & ex) {
6773
throw_mapnik_exception(ex.what());
6874
} catch (const std::runtime_error & ex) {
@@ -78,7 +84,8 @@ PHP_METHOD(Map, loadXmlFile)
7884
{
7985
map_object *obj = Z_PHP_MAPNIK_MAP_P(getThis());
8086

81-
zend_string *filename, *base_path;
87+
zend_string *filename;
88+
zend_string *base_path;
8289
zend_bool strict = false;
8390

8491
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 3)
@@ -88,10 +95,15 @@ PHP_METHOD(Map, loadXmlFile)
8895
Z_PARAM_STR(base_path)
8996
ZEND_PARSE_PARAMETERS_END();
9097

98+
std::string filename_str(ZSTR_VAL(filename), ZSTR_LEN(filename));
99+
91100
try {
92-
std::string filename_str(ZSTR_VAL(filename), ZSTR_LEN(filename));
93-
std::string base_path_str(ZSTR_VAL(base_path), ZSTR_LEN(base_path));
94-
mapnik::load_map(*obj->map, filename_str, strict, base_path_str);
101+
if (ZEND_NUM_ARGS() > 2) {
102+
std::string base_path_str(ZSTR_VAL(base_path), ZSTR_LEN(base_path));
103+
mapnik::load_map(*obj->map, filename_str, false, base_path_str);
104+
} else {
105+
mapnik::load_map(*obj->map, filename_str, strict);
106+
}
95107
} catch (const mapnik::proj_init_error & ex) {
96108
throw_mapnik_exception(ex.what());
97109
} catch (const std::runtime_error & ex) {

tests/data/world.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
<Parameter name="file">ne_110m_admin_0_countries.shp</Parameter>
1414
</Datasource>
1515
</Layer>
16-
</Map>
16+
</Map>

tests/image.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
--EXTENSIONS--
44
gd
55
--SKIPIF--
6-
<?php if (!extension_loaded("mapnik")) print "skip"; ?>
6+
<?php
7+
if (!extension_loaded("mapnik")) print "skip";
8+
// Unsuccessful in attempts to get GD extension to load in dev image... just skip if unavailable.
9+
if (!extension_loaded("gd")) print "skip";
10+
?>
711
--FILE--
812
<?php
913

0 commit comments

Comments
 (0)