mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 11:38:20 +00:00
revised error-reporting interface for ZVal's, to accommodate ZAM inner loop
This commit is contained in:
parent
d524318154
commit
f3fa8a7c0b
2 changed files with 12 additions and 10 deletions
|
@ -9,7 +9,7 @@
|
||||||
using namespace zeek;
|
using namespace zeek;
|
||||||
|
|
||||||
|
|
||||||
bool ZVal::zval_was_nil = false;
|
bool* ZVal::zval_was_nil_addr = nullptr;
|
||||||
|
|
||||||
|
|
||||||
ZVal::ZVal(ValPtr v, const TypePtr& t)
|
ZVal::ZVal(ValPtr v, const TypePtr& t)
|
||||||
|
@ -271,7 +271,8 @@ ValPtr ZVal::ToVal(const TypePtr& t) const
|
||||||
if ( v )
|
if ( v )
|
||||||
return {NewRef{}, v};
|
return {NewRef{}, v};
|
||||||
|
|
||||||
zval_was_nil = true;
|
if ( zval_was_nil_addr )
|
||||||
|
*zval_was_nil_addr = true;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
17
src/ZVal.h
17
src/ZVal.h
|
@ -88,13 +88,6 @@ union ZVal {
|
||||||
// ensure that they're providing the correct type.
|
// ensure that they're providing the correct type.
|
||||||
ValPtr ToVal(const TypePtr& t) const;
|
ValPtr ToVal(const TypePtr& t) const;
|
||||||
|
|
||||||
// Whether a ZVal was accessed that was missing (a nil pointer).
|
|
||||||
// Used to generate run-time error messages.
|
|
||||||
static bool ZValNilStatus() { return zval_was_nil; }
|
|
||||||
|
|
||||||
// Resets the notion of low-level-error-occurred.
|
|
||||||
static void ClearZValNilStatus() { zval_was_nil = false; }
|
|
||||||
|
|
||||||
bro_int_t AsInt() const { return int_val; }
|
bro_int_t AsInt() const { return int_val; }
|
||||||
bro_uint_t AsCount() const { return uint_val; }
|
bro_uint_t AsCount() const { return uint_val; }
|
||||||
double AsDouble() const { return double_val; }
|
double AsDouble() const { return double_val; }
|
||||||
|
@ -133,6 +126,14 @@ union ZVal {
|
||||||
DeleteManagedType(v);
|
DeleteManagedType(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Specifies the address of a flag to set if a ZVal is accessed
|
||||||
|
// that was missing (a nil pointer). Used to generate run-time
|
||||||
|
// error messages. We use an address-based interface so that
|
||||||
|
// this flag can be combined with a general-purpose error flag,
|
||||||
|
// allowing inner loops to only have to test a single flag.
|
||||||
|
static void SetZValNilStatusAddr(bool* _zval_was_nil_addr)
|
||||||
|
{ zval_was_nil_addr = _zval_was_nil_addr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class RecordVal;
|
friend class RecordVal;
|
||||||
friend class VectorVal;
|
friend class VectorVal;
|
||||||
|
@ -175,7 +176,7 @@ private:
|
||||||
// because often the caller won't have direct access to the
|
// because often the caller won't have direct access to the
|
||||||
// particular ZVal that produces the issue, and just wants to
|
// particular ZVal that produces the issue, and just wants to
|
||||||
// know whether it occurred at some point.
|
// know whether it occurred at some point.
|
||||||
static bool zval_was_nil;
|
static bool* zval_was_nil_addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // zeek
|
} // zeek
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue