Repository navigation
Free the string or byte buffer MEOS hands the caller once it is copied - #47
Merged
estebanzimanyi merged 1 commit intoNov 2, 2026
Merged
Conversation
A MEOS function returning char * hands the caller a string the caller owns, as MEOS's example 03_berlinmod_assemble.c frees the temporal_as_hexwkb it writes, so the wrapper copies it into a Python str and frees it (_take_string); a const char * names a string MEOS keeps, such as temporal_subtype's, and is copied alone (_read_string). A byte buffer MEOS sizes through a size_t pointer is copied into bytes and freed the same way (_take_bytes). A NULL return is None before any copy. The cdef declares the C library's free beside the catalog's functions. GoMEOS frees each char * return and leaves each const char * alone, and MEOS.NET's string marshalling frees the string it copies. Witness: a wrapper returning _ffi.string(result).decode(...) or bytes(_ffi.buffer(result, size)) left the C allocation behind on every call: 152 string returns, 48 byte buffers and text_to_cstring. Measured: on wheels generated from one catalog of MobilityDB master 9c0caecd72, before and after, 200000 calls each grow the resident set by 15616 KB (temporal_out), 18688 KB (temporal_as_hexwkb) and 12416 KB (temporal_as_wkb) before and by 0 KB after; the generated surfaces differ in those returns and the three helpers alone; PyMEOS master passes 4855 tests with 1 skipped on the wheel after, and the smoke test reads a freed and a kept string twice each.
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.
A MEOS function returning char * hands the caller a string the caller
owns, as MEOS's example 03_berlinmod_assemble.c frees the
temporal_as_hexwkb it writes, so
the wrapper copies it into a Python str and frees it (_take_string); a
const char * names a string MEOS keeps, such as temporal_subtype's, and
is copied alone (_read_string). A byte buffer MEOS sizes through a
size_t pointer is copied into bytes and freed the same way
(_take_bytes). A NULL return is None before any copy. The cdef declares
the C library's free beside the catalog's functions. GoMEOS frees each
char * return and leaves each const char * alone, and MEOS.NET's string
marshalling frees the string it copies.
Witness: a wrapper returning _ffi.string(result).decode(...) or
bytes(_ffi.buffer(result, size)) left the C allocation behind on every
call: 152 string returns, 48 byte buffers and text_to_cstring.
Measured: on wheels generated from one catalog of MobilityDB master
9c0caecd72, before and after, 200000 calls each grow the resident set by
15616 KB (temporal_out), 18688 KB (temporal_as_hexwkb) and 12416 KB
(temporal_as_wkb) before and by 0 KB after; the generated surfaces
differ in those returns and the three helpers alone; PyMEOS master
passes 4855 tests with 1 skipped on the wheel after, and the smoke test
reads a freed and a kept string twice each.