Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions codegen/src/main/java/FunctionsGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public class FunctionsGenerator {
private static final Set<String> DATE_C_TYPES = Set.of("DateADT");
private static final Set<String> TIMESTAMP_C_TYPES = Set.of("Timestamp", "TimestampTz");

// The JSON sometimes encodes them as int32_t rather than size_t, producing
// "int" in the interface. old_functions.txt used "long" consistently for these,
// so we force long when the interface type resolved to int for these names.
private static final Set<String> SIZE_PARAM_NAMES = Set.of("size", "wkb_size");

/** Name of the leading parameter carrying the address of a struct returned through memory. */
private static final String RESULT_PARAM = "_result_address";

Expand Down Expand Up @@ -509,12 +504,6 @@ private FunctionDef parseFunctionDef(JsonNode fn) {
String pCType = p.get("cType").asText();
String pJava = mapCTypeToJava(pCType);

// Override int → long for known byte-count parameters.
// The JSON may emit int32_t for these; old_functions.txt used long.
if (SIZE_PARAM_NAMES.contains(pName) && pJava.equals("int")) {
pJava = "long";
}

params.add(new ParamDef(pName, pJava, pCType, outParams.contains(rawName)));
}
}
Expand Down Expand Up @@ -999,10 +988,6 @@ private String generateStaticMethod(FunctionDef fn, int partIndex) {
continue; // hide from signature; allocated below
}
String wrapperType = mapCTypeToJavaWrapper(p.cType);
// Preserve the long override for size params
if (SIZE_PARAM_NAMES.contains(p.name) && wrapperType.equals("int")) {
wrapperType = "long";
}
boolean needsConversion = isTemporalCType(p.cType);
wparams.add(new WrapperParam(p.name, wrapperType, p.javaType, needsConversion));
}
Expand Down Expand Up @@ -1199,10 +1184,7 @@ private String buildInterfaceParamList(List<ParamDef> params) {
if (params.isEmpty()) return "";
StringJoiner sj = new StringJoiner(", ");
for (ParamDef p : params) {
// Restore long for size params even at interface level
String type = SIZE_PARAM_NAMES.contains(p.name) && p.javaType.equals("int")
? "long" : p.javaType;
sj.add(type + " " + p.name);
sj.add(p.javaType + " " + p.name);
}
return sj.toString();
}
Expand Down
25 changes: 13 additions & 12 deletions codegen/src/test/java/FunctionsGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,27 +806,28 @@ void javaKeywordParam() throws Exception {
}

@Test
@DisplayName("size/wkb_size params use long in interface")
void sizeLongOverride() throws Exception {
@DisplayName("a parameter takes the Java type of its C type whatever its name")
void paramTypeFollowsCTypeNotName() throws Exception {
String json = """
{
"functions": [{
"name": "tsequence_make",
"returnType": {"c": "TSequence *"},
"name": "tint_value_split",
"returnType": {"c": "Temporal **"},
"params": [
{"name": "instants", "cType": "TInstant **"},
{"name": "size", "cType": "int32_t"},
{"name": "lower_inc","cType": "bool"},
{"name": "upper_inc","cType": "bool"},
{"name": "interp", "cType": "interpType"},
{"name": "normalize","cType": "bool"}
{"name": "temp", "cType": "const Temporal *"},
{"name": "size", "cType": "int"},
{"name": "wkb_size", "cType": "int32_t"},
{"name": "vsize", "cType": "size_t"}
]
}]
}
""";
String out = generateFromJson(json);
// 'size' must be long even though cType is int32_t
assertTrue(out.contains("long size"));
assertTrue(out.contains("int size"));
assertTrue(out.contains("int wkb_size"));
assertTrue(out.contains("long vsize"));
assertFalse(out.contains("long size"));
assertFalse(out.contains("long wkb_size"));
}

@Test
Expand Down
Loading