[Bro] new patch for binpac in bro-1.2.1-dev.tar.gz
jmzhou.ml at gmail.com
jmzhou.ml at gmail.com
Thu Apr 19 09:35:00 PDT 2007
Hi,
This includes the patch I sent yesterday, and a new fix to solve a
problem of dependency issue in Type::Prepare.
BTW, is there a CVS/SVN tree to track the latest code? It will
make patching easier.
Cheers,
Jimmy
____________________________________________________________
The future is not set. There is no fate but what we make
for ourselves. - Terminator II, Judgment Day
------------------------------------------------------------
-------------- next part --------------
diff -urNp bro-1.2.1.orig/src/binpac/pac_common.h bro-1.2.1/src/binpac/pac_common.h
--- bro-1.2.1.orig/src/binpac/pac_common.h 2006-07-26 15:02:40.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_common.h 2007-04-18 11:09:16.000000000 -0700
@@ -105,6 +105,11 @@ typedef vector<StateVar*> StateVarList;
if ( pc ) \
for ( ct::iterator i = (pc)->begin(); i != (pc)->end(); ++i )
+#define foreach_rev(i, ct, pc) \
+ if ( pc ) \
+ for ( ct::iterator i = (pc)->end(); i-- != (pc)->begin(); )
+
+
#define delete_list(ct, pc) \
{ \
foreach(delete_list_i, ct, pc) \
diff -urNp bro-1.2.1.orig/src/binpac/pac_expr.def bro-1.2.1/src/binpac/pac_expr.def
--- bro-1.2.1.orig/src/binpac/pac_expr.def 2006-07-26 15:02:39.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_expr.def 2007-04-18 11:06:47.000000000 -0700
@@ -14,7 +14,7 @@ EXPR_DEF(EXPR_PLUS, 2, "%s + %s")
EXPR_DEF(EXPR_MINUS, 2, "%s - %s")
EXPR_DEF(EXPR_TIMES, 2, "%s * %s")
EXPR_DEF(EXPR_DIV, 2, "%s / %s")
-EXPR_DEF(EXPR_MOD, 2, "%s % %s")
+EXPR_DEF(EXPR_MOD, 2, "%s %% %s")
EXPR_DEF(EXPR_BITNOT, 1, "~%s")
EXPR_DEF(EXPR_BITAND, 2, "%s & %s")
EXPR_DEF(EXPR_BITOR, 2, "%s | %s")
diff -urNp bro-1.2.1.orig/src/binpac/pac_field.cc bro-1.2.1/src/binpac/pac_field.cc
--- bro-1.2.1.orig/src/binpac/pac_field.cc 2006-07-26 15:02:39.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_field.cc 2007-04-19 09:23:59.000000000 -0700
@@ -12,6 +12,7 @@ Field::Field(FieldType tof, int flags, I
decl_id_ = current_decl_id;
field_id_str_ = strfmt("%s:%s", decl_id()->Name(), id_->Name());
attrs_ = 0;
+ prepared_ = false;
}
Field::~Field()
@@ -73,6 +74,11 @@ int Field::ValueVarType() const
void Field::Prepare(Env *env)
{
+ /* prevent infinite recursion */
+ if ( prepared_ )
+ return ;
+ prepared_ = true;
+
if ( type_ )
{
if ( anonymous_field() )
diff -urNp bro-1.2.1.orig/src/binpac/pac_field.h bro-1.2.1/src/binpac/pac_field.h
--- bro-1.2.1.orig/src/binpac/pac_field.h 2006-07-26 15:02:40.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_field.h 2007-04-19 09:24:05.000000000 -0700
@@ -74,6 +74,7 @@ protected:
protected:
FieldType tof_;
int flags_;
+ bool prepared_;
ID* id_;
Type *type_;
const ID* decl_id_;
diff -urNp bro-1.2.1.orig/src/binpac/pac_type.cc bro-1.2.1/src/binpac/pac_type.cc
--- bro-1.2.1.orig/src/binpac/pac_type.cc 2006-07-26 15:02:40.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_type.cc 2007-04-19 09:29:56.000000000 -0700
@@ -305,9 +305,40 @@ void Type::Prepare(Env* env, int flags)
}
}
+ /* prepare parameter fields first as they may be dependency */
foreach (i, FieldList, fields_)
{
Field *f = *i;
+ if (PARAM_FIELD == f->tof())
+ f->Prepare(env);
+ }
+
+ foreach (i, FieldList, fields_)
+ {
+ Field *f = *i;
+ Expr* req;
+ if (NULL == f->type() /* can be a padding field */ ||
+ NULL == (req = f->type()->attr_requires()))
+ {
+ /* there is no &requires dependents, good! */
+ f->Prepare(env);
+ continue;
+ }
+
+ /* there are dependents on some &let fields :-( */
+ ASSERT(Expr::EXPR_CALLARGS == req->expr_type());
+
+ FieldList::iterator newi = i+1;
+ for (; newi != fields_->end(); ++ newi)
+ {
+ /* not a field of &let, ignore it */
+ Field* newf = *newi;
+ if (LET_FIELD != newf->tof())
+ continue;
+
+ if (req->HasReference (newf->id()))
+ newf->Prepare(env);
+ }
f->Prepare(env);
}
}
@@ -367,7 +398,7 @@ void Type::GenInitCode(Output* out_cc, E
void Type::GenCleanUpCode(Output* out_cc, Env* env)
{
- foreach (i, FieldList, fields_)
+ foreach_rev (i, FieldList, fields_)
{
Field *f = *i;
if ( f->tof() != CASE_FIELD )
diff -urNp bro-1.2.1.orig/src/binpac/pac_type.h bro-1.2.1/src/binpac/pac_type.h
--- bro-1.2.1.orig/src/binpac/pac_type.h 2006-10-17 15:46:32.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_type.h 2007-04-19 09:28:18.000000000 -0700
@@ -155,6 +155,7 @@ public:
Expr *attr_if_expr() const { return attr_if_expr_; }
// TODO: generate the length expression automatically.
Expr *attr_length_expr() const { return attr_length_expr_; }
+ Expr *attr_requires() const { return attr_requires_; }
bool attr_refcount() const { return attr_refcount_; }
bool attr_transient() const { return attr_transient_; }
More information about the Bro
mailing list