opensourcerouting / c-capnproto

C library/compiler for the Cap'n Proto serialization/RPC protocol
MIT License
118 stars 40 forks source link

Field Accessors Bug ( I think)! #25

Open laithsakka opened 6 years ago

laithsakka commented 6 years ago

Hi , I was trying to use the plugin and I encountered what I think is a bug, please let me know if my understanding is wrong about how the generated API works. The schema definitions that I used is the following:

struct Leaf{
        value @0 : Int32;
}
struct Inner {
        left @0  :TreeNode;
        right @1 : TreeNode;
}
struct TreeNode {
  nodeType @0 :Int32;
  leaf  @1 : Leaf;
  inner @2 :Inner;

}

For the following code I expect 1 to be printed but 0 is printed instead ;It looks like there is something wrong in the method Tree_Node_set_leaf(...) unless I misunderstand how it should work!

   struct capn c;
   struct capn_segment *cs;
   capn_ptr cr;

    capn_init_malloc(&c);
    cr = capn_root(&c);
    cs = cr.seg;

   TreeNode_ptr n = new_TreeNode(cs);
   TreeNode_set_nodeType(n, 1);
   Leaf_ptr l = new_Leaf(cs);
   Leaf_set_value(l , 1);
   TreeNode_set_leaf(n, l);
    cout<<Leaf_get_value(TreeNode_get_leaf(n))<<endl;
eqvinox commented 6 years ago

Hrm, yes, the problem seems to be that TreeNode_set_leaf sets up an unresolved pointer and TreeNode_get_leaf doesn't resolve it (3rd argument to capn_getp is 0...)