Repository navigation
Fix datasource lifecycle locking, boolean detection and docs - #119
Merged
Merged
Conversation
Thread safety
- mapnik_datasource_destroy now takes the lifecycle mutex like
mapnik_datasource_create, so a datasource cannot be torn down while
another thread is loading a stylesheet. The class documentation claimed
lifecycle paths could not interleave; datasource destruction was the
exception.
- MapnikDatasource.init passes the pointer arrays directly instead of
reinterpreting their storage through UnsafeRawPointer +
assumingMemoryBound, which is undefined behaviour (and force-unwrapped
baseAddress).
- Documented that MapnikDatasource is only safe for one concurrent query
at a time, and that Mapnik.deinit may block on the lifecycle lock.
Feature queries
- Boolean detection compares against Foundation's shared boolean
instances instead of sniffing NSNumber.objCType[0] == 'c', which is an
implementation detail and also matches small integers on some versions.
Verified: {"flag": true, "small": 1} now decodes as Bool and Int.
Docs
- renderTile warns that a non-Web-Mercator map interprets the tile box in
its own SRS (an epsg:4326 map renders empty), instead of claiming it is
"valid".
- ImageFormat.svg documents that it is not usable with the raster entry
points.
- inspect's fieldFilter documents that it is a membership filter and does
not control output order.
- The counting-datasource header now matches the implementation: the
layer keeps a shared_ptr, so the handle may be destroyed early.
- MetatileOptions.validated() validates at construction for callers that
want the error early, without making the default argument throwing.
Tests
- Concurrent datasource create/inspect/query/destroy, and that a map
stays usable after its counting datasource handle is destroyed.
Fixes #41
Fixes #47
Fixes #61
Fixes #84
Fixes #87
Fixes #97
Fixes #102
Fixes #105
Fixes #110
Rebased onto main after #118 landed. Conflicts were resolved by combining both sides: main's newer code (dropped-feature counting, non-square metatile dimensions) plus this PR's hardening on top. Thread safety - mapnik_datasource_destroy takes the lifecycle mutex like mapnik_datasource_create, so a datasource cannot be torn down while another thread is loading a stylesheet. - MapnikDatasource.init passes the pointer arrays directly instead of reinterpreting their storage through UnsafeRawPointer + assumingMemoryBound (undefined behaviour, and it force-unwrapped baseAddress). - Documented that MapnikDatasource is safe for one concurrent query at a time, and that Mapnik.deinit may block on the lifecycle lock. Feature queries - Boolean detection compares against Foundation's shared boolean instances instead of sniffing NSNumber.objCType[0] == 'c', which is an implementation detail and also matches small integers on some versions. Verified: {"flag": true, "small": 1} decodes as Bool and Int. Docs - renderTile warns that a non-Web-Mercator map interprets the tile box in its own SRS (an epsg:4326 map renders empty) instead of claiming it is "valid". - ImageFormat.svg documents that it is not usable with the raster entry points. - inspect's fieldFilter documents that it is a membership filter and does not control output order. - The counting-datasource header matches the implementation: the layer keeps a shared_ptr, so the handle may be destroyed early. - MetatileOptions.validated() validates at construction for callers that want the error early, without making the default argument throwing. Tests - Concurrent datasource create/inspect/query/destroy, and that a map stays usable after its counting datasource handle is destroyed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Datasource destruction was the one lifecycle path not covered by the documented serialization, boolean detection relied on a Foundation implementation detail, and several doc comments contradicted the code.
Thread safety
Datasource destruction was unsynchronized
mapnik_datasource_createtakesmapnik_lifecycle_mutex, butmapnik_datasource_destroydid not — so a datasource could be torn down while another thread was loading a stylesheet, which the class documentation says cannot happen. Destruction now takes the same mutex.Undefined behaviour in
MapnikDatasource.initThe buffer's element type was already
UnsafePointer<CChar>?, so this round-tripped throughUnsafeRawPointerfor no reason and force-unwrappedbaseAddress. It now passes the buffer pointers directly.Documented contracts
MapnikDatasourceis documented as safe for one concurrent query at a time.Mapnik.deinitis documented as possibly blocking on the lifecycle lock.shared_ptr, so the handle may be destroyed early (it previously said the opposite).Boolean detection
objCTypeis a Foundation implementation detail, and"c"also matches small integers on some versions. The check now compares against Foundation's shared boolean instances:Documentation
epsg:4326map reads the tile box as ±20037508 degrees and renders emptyImageFormat.svgis just another formatfieldFiltercontrols the reported field orderMetatileOptions.validated()was added so callers can get validation errors at construction without making the default argument throwing.Testing
Closes #41
Closes #47
Closes #61
Closes #84
Closes #87
Closes #97
Closes #102
Closes #105
Closes #110