Repository navigation
Read the arguments a helper fills through the addresses of a wrapper's locals - #209
Merged
estebanzimanyi merged 1 commit intoOct 26, 2026
Conversation
…s locals A wrapper can hand the call info and the addresses of its locals to a helper reading its arguments: Raster_value_count_rows calls value_count_args(fcinfo, false, &band, &exclude_nodata, &searchvalues, &nsearch, &roundto), which sets *band = nargs >= 4 ? PG_GETARG_INT32(1) : 1 and *exclude_nodata = nargs == 5 ? PG_GETARG_BOOL(2) : true. extract_wrappers and extract_helpers read each such call as the statements the helper runs (_expand_arg_helpers): each *p and (*p) as the local whose address p receives, a bare p as that address, a parameter given a literal as the literal, the local holding PG_NARGS() as PG_NARGS(), and a value chosen by the number of arguments as the value of the other numbers followed by its replacement under that test, band = 1; if (PG_NARGS() >= 4) band = PG_GETARG_INT32(1);, the shape _guarded_default reads. A call handing the helper no address is a delegation and stays. attach_null_default_binds follows a wrapper into the helper it delegates to, as merge_boundargs follows it, and reads a local starting from a literal and replaced only where argument k is not NULL (_notnull_default) as passing that literal for a NULL k. It reads the body for the number of arguments of each signature (_fold_nargs): PG_NARGS() as that number, a sum or difference of numbers as its value, a local set once to a number as that number where it indexes an argument, and a statement under a condition no argument changes, if (false), as one that never runs. Witness: on master, valueCount(raster, integer, float[], float) and valueCount(raster, float[], float), and their valuePercent twins, state no boundArgs, so no binding fills the C parameters exclude_nodata and band they leave out, and valueCount(raster, integer, boolean, float[], float) states no nullDefaultBinds for searchvalues DEFAULT NULL. Here the 4-argument forms bind exclude_nodata true, the 3-argument ones band 1 and exclude_nodata true, and a NULL searchvalues passes searchvalues NULL and nsearch 0, as value_count_args reads them. Measured over MobilityDB master f3d480c80a, from the headers of the libmeos it builds, as the tests job derives the catalog: the catalog differs from master's in raster_value_count, as above; in raster_clip, whose clip(raster, integer[], geometry, float[], boolean, boolean) passes nodata NULL and nnodata 0 for a NULL nodataval; and in raster_set_values, whose NULL noset passes noset NULL; each as its wrapper sets the local NULL and replaces it only under ! PG_ARGISNULL(k). Over that catalog the JVM generators of JMEOS main and MobilityDuck main's generator write the same files as over master's. tests/test_boundargs.py reads the binds of each number of arguments a helper leaves, the NULL default it replaces only when given, and no extra bind where every signature states every argument the helper reads; the suite passes, 602 tests and none skipped, with MDB_SRC_ROOT, MEOS_LIBRARY_PATH, MEOS_INCLUDE_DIR and PYMEOS_FACTORY set as the tests job sets them. Why: the C parameters a SQL signature leaves out reach a binding only through the binds the catalog states; a wrapper reading them through a helper stated none, so no binding could place those signatures.
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 wrapper can hand the call info and the addresses of its locals to a helper reading its arguments: Raster_value_count_rows calls value_count_args(fcinfo, false, &band, &exclude_nodata, &searchvalues, &nsearch, &roundto), which sets *band = nargs >= 4 ? PG_GETARG_INT32(1) : 1 and *exclude_nodata = nargs == 5 ? PG_GETARG_BOOL(2) : true. extract_wrappers and extract_helpers read each such call as the statements the helper runs (_expand_arg_helpers): each *p and (*p) as the local whose address p receives, a bare p as that address, a parameter given a literal as the literal, the local holding PG_NARGS() as PG_NARGS(), and a value chosen by the number of arguments as the value of the other numbers followed by its replacement under that test, band = 1; if (PG_NARGS() >= 4) band = PG_GETARG_INT32(1);, the shape _guarded_default reads. A call handing the helper no address is a delegation and stays.
attach_null_default_binds follows a wrapper into the helper it delegates to, as merge_boundargs follows it, and reads a local starting from a literal and replaced only where argument k is not NULL (_notnull_default) as passing that literal for a NULL k. It reads the body for the number of arguments of each signature (_fold_nargs): PG_NARGS() as that number, a sum or difference of numbers as its value, a local set once to a number as that number where it indexes an argument, and a statement under a condition no argument changes, if (false), as one that never runs.
Witness: on master, valueCount(raster, integer, float[], float) and valueCount(raster, float[], float), and their valuePercent twins, state no boundArgs, so no binding fills the C parameters exclude_nodata and band they leave out, and valueCount(raster, integer, boolean, float[], float) states no nullDefaultBinds for searchvalues DEFAULT NULL. Here the 4-argument forms bind exclude_nodata true, the 3-argument ones band 1 and exclude_nodata true, and a NULL searchvalues passes searchvalues NULL and nsearch 0, as value_count_args reads them.
Measured over MobilityDB master f3d480c80a, from the headers of the libmeos it builds, as the tests job derives the catalog: the catalog differs from master's in raster_value_count, as above; in raster_clip, whose clip(raster, integer[], geometry, float[], boolean, boolean) passes nodata NULL and nnodata 0 for a NULL nodataval; and in raster_set_values, whose NULL noset passes noset NULL; each as its wrapper sets the local NULL and replaces it only under ! PG_ARGISNULL(k). Over that catalog the JVM generators of JMEOS main and MobilityDuck main's generator write the same files as over master's. tests/test_boundargs.py reads the binds of each number of arguments a helper leaves, the NULL default it replaces only when given, and no extra bind where every signature states every argument the helper reads; the suite passes, 602 tests and none skipped, with MDB_SRC_ROOT, MEOS_LIBRARY_PATH, MEOS_INCLUDE_DIR and PYMEOS_FACTORY set as the tests job sets them.
Why: the C parameters a SQL signature leaves out reach a binding only through the binds the catalog states; a wrapper reading them through a helper stated none, so no binding could place those signatures.