From 10dc1c4bc2b01198fd23d0443a2f9a9a5e47d71f Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Wed, 19 Apr 2023 14:42:00 +0200 Subject: [PATCH] zeek.bif: Remove cat_sep() fully var_arg changes These were introduced to better catch type violations at runtime. With bifcl doing these checks, revert to a better documented version. --- src/zeek.bif | 38 +++---------------- .../Baseline/bifs.cat_sep_errors-2/.stderr | 2 +- .../Baseline/bifs.cat_sep_errors-3/.stderr | 2 +- .../Baseline/bifs.cat_sep_errors-4/.stderr | 2 +- .../Baseline/bifs.cat_sep_errors-5/.stderr | 2 +- .../Baseline/bifs.cat_sep_errors/.stderr | 2 +- 6 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/zeek.bif b/src/zeek.bif index 5684d7fac5..924cb720e1 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1541,44 +1541,18 @@ function cat%(...%): string ## Concatenates all arguments, with a separator placed between each one. This ## function is similar to :zeek:id:`cat`, but places a separator between each ## given argument. If any of the variable arguments is an empty string it is -## replaced by the given default string instead. This function takes at least -## two arguments. The first argument is the separator *sep* placed between -## each argument, the second argument is the default string *def* used when -## an argument is the empty string. +## replaced by the given default string instead. +## +## sep: The separator to place between each argument. +## +## def: The default string to use when an argument is the empty string. ## ## Returns: A concatenation of all arguments with *sep* between each one and ## empty strings replaced with *def*. ## ## .. zeek:see:: cat string_cat -function cat_sep%(...%): string +function cat_sep%(sep: string, def: string, ...%): string %{ - if ( @ARGC@ < 2 ) - { - zeek::emit_builtin_error(zeek::util::fmt("cat_sep() takes at least 2 arguments, got %ld", - @ARGC@)); - return nullptr; - } - - zeek::ValPtr sep_arg = @ARG@[0]; - zeek::ValPtr def_arg = @ARG@[1]; - - if ( sep_arg->GetType()->Tag() != zeek::TYPE_STRING ) - { - zeek::emit_builtin_error(zeek::util::fmt("expected type string for separator, got %s", - zeek::type_name(sep_arg->GetType()->Tag()))); - return nullptr; - } - - if ( def_arg->GetType()->Tag() != zeek::TYPE_STRING ) - { - zeek::emit_builtin_error(zeek::util::fmt("expected type string for default, got %s", - zeek::type_name(def_arg->GetType()->Tag()))); - return nullptr; - } - - zeek::StringVal* sep = sep_arg->AsStringVal(); - zeek::StringVal* def = def_arg->AsStringVal(); - zeek::ODesc d; d.SetStyle(RAW_STYLE); int pre_size = 0; diff --git a/testing/btest/Baseline/bifs.cat_sep_errors-2/.stderr b/testing/btest/Baseline/bifs.cat_sep_errors-2/.stderr index 13a40bc019..f3eeb2d94b 100644 --- a/testing/btest/Baseline/bifs.cat_sep_errors-2/.stderr +++ b/testing/btest/Baseline/bifs.cat_sep_errors-2/.stderr @@ -1,2 +1,2 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -error in <...>/cat_sep_errors.zeek, line 3: cat_sep() takes at least 2 arguments, got 1 (cat_sep(sep)) +error in <...>/cat_sep_errors.zeek, line 3: cat_sep() takes at least 2 argument(s), got 1 (cat_sep(sep)) diff --git a/testing/btest/Baseline/bifs.cat_sep_errors-3/.stderr b/testing/btest/Baseline/bifs.cat_sep_errors-3/.stderr index c19b73c3da..3aec3d0c30 100644 --- a/testing/btest/Baseline/bifs.cat_sep_errors-3/.stderr +++ b/testing/btest/Baseline/bifs.cat_sep_errors-3/.stderr @@ -1,2 +1,2 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -error in <...>/cat_sep_errors.zeek, line 4: expected type string for default, got count (cat_sep(sep, 1)) +error in <...>/cat_sep_errors.zeek, line 4: expected type string for def, got count (cat_sep(sep, 1)) diff --git a/testing/btest/Baseline/bifs.cat_sep_errors-4/.stderr b/testing/btest/Baseline/bifs.cat_sep_errors-4/.stderr index 6416ec7c35..c414809740 100644 --- a/testing/btest/Baseline/bifs.cat_sep_errors-4/.stderr +++ b/testing/btest/Baseline/bifs.cat_sep_errors-4/.stderr @@ -1,2 +1,2 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -error in <...>/cat_sep_errors.zeek, line 4: expected type string for separator, got count (cat_sep(1, default)) +error in <...>/cat_sep_errors.zeek, line 4: expected type string for sep, got count (cat_sep(1, default)) diff --git a/testing/btest/Baseline/bifs.cat_sep_errors-5/.stderr b/testing/btest/Baseline/bifs.cat_sep_errors-5/.stderr index 53fbad9616..fd3e37d3a7 100644 --- a/testing/btest/Baseline/bifs.cat_sep_errors-5/.stderr +++ b/testing/btest/Baseline/bifs.cat_sep_errors-5/.stderr @@ -1,2 +1,2 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -error in <...>/cat_sep_errors.zeek, line 3: expected type string for separator, got record (cat_sep([$a=1], default)) +error in <...>/cat_sep_errors.zeek, line 3: expected type string for sep, got record (cat_sep([$a=1], default)) diff --git a/testing/btest/Baseline/bifs.cat_sep_errors/.stderr b/testing/btest/Baseline/bifs.cat_sep_errors/.stderr index f3813297fe..c0a49beadf 100644 --- a/testing/btest/Baseline/bifs.cat_sep_errors/.stderr +++ b/testing/btest/Baseline/bifs.cat_sep_errors/.stderr @@ -1,2 +1,2 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -error in <...>/cat_sep_errors.zeek, line 6: cat_sep() takes at least 2 arguments, got 0 (cat_sep()) +error in <...>/cat_sep_errors.zeek, line 6: cat_sep() takes at least 2 argument(s), got 0 (cat_sep())