]> granicus.if.org Git - jq/commitdiff
Define error/1 in terms of error/0
authorMuh Muhten <muh.muhten@gmail.com>
Thu, 7 Feb 2019 02:00:02 +0000 (21:00 -0500)
committerNico Williams <nico@cryptonector.com>
Thu, 7 Feb 2019 17:05:06 +0000 (11:05 -0600)
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.

src/builtin.c
src/builtin.jq

index 87941984f2cbc68b5689360e51301d2c35d976e5..5d44b1d34faa6b33c32adb922cad0b374461a705 100644 (file)
@@ -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},
index 02bec9c181c57a5115d738c2937c90243a885001..d1be3f40073aa1b6f02243c3100984fbd6996eeb 100644 (file)
@@ -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]));