Thus wrote darkjames-ws@xxxxxxxxxxxx (darkjames-ws@xxxxxxxxxxxx):
> Hi,
> On Mon, Jul 28, 2014 at 10:47:43PM +0200, Martin Kaiser wrote:
> > However, I don't quite understand why for tree!=NULL but not visible,
> > proto_tree_add_text() returns tree. I can see this in the code, we call
> > TRY_TO_FAKE_THIS_ITEM(), which returns the tree itself when it's not
> > visible. But what sense does this make for the caller?
> Just to make filtering works.
> We're keeping array of "interesting fields", stored in tree->tree_data->interesting_hfids.
> In common case like this:
> foobar_tree = proto_tree_add_subtree_format(tree, ..., "Foobar");
> proto_tree_add_item(foobar_tree, hf_foobar_xyz, ...);
> proto_tree_add_item(foobar_tree, hf_foobar_aaa, ...);
> when foobar_tree == NULL, proto_tree_add_item() will fast return in if (!tree) check inside TRY_TO_FAKE_THIS_ITEM_OR_FREE
This case is ok, I understand that this makes things faster if we don't
have a tree.
I'm confused about this block in TRY_TO_FAKE_THIS_ITEM_OR_FREE
if (!(PTREE_DATA(tree)->visible)) { \
if (PTREE_FINFO(tree)) { \
if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) \
&& (hfinfo->type != FT_PROTOCOL || \
PTREE_DATA(tree)->fake_protocols)) { \
free_block; \
/* just return tree back to the caller */\
return tree; \
If tree is not visible (and fake_protocols is set, which seems to be the
default), we return the tree itself.
proto_item *it = proto_tree_add_text(tree, tvb, 0, -1, "foobar");
If tree!=NULL && !(PTREE_DATA(tree)->visible) the return value it==tree
Why does this make sense?
Regards,
Martin