revised error-reporting interface for ZVal's, to accommodate ZAM inner loop

This commit is contained in:
Vern Paxson 2021-05-30 18:36:21 -07:00
parent d524318154
commit f3fa8a7c0b
2 changed files with 12 additions and 10 deletions

View file

@ -9,7 +9,7 @@
using namespace zeek;
bool ZVal::zval_was_nil = false;
bool* ZVal::zval_was_nil_addr = nullptr;
ZVal::ZVal(ValPtr v, const TypePtr& t)
@ -271,7 +271,8 @@ ValPtr ZVal::ToVal(const TypePtr& t) const
if ( v )
return {NewRef{}, v};
zval_was_nil = true;
if ( zval_was_nil_addr )
*zval_was_nil_addr = true;
return nullptr;
}

View file

@ -88,13 +88,6 @@ union ZVal {
// ensure that they're providing the correct type.
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_uint_t AsCount() const { return uint_val; }
double AsDouble() const { return double_val; }
@ -133,6 +126,14 @@ union ZVal {
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:
friend class RecordVal;
friend class VectorVal;
@ -175,7 +176,7 @@ private:
// because often the caller won't have direct access to the
// particular ZVal that produces the issue, and just wants to
// know whether it occurred at some point.
static bool zval_was_nil;
static bool* zval_was_nil_addr;
};
} // zeek