mapbox/node-fontnik — pull request #60 by springmeyer (2014-09-05 07:44:52+00:00)
Title: Fix unsafe vendorization of fontnik && mapnik

This change needs to be done otherwise using node-fontnik and node-mapnik in the same process will create undefined behavior and lead to crashes. The only condition where the current code could possibly work is when there is complete ABI compatibility between the vendorized code and the code in node-mapnik and that is not something that is possible to control.

What triggered me to notice this was

- Bringing in a new node-mapnik and immediately hitting crashes
- Then seeing interleaved backtraces between node-mapnik an node-fontnik that show memory getting clobbered (because of course the two apps should have no relation and never show up in a backtrace together):

```
Thread 7 Crashed:
0 libsystem_platform.dylib	0x00007fff8fea1220 _platform_memcmp + 288
1 fontnik.node	0x000000010359768d std::__1::__tree_iterator, std::__1::allocator >, std::__1::shared_ptr >, std::__1::__tree_node, std::__1::allocator >, std::__1::shared_ptr >, void*>*, long> std::__1::__tree, std::__1::allocator >, std::__1::shared_ptr >, std::__1::__map_value_compare, std::__1::allocator >, std::__1::__value_type, std::__1::allocator >, std::__1::shared_ptr >, std::__1::less, std::__1::allocator > >, true>, std::__1::allocator, std::__1::allocator >, std::__1::shared_ptr > > >::__lower_bound, std::__1::allocator > >(std::__1::basic_string, std::__1::allocator > const&, std::__1::__tree_node, std::__1::allocator >, std::__1::shared_ptr >, void*>*, std::__1::__tree_node, std::__1::allocator >, std::__1::shared_ptr >, void*>*) + 147
2 fontnik.node	0x0000000103597575 std::__1::__tree_iterator, std::__1::allocator >, std::__1::shared_ptr >, std::__1::__tree_node, std::__1::allocator >, std::__1::shared_ptr >, void*>*, long> std::__1::__tree, std::__1::allocator >, std::__1::shared_ptr >, std::__1::__map_value_compare, std::__1::allocator >, std::__1::__value_type, std::__1::allocator >, std::__1::shared_ptr >, std::__1::less, std::__1::allocator > >, true>, std::__1::allocator, std::__1::allocator >, std::__1::shared_ptr > > >::find, std::__1::allocator > >(std::__1::basic_string, std::__1::allocator > const&) + 33
3 fontnik.node	0x000000010359663b mapnik::face_manager::get_face(std::__1::basic_string, std::__1::allocator > const&) + 39
4 libmapnik_4.dylib	0x0000000104298c0b mapnik::map_parser::parse_font(mapnik::font_set&, mapnik::xml_node const&) + 123
5 libmapnik_4.dylib	0x0000000104298229 mapnik::map_parser::parse_fontset(mapnik::Map&, mapnik::xml_node const&) + 345
6 libmapnik_4.dylib	0x0000000104294170 mapnik::map_parser::parse_map_include(mapnik::Map&, mapnik::xml_node const&) + 496
7 libmapnik_4.dylib	0x0000000104292de0 mapnik::map_parser::parse_map(mapnik::Map&, mapnik::xml_node const&, std::__1::basic_string, std::__1::allocator > const&) + 2816
8 libmapnik_4.dylib	0x0000000104293d03 mapnik::load_map_string(mapnik::Map&, std::__1::basic_string, std::__1::allocator > const&, bool, std::__1::basic_string, std::__1::allocator >) + 227
9 mapnik.node	0x0000000104022733 Map::EIO_FromString(uv_work_s*) + 67
10 node	0x0000000100445fd7 worker + 90
11 node	0x000000010043c79a uv__thread_start + 25
12 libsystem_pthread.dylib	0x00007fff93edc899 _pthread_body + 138
13 libsystem_pthread.dylib	0x00007fff93edc72a _pthread_start + 137
14 libsystem_pthread.dylib	0x00007fff93ee0fc9 thread_start + 13
```