summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMuh Muhten <muh.muhten@gmail.com>2019-02-06 21:00:02 -0500
committerNico Williams <nico@cryptonector.com>2019-02-07 11:05:06 -0600
commit956d40d9dd7cc69227af817009ad47373e709e5f (patch)
tree934cf1ec225587336db641cc7b234a66ab909e3b
parent2fd725209e33558c3a79b7316bf994dc55d3a005 (diff)
Define error/1 in terms of error/0
The parser generates a call to error/0 on break. Having that exported from C directly removes a language dependency on builtin.jq. In any case, error/0 seems to be the more fundamental operation, seeing as the old C impementation of error/1 did nothing useful with its input.
-rw-r--r--src/builtin.c7
-rw-r--r--src/builtin.jq2
2 files changed, 4 insertions, 5 deletions
diff --git a/src/builtin.c b/src/builtin.c
index 87941984..5d44b1d3 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -1056,9 +1056,8 @@ static jv f_nan(jq_state *jq, jv input) {
return jv_number(NAN);
}
-static jv f_error(jq_state *jq, jv input, jv msg) {
- jv_free(input);
- return jv_invalid_with_msg(msg);
+static jv f_error(jq_state *jq, jv input) {
+ return jv_invalid_with_msg(input);
}
// FIXME Should autoconf check for this!
@@ -1653,7 +1652,7 @@ static const struct cfunction function_list[] = {
{(cfunction_ptr)f_max, "max", 1},
{(cfunction_ptr)f_min_by_impl, "_min_by_impl", 2},
{(cfunction_ptr)f_max_by_impl, "_max_by_impl", 2},
- {(cfunction_ptr)f_error, "error", 2},
+ {(cfunction_ptr)f_error, "error", 1},
{(cfunction_ptr)f_format, "format", 2},
{(cfunction_ptr)f_env, "env", 1},
{(cfunction_ptr)f_halt, "halt", 1},
diff --git a/src/builtin.jq b/src/builtin.jq
index 02bec9c1..d1be3f40 100644
--- a/src/builtin.jq
+++ b/src/builtin.jq
@@ -1,5 +1,5 @@
def halt_error: halt_error(5);
-def error: error(.);
+def error(msg): msg|error;
def map(f): [.[] | f];
def select(f): if f then . else empty end;
def sort_by(f): _sort_by_impl(map([f]));