mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Spicy: Fix passing vectors to Zeek.
We missed the allocator argument for the C++-side conversion template, which let vector's of certain types not compile. Closes #4250.
This commit is contained in:
parent
60bd08ca1a
commit
b77faa765a
3 changed files with 19 additions and 7 deletions
|
@ -502,8 +502,8 @@ template<typename K, typename V>
|
|||
ValPtr to_val(const hilti::rt::Map<K, V>& s, const TypePtr& target);
|
||||
template<typename T>
|
||||
ValPtr to_val(const hilti::rt::Set<T>& s, const TypePtr& target);
|
||||
template<typename T>
|
||||
ValPtr to_val(const hilti::rt::Vector<T>& v, const TypePtr& target);
|
||||
template<typename T, typename Allocator>
|
||||
ValPtr to_val(const hilti::rt::Vector<T, Allocator>& v, const TypePtr& target);
|
||||
template<typename T>
|
||||
ValPtr to_val(const std::optional<T>& t, const TypePtr& target);
|
||||
template<typename T, typename E>
|
||||
|
@ -695,8 +695,8 @@ inline ValPtr to_val(const hilti::rt::Time& t, const TypePtr& target) {
|
|||
* Converts a Spicy-side vector to a Zeek value. The result is returned with
|
||||
* ref count +1.
|
||||
*/
|
||||
template<typename T>
|
||||
inline ValPtr to_val(const hilti::rt::Vector<T>& v, const TypePtr& target) {
|
||||
template<typename T, typename Allocator>
|
||||
inline ValPtr to_val(const hilti::rt::Vector<T, Allocator>& v, const TypePtr& target) {
|
||||
if ( target->Tag() != TYPE_VECTOR && target->Tag() != TYPE_LIST )
|
||||
throw ParameterMismatch("expected vector or list", target);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
[$a=b"SSH-2", $b=11824, $c=11599, $d=3.14, $e=1.2.3.4, $f=2001:db8::1428:57ab, $g=True, $h="MyString", $i=2011-01-19T05:31:50.500000000Z, $j=4.000000s, $r=[$i=11, $s=(not set)], $s={1, 2, 3}, $t=(47, "foo"), $v=[b"A", b"B", b"C"], $l=[b"A", b"B", b"C"], $m={1: "A", 2: "B", 3: "C"}]
|
||||
[$a=b"SSH-2", $b=11824, $c=11599, $d=3.14, $e=1.2.3.4, $f=2001:db8::1428:57ab, $g=True, $h="MyString", $i=2011-01-19T05:31:50.500000000Z, $j=4.000000s, $k=Enum::B, $r=[$i=11, $s=(not set)], $s={1, 2, 3}, $t=(47, "foo"), $v=[b"A", b"B", b"C"], $l=[b"A", b"B", b"C"], $m={1: "A", 2: "B", 3: "C"}, $n=[Enum::A, Enum::B]]
|
||||
[orig_h=192.150.186.169, orig_p=49244/tcp, resp_h=131.159.14.23, resp_p=22/tcp, proto=6]
|
||||
T
|
||||
SSH-2
|
||||
|
@ -12,6 +12,7 @@ T
|
|||
MyString
|
||||
XXXXXXXXXX.XXXXXX
|
||||
4.000000, interval
|
||||
Conv::Enum_B
|
||||
[i=11, s=<uninitialized>]
|
||||
{
|
||||
2,
|
||||
|
@ -26,3 +27,4 @@ XXXXXXXXXX.XXXXXX
|
|||
[1] = A,
|
||||
[3] = C
|
||||
}
|
||||
[Conv::Enum_A, Conv::Enum_B]
|
||||
|
|
|
@ -12,6 +12,8 @@ event zeek_init() {
|
|||
|
||||
module Conv;
|
||||
|
||||
public type Enum = enum { A, B = 2, C };
|
||||
|
||||
public type Test = unit {
|
||||
a: bytes &size=5;
|
||||
b: int16;
|
||||
|
@ -23,6 +25,7 @@ public type Test = unit {
|
|||
h: bytes &size=1 &convert="MyString";
|
||||
i: bytes &size=1 &convert=time(1295415110.5);
|
||||
j: bytes &size=1 &convert=interval(4.0);
|
||||
k: bytes &size=1 &convert=Enum(2);
|
||||
|
||||
var r: MyStruct = [$i = 11];
|
||||
var s: set<uint64> = set<uint64>(1,2,3);
|
||||
|
@ -30,6 +33,7 @@ public type Test = unit {
|
|||
var v: vector<bytes> = vector<bytes>(b"A", b"B", b"C");
|
||||
var l: vector<bytes> = vector<bytes>(b"A", b"B", b"C");
|
||||
var m: map<int64, string> = map(1: "A", 2: "B", 3: "C");
|
||||
var n: vector<Enum> = [Enum::A, Enum::B];
|
||||
|
||||
on %done { print self; }
|
||||
};
|
||||
|
@ -59,12 +63,14 @@ on Conv::Test -> event conv::test($conn,
|
|||
self.h,
|
||||
self.i,
|
||||
self.j,
|
||||
self.k,
|
||||
self.r,
|
||||
self.s,
|
||||
self.t,
|
||||
self.v,
|
||||
self.l,
|
||||
self.m
|
||||
self.m,
|
||||
self.n
|
||||
);
|
||||
|
||||
@TEST-END-FILE
|
||||
|
@ -86,12 +92,14 @@ event conv::test(x: connection,
|
|||
h: string,
|
||||
i: time,
|
||||
j: interval,
|
||||
k: Conv::Enum,
|
||||
r: MyRecord,
|
||||
s: set[count],
|
||||
t: MyRecord,
|
||||
v: vector of string,
|
||||
l: vector of string,
|
||||
m: table[int] of string
|
||||
m: table[int] of string,
|
||||
n: vector of Conv::Enum
|
||||
)
|
||||
{
|
||||
print x$id;
|
||||
|
@ -106,10 +114,12 @@ event conv::test(x: connection,
|
|||
print h;
|
||||
print i;
|
||||
print fmt("%f", j), type_name(j); # print as float as interval format differs between versions
|
||||
print k;
|
||||
print r;
|
||||
print s;
|
||||
print t;
|
||||
print v;
|
||||
print l;
|
||||
print m;
|
||||
print n;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue