Skip to content

Commit 1f5dabf

Browse files
committed
Some function call cleanup to make things more consistent.
1 parent 59ad4d2 commit 1f5dabf

8 files changed

Lines changed: 74 additions & 75 deletions

File tree

META.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
},
1818
"provides": {
1919
"pljs": {
20-
"file": "pljs--1.0.3.sql",
20+
"file": "pljs--1.0.4.sql",
2121
"docfile": "README.md",
22-
"version": "1.0.3",
22+
"version": "1.0.4",
2323
"abstract": "PLJS trusted procedural language"
2424
}
2525
},

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: lintcheck format cleansql docs clean test all
22

3-
PLJS_VERSION = 1.0.3
3+
PLJS_VERSION = 1.0.4
44

55
PG_CONFIG ?= pg_config
66
PGXS := $(shell $(PG_CONFIG) --pgxs)
@@ -21,9 +21,6 @@ SHLIB_LINK = -Ldeps/quickjs -lquickjs
2121
ifeq ($(DEBUG), 1)
2222
PG_CFLAGS += -g
2323
SHLIB_LINK += -g
24-
else
25-
PG_CFLAGS += -O3
26-
SHLIB_LINK += -O3
2724
endif
2825

2926
ifeq ($(DEBUG_MEMORY), 1)

docs/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ Released _August 20, 2025_.
2929

3030
- PGXN release went out with an incorrect control file
3131

32-
### 1.1.0
32+
### 1.0.4
3333

3434
- Up memory default limit to 512MB
3535
- Remove unnecessary include from modules.c
3636
- Remove extra running of GC after each execution
37+
- Better handling of SRF's, including freeing resources
38+
- Increased test timeouts to accommodate slower CI machines

pljs.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
comment = 'PL/JS trusted procedural language'
22

3-
default_version = '1.0.3'
3+
default_version = '1.0.4'
44
module_pathname = '$libdir/pljs'
55
relocatable = false
66
schema = pg_catalog

src/functions.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static int pljs_execute_params(const char *sql, JSValue params,
362362
JSValue param = JS_GetPropertyUint32(ctx, params, i);
363363
bool is_null;
364364

365-
values[i] = pljs_jsvalue_to_datum(param, parstate.param_types[i], ctx, NULL,
365+
values[i] = pljs_jsvalue_to_datum(parstate.param_types[i], param, ctx, NULL,
366366
&is_null);
367367

368368
JS_FreeValue(ctx, param);
@@ -441,7 +441,7 @@ static JSValue pljs_plan_execute(JSContext *ctx, JSValueConst this_val,
441441
bool is_null;
442442

443443
values[i] = pljs_jsvalue_to_datum(
444-
param, plan->parstate ? plan->parstate->param_types[i] : 0, ctx, NULL,
444+
plan->parstate ? plan->parstate->param_types[i] : 0, param, ctx, NULL,
445445
&is_null);
446446

447447
JS_FreeValue(ctx, param);
@@ -739,7 +739,7 @@ static JSValue pljs_plan_cursor(JSContext *ctx, JSValueConst this_val, int argc,
739739
bool is_null;
740740

741741
values[i] = pljs_jsvalue_to_datum(
742-
param, plan->parstate ? plan->parstate->param_types[i] : 0, ctx, NULL,
742+
plan->parstate ? plan->parstate->param_types[i] : 0, param, ctx, NULL,
743743
&is_null);
744744
}
745745

@@ -1070,7 +1070,7 @@ static JSValue pljs_return_next(JSContext *ctx, JSValueConst this_val, int argc,
10701070
}
10711071

10721072
bool *nulls = (bool *)palloc0(sizeof(bool) * retstate->tuple_desc->natts);
1073-
Datum *values = pljs_jsvalue_to_datums(argv[0], NULL, ctx, &nulls,
1073+
Datum *values = pljs_jsvalue_to_datums(NULL, argv[0], ctx, &nulls,
10741074
retstate->tuple_desc);
10751075

10761076
tuplestore_putvalues(retstate->tuple_store_state, retstate->tuple_desc,
@@ -1080,9 +1080,9 @@ static JSValue pljs_return_next(JSContext *ctx, JSValueConst this_val, int argc,
10801080
pfree(values);
10811081
} else {
10821082
bool is_null = false;
1083-
Datum result = pljs_jsvalue_to_datum(
1084-
argv[0], TupleDescAttr(retstate->tuple_desc, 0)->atttypid, ctx, NULL,
1085-
&is_null);
1083+
Datum result =
1084+
pljs_jsvalue_to_datum(TupleDescAttr(retstate->tuple_desc, 0)->atttypid,
1085+
argv[0], ctx, NULL, &is_null);
10861086
tuplestore_putvalues(retstate->tuple_store_state, retstate->tuple_desc,
10871087
&result, &is_null);
10881088
}
@@ -1378,7 +1378,7 @@ static JSValue pljs_window_get_func_arg_in_partition(JSContext *ctx,
13781378
return JS_UNDEFINED;
13791379
}
13801380

1381-
return pljs_datum_to_jsvalue(res, storage->function->argtypes[argno], ctx,
1381+
return pljs_datum_to_jsvalue(storage->function->argtypes[argno], res, ctx,
13821382
false);
13831383
}
13841384

@@ -1424,7 +1424,7 @@ static JSValue pljs_window_get_func_arg_in_frame(JSContext *ctx,
14241424
if (isout) {
14251425
return JS_UNDEFINED;
14261426
}
1427-
return pljs_datum_to_jsvalue(res, storage->function->argtypes[argno], ctx,
1427+
return pljs_datum_to_jsvalue(storage->function->argtypes[argno], res, ctx,
14281428
false);
14291429
}
14301430

@@ -1456,7 +1456,7 @@ static JSValue pljs_window_get_func_arg_current(JSContext *ctx,
14561456
}
14571457
PG_END_TRY();
14581458

1459-
return pljs_datum_to_jsvalue(res, storage->function->argtypes[argno], ctx,
1459+
return pljs_datum_to_jsvalue(storage->function->argtypes[argno], res, ctx,
14601460
false);
14611461
}
14621462

src/pljs.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static JSValueConst *convert_arguments_to_javascript(FunctionCallInfo fcinfo,
432432
if (isnull) {
433433
argv[i] = JS_NULL;
434434
} else {
435-
argv[i] = pljs_datum_to_jsvalue(arg, argtypes[i], context->ctx, true);
435+
argv[i] = pljs_datum_to_jsvalue(argtypes[i], arg, context->ctx, true);
436436
}
437437
}
438438
} else {
@@ -456,8 +456,8 @@ static JSValueConst *convert_arguments_to_javascript(FunctionCallInfo fcinfo,
456456
if (fcinfo->args[inargs].isnull == 1) {
457457
argv[inargs] = JS_NULL;
458458
} else {
459-
argv[inargs] = pljs_datum_to_jsvalue(fcinfo->args[inargs].value,
460-
argtype, context->ctx, false);
459+
argv[inargs] = pljs_datum_to_jsvalue(
460+
argtype, fcinfo->args[inargs].value, context->ctx, false);
461461
}
462462

463463
inargs++;
@@ -986,7 +986,7 @@ static Datum call_trigger(FunctionCallInfo fcinfo, pljs_context *context) {
986986

987987
pljs_type type;
988988
pljs_type_fill(&type, context->function->rettype);
989-
Datum d = pljs_jsvalue_to_record(ret, &type, context->ctx, NULL, tupdesc);
989+
Datum d = pljs_jsvalue_to_record(&type, ret, context->ctx, NULL, tupdesc);
990990

991991
HeapTupleHeader header = DatumGetHeapTupleHeader(d);
992992

@@ -1064,11 +1064,11 @@ static Datum call_function(FunctionCallInfo fcinfo, pljs_context *context,
10641064
pljs_type type;
10651065
pljs_type_fill(&type, rettype);
10661066

1067-
datum = pljs_jsvalue_to_record(ret, &type, context->ctx, NULL, tupdesc);
1067+
datum = pljs_jsvalue_to_record(&type, ret, context->ctx, NULL, tupdesc);
10681068
} else {
10691069
bool is_null;
10701070
datum =
1071-
pljs_jsvalue_to_datum(ret, rettype, context->ctx, fcinfo, &is_null);
1071+
pljs_jsvalue_to_datum(rettype, ret, context->ctx, fcinfo, &is_null);
10721072
}
10731073

10741074
JS_FreeValue(context->ctx, ret);
@@ -1189,7 +1189,7 @@ static Datum call_srf_function(FunctionCallInfo fcinfo, pljs_context *context,
11891189
if (state->is_composite) {
11901190
bool *nulls = (bool *)palloc0(sizeof(bool) * state->tuple_desc->natts);
11911191

1192-
Datum *values = pljs_jsvalue_to_datums(argv[0], NULL, context->ctx,
1192+
Datum *values = pljs_jsvalue_to_datums(NULL, argv[0], context->ctx,
11931193
&nulls, state->tuple_desc);
11941194
tuplestore_putvalues(state->tuple_store_state, state->tuple_desc,
11951195
values, nulls);
@@ -1203,15 +1203,15 @@ static Datum call_srf_function(FunctionCallInfo fcinfo, pljs_context *context,
12031203
JSValue val = JS_GetPropertyUint32(context->ctx, ret, i);
12041204

12051205
Datum result = pljs_jsvalue_to_datum(
1206-
val, TupleDescAttr(state->tuple_desc, 0)->atttypid,
1206+
TupleDescAttr(state->tuple_desc, 0)->atttypid, val,
12071207
context->ctx, NULL, &is_null);
12081208
tuplestore_putvalues(state->tuple_store_state, state->tuple_desc,
12091209
&result, &is_null);
12101210
}
12111211
} else {
12121212
if (!JS_IsUndefined(ret)) {
12131213
Datum result = pljs_jsvalue_to_datum(
1214-
ret, TupleDescAttr(state->tuple_desc, 0)->atttypid,
1214+
TupleDescAttr(state->tuple_desc, 0)->atttypid, ret,
12151215
context->ctx, NULL, &is_null);
12161216

12171217
tuplestore_putvalues(state->tuple_store_state, state->tuple_desc,

src/pljs.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,22 @@ void pljs_cache_reset(void);
181181
// type.c
182182

183183
// To Javascript
184-
JSValue pljs_datum_to_jsvalue(Datum arg, Oid type, JSContext *ctx,
184+
JSValue pljs_datum_to_jsvalue(Oid type, Datum arg, JSContext *ctx,
185185
bool skip_composite);
186-
JSValue pljs_datum_to_array(Datum arg, pljs_type *type, JSContext *ctx);
187-
JSValue pljs_datum_to_object(Datum arg, pljs_type *type, JSContext *ctx);
186+
JSValue pljs_datum_to_array(pljs_type *type, Datum arg, JSContext *ctx);
187+
JSValue pljs_datum_to_object(pljs_type *type, Datum arg, JSContext *ctx);
188188
JSValue pljs_tuple_to_jsvalue(TupleDesc, HeapTuple, JSContext *ctx);
189189
JSValue pljs_spi_result_to_jsvalue(int, JSContext *);
190190

191191
// To Postgres
192-
Datum pljs_jsvalue_to_array(JSValue, pljs_type *, JSContext *,
192+
Datum pljs_jsvalue_to_array(pljs_type *, JSValue, JSContext *,
193193
FunctionCallInfo);
194-
Datum pljs_jsvalue_to_datum(JSValue, Oid, JSContext *, FunctionCallInfo,
195-
bool *);
196-
Datum pljs_jsvalue_to_record(JSValue val, pljs_type *type, JSContext *ctx,
194+
Datum pljs_jsvalue_to_datum(Oid, JSValue, JSContext *, FunctionCallInfo,
195+
bool *is_null);
196+
Datum pljs_jsvalue_to_record(pljs_type *type, JSValue val, JSContext *ctx,
197197
bool *is_null, TupleDesc);
198-
Datum *pljs_jsvalue_to_datums(JSValue val, pljs_type *type, JSContext *ctx,
199-
bool **nulls, TupleDesc tupdesc);
198+
Datum *pljs_jsvalue_to_datums(pljs_type *type, JSValue val, JSContext *ctx,
199+
bool **is_null, TupleDesc tupdesc);
200200

201201
// Utility
202202
uint32_t pljs_js_array_length(JSValue, JSContext *);

0 commit comments

Comments
 (0)