Repository navigation
Fix mapnik initialization and plugin discovery - #113
Merged
Merged
Conversation
Initialization
- mapnik_init now fails when a plugin or font path does not exist, is not
a directory, or registers nothing (no *.input files / no usable fonts).
Previously register_fonts("/nonexistent") returned 0 without throwing,
so initialize() reported success for paths that registered nothing.
- A failed initialize() is no longer cached. Caching the failure let one
bad explicit path poison the process: every later Mapnik(xml:) failed
and the lazy default initialization could never retry.
- Calling initialize() with different paths after a successful
initialization now throws instead of silently returning, so an
accidental "too late" call is visible rather than ignored.
- defaultPluginPath/defaultFontPath are computed properties.
Plugin discovery
- versionComponents now splits the version component on ".", so "4.2"
parses as [4, 2]. It previously used Int("4.2"), which is nil, so every
candidate produced [] and the "highest version wins" logic silently
degraded to a lexicographic comparison: 4.10 sorted below 4.2 and 10.0
below 3.1.
- compareVersionedPaths handles unversioned paths explicitly and is
internal so it can be tested.
- highestVersionedDirectory is internal for the same reason.
- The cached Linux plugin path moved from a lazy `static let` (which ran
pkg-config during global initialization and could never be reset) into
the lock-protected State, with an injectable provider for tests.
pkg-config probing
- stderr goes to /dev/null instead of an undrained Pipe, and the pipe is
closed in a defer. A chatty pkg-config could previously fill the stderr
pipe buffer and deadlock the child, hanging the first map creation.
Tests
- PluginDiscoveryTests covers version parsing, numeric comparison
(4.10 > 4.2, 10.0 > 3.1), unversioned paths, and picking the newest
plugin directory from a synthetic layout.
- MapnikConfigInitializationTests runs the process-wide initialization
scenarios in child processes: bad paths throw, a failure does not poison
the lazy default init, and different paths after success throw.
Fixes #11
Fixes #12
Fixes #38
Fixes #39
Fixes #40
The child-process initialization tests assumed argv[0] is the runnable test binary, which is true on Linux but not on macOS: there argv[0] is the .xctest bundle directory and the executable lives in Contents/MacOS/<name>. The helper now handles both layouts, returns nil (skip) when neither matches, and the resolution is unit-tested for the bundle layout so it is covered on Linux CI too.
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
MapnikConfig.initializereported success for paths that registered nothing, cached failures forever, and silently ignored custom paths once the lazy default had run. The Linux plugin discovery also never actually compared versions. This PR fixes all of it.Initialization
initializesucceeded for nonexistent pathsregister_fonts("/nonexistent", true)returns0without throwing, andregister_datasourcesdoes not throw for an empty directory either, somapnik_initreturnedtrue:mapnik_initnow checks that each non-empty path exists, is a directory, and actually registers something (at least one.inputfile;register_fontsreturning true).A failed init poisoned the process permanently
The failure was cached as
.failure, so the lazyensureInitializedpath could never retry with the platform defaults. Failures are no longer cached:Custom paths after the lazy default were silently ignored
Same paths stay a cheap no-op; different paths now surface the ordering mistake.
Plugin discovery
versionComponentsusedInt("4.2"), which isnil, so every candidate produced an empty version list and the "highest version wins" logic silently degraded to a lexicographic tiebreak:The version component is now split on
.and compared numerically.compareVersionedPathsandhighestVersionedDirectoryare internal so they can be tested directly, and the cached path moved out of a lazystatic letinto the lock-protected state with an injectable provider.pkg-config deadlock
standardErrorwas an undrainedPipe(). Apkg-configthat writes more than the pipe buffer to stderr would block forever whilereadDataToEndOfFile()waited on stdout — hanging the firstMapnik(xml:)in the process. stderr now goes to/dev/nulland the pipe is closed in adefer.Testing
PluginDiscoveryTests: version parsing, numeric comparison (4.10 > 4.2,10.0 > 3.1), unversioned paths, and picking the newest directory from a synthetic layout.MapnikConfigInitializationTests: the process-wide scenarios run in child processes (bad paths throw, a failure does not poison the lazy init, different paths after success throw).saveXML(explicitDefaults:)failures remaining — fixed in Honour all render options and fix metatile geometry #111.Breaking changes
initializethrows for a nonexistent/empty plugin or font path instead of silently succeeding.initializethrows when called with different paths after a successful initialization.defaultPluginPath/defaultFontPathare computed properties (same values).Closes #11
Closes #12
Closes #38
Closes #39
Closes #40