Skip to content

Commit 9ae7aa8

Browse files
kevinelliottclaude
andcommitted
Runtime (C): uniform 2-arg helper signatures (matches Rust convergence)
Every decode-fn helper now accepts (value, args_json), where args_json is '{}' when the spec specifies no args. Args-free helpers (decode_float, decode_string, etc.) just ignore the second arg. Removes the *_args / *_with_args duplicate functions; they had unified implementations behind separate names which confused the emitter dispatch. Now the emitter always emits the same 2-arg form regardless of whether args is empty. Same fix shape as the Rust convergence pass (init/ads-v1@6b475ff). Both runtimes are now consistent. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fae352d commit 9ae7aa8

2 files changed

Lines changed: 49 additions & 34 deletions

File tree

‎runtimes/c/include/ads_helpers.h‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,23 @@ void ads_regex_match_free(ads_regex_match_t *m);
3030
bool ads_regex_test(const char *pattern, const char *input);
3131

3232
/* ─── Decode-fn helpers ──────────────────────────────────────────────────── */
33+
/* Uniform signature: every decode-fn helper accepts (value, args_json),
34+
* where args_json is "{}" when the spec specifies no args. Simplifies the
35+
* emitter and matches the Rust runtime's convergence pass. */
3336

3437
ads_value_t *ads_decode_coordinate(const char *value, const char *args_json);
3538
ads_value_t *ads_decode_coordinate_decimal_minutes(const char *value, const char *args_json);
36-
ads_value_t *ads_decode_integer(const char *value);
37-
ads_value_t *ads_decode_integer_args(const char *value, const char *args_json);
38-
ads_value_t *ads_decode_float(const char *value);
39-
ads_value_t *ads_decode_string(const char *value);
40-
ads_value_t *ads_decode_trim(const char *value);
41-
ads_value_t *ads_decode_uppercase(const char *value);
42-
ads_value_t *ads_decode_lowercase(const char *value);
43-
ads_value_t *ads_decode_timestamp_hhmmss(const char *value);
44-
ads_value_t *ads_decode_timestamp_hhmmss_args(const char *value, const char *args_json);
45-
ads_value_t *ads_decode_callsign(const char *value);
39+
ads_value_t *ads_decode_integer(const char *value, const char *args_json);
40+
ads_value_t *ads_decode_float(const char *value, const char *args_json);
41+
ads_value_t *ads_decode_string(const char *value, const char *args_json);
42+
ads_value_t *ads_decode_trim(const char *value, const char *args_json);
43+
ads_value_t *ads_decode_uppercase(const char *value, const char *args_json);
44+
ads_value_t *ads_decode_lowercase(const char *value, const char *args_json);
45+
ads_value_t *ads_decode_timestamp_hhmmss(const char *value, const char *args_json);
46+
ads_value_t *ads_decode_callsign(const char *value, const char *args_json);
4647
ads_value_t *ads_decode_tail_number(const char *value, const char *args_json);
47-
ads_value_t *ads_decode_flight_number(const char *value);
48-
ads_value_t *ads_decode_airport(const char *value);
48+
ads_value_t *ads_decode_flight_number(const char *value, const char *args_json);
49+
ads_value_t *ads_decode_airport(const char *value, const char *args_json);
4950

5051
/* ─── Binary / encoding ──────────────────────────────────────────────────── */
5152

‎runtimes/c/src/helpers.c‎

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
/* Decode-fn helpers (numerics, strings, identifiers, encodings, bitfields). */
1+
/* Decode-fn helpers (numerics, strings, identifiers, encodings, bitfields).
2+
*
3+
* Uniform signature: every helper accepts (value, args_json). Args-free
4+
* helpers ignore the second arg. Matches the Rust runtime's pattern.
5+
*/
26

37
#include "ads_helpers.h"
48
#include <cjson/cJSON.h>
@@ -19,11 +23,7 @@ static char *substr_copy(const char *s, size_t start, size_t len) {
1923
return out;
2024
}
2125

22-
ads_value_t *ads_decode_integer(const char *value) {
23-
return ads_value_from_int(value ? atoll(value) : 0);
24-
}
25-
26-
ads_value_t *ads_decode_integer_args(const char *value, const char *args_json) {
26+
ads_value_t *ads_decode_integer(const char *value, const char *args_json) {
2727
cJSON *args = args_json ? cJSON_Parse(args_json) : NULL;
2828
size_t start = 0;
2929
long len = -1;
@@ -37,17 +37,31 @@ ads_value_t *ads_decode_integer_args(const char *value, const char *args_json) {
3737
if (cJSON_IsNumber(m)) mult = m->valuedouble;
3838
}
3939
cJSON_Delete(args);
40+
if (!value) return ads_value_from_double(0.0);
4041
char *s = len >= 0 ? substr_copy(value, start, (size_t)len)
4142
: substr_copy(value, start, strlen(value));
4243
double n = atof(s) * mult;
4344
free(s);
4445
return ads_value_from_double(n);
4546
}
4647

47-
ads_value_t *ads_decode_float(const char *value) { return ads_value_from_double(value ? atof(value) : 0.0); }
48-
ads_value_t *ads_decode_string(const char *value) { return ads_value_from_string(value ? value : ""); }
49-
ads_value_t *ads_decode_callsign(const char *value) { return ads_decode_string(value); }
50-
ads_value_t *ads_decode_flight_number(const char *v) { return ads_decode_string(v); }
48+
ads_value_t *ads_decode_float(const char *value, const char *args_json) {
49+
(void)args_json;
50+
return ads_value_from_double(value ? atof(value) : 0.0);
51+
}
52+
53+
ads_value_t *ads_decode_string(const char *value, const char *args_json) {
54+
(void)args_json;
55+
return ads_value_from_string(value ? value : "");
56+
}
57+
58+
ads_value_t *ads_decode_callsign(const char *value, const char *args_json) {
59+
return ads_decode_string(value, args_json);
60+
}
61+
62+
ads_value_t *ads_decode_flight_number(const char *value, const char *args_json) {
63+
return ads_decode_string(value, args_json);
64+
}
5165

5266
static char *trim_inplace(char *s) {
5367
char *start = s;
@@ -58,31 +72,35 @@ static char *trim_inplace(char *s) {
5872
return s;
5973
}
6074

61-
ads_value_t *ads_decode_trim(const char *value) {
75+
ads_value_t *ads_decode_trim(const char *value, const char *args_json) {
76+
(void)args_json;
6277
char *copy = strdup(value ? value : "");
6378
trim_inplace(copy);
6479
ads_value_t *v = ads_value_from_string(copy);
6580
free(copy);
6681
return v;
6782
}
6883

69-
ads_value_t *ads_decode_uppercase(const char *value) {
84+
ads_value_t *ads_decode_uppercase(const char *value, const char *args_json) {
85+
(void)args_json;
7086
char *copy = strdup(value ? value : "");
7187
for (char *p = copy; *p; p++) *p = (char)toupper((unsigned char)*p);
7288
ads_value_t *v = ads_value_from_string(copy);
7389
free(copy);
7490
return v;
7591
}
7692

77-
ads_value_t *ads_decode_lowercase(const char *value) {
93+
ads_value_t *ads_decode_lowercase(const char *value, const char *args_json) {
94+
(void)args_json;
7895
char *copy = strdup(value ? value : "");
7996
for (char *p = copy; *p; p++) *p = (char)tolower((unsigned char)*p);
8097
ads_value_t *v = ads_value_from_string(copy);
8198
free(copy);
8299
return v;
83100
}
84101

85-
ads_value_t *ads_decode_airport(const char *value) {
102+
ads_value_t *ads_decode_airport(const char *value, const char *args_json) {
103+
(void)args_json;
86104
char *copy = strdup(value ? value : "");
87105
trim_inplace(copy);
88106
for (char *p = copy; *p; p++) *p = (char)toupper((unsigned char)*p);
@@ -121,20 +139,16 @@ static int64_t hhmmss_to_tod(const char *s) {
121139
return (int64_t)h * 3600 + (int64_t)m * 60 + sec;
122140
}
123141

124-
ads_value_t *ads_decode_timestamp_hhmmss(const char *value) {
125-
return ads_value_from_int(hhmmss_to_tod(value));
126-
}
127-
128-
ads_value_t *ads_decode_timestamp_hhmmss_args(const char *value, const char *args_json) {
142+
ads_value_t *ads_decode_timestamp_hhmmss(const char *value, const char *args_json) {
129143
cJSON *args = args_json ? cJSON_Parse(args_json) : NULL;
130144
const cJSON *app = args ? cJSON_GetObjectItemCaseSensitive(args, "append") : NULL;
131145
char *combined;
132146
if (app && cJSON_IsString(app)) {
133-
size_t n = strlen(value) + strlen(app->valuestring) + 1;
147+
size_t n = strlen(value ? value : "") + strlen(app->valuestring) + 1;
134148
combined = malloc(n);
135-
snprintf(combined, n, "%s%s", value, app->valuestring);
149+
snprintf(combined, n, "%s%s", value ? value : "", app->valuestring);
136150
} else {
137-
combined = strdup(value);
151+
combined = strdup(value ? value : "");
138152
}
139153
cJSON_Delete(args);
140154
int64_t tod = hhmmss_to_tod(combined);

0 commit comments

Comments
 (0)