Skip to content

Read the arguments a helper fills through the addresses of a wrapper's locals - #209

Merged
estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:catalog/argument-helper-outparams
Oct 26, 2026
Merged

estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:catalog/argument-helper-outparams

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

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.

…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.
@estebanzimanyi
estebanzimanyi merged commit 185c560 into MobilityDB:master Oct 26, 2026
3 checks passed
@estebanzimanyi
estebanzimanyi deleted the catalog/argument-helper-outparams branch October 26, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant