Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated code broken for Data type with empty string as default #23

Open
assaf758 opened this issue Oct 18, 2017 · 1 comment
Open

Comments

@assaf758
Copy link

The generated .c file for the below capnp does not compile due to undeclared capn_buf:

$ cat Test.capnp.c                 
#include "Test.capnp.h"            
/* AUTO GENERATED - DO NOT EDIT */ 
#ifdef __GNUC__                    
# define capnp_unused __attribute__((unused))                                                                                                 
# define capnp_use(x) (void) x;    
#else                              
# define capnp_unused              
# define capnp_use(x)              
#endif                             
                                                                       
static const capn_ptr capn_null = {CAPN_NULL};                         
static capn_data capn_val1 = {{2,0,0,0,1,0,0,(char*)&capn_buf[0],(struct capn_segment*)&capn_seg}};                                           
...

File Test.capnp:

@0xa4ba9dce9642ee58;

struct Record {
   info     @0: Data = "";
}

struct RootStruct {
   myList   @0: List(Record);
}
@assaf758 assaf758 changed the title generated code broken for Data struct with empty string as default generated code broken for Data type with empty string as default Oct 18, 2017
@assaf758
Copy link
Author

this seems to fix it for me, not sure its the right approach

@@ -1026,7 +1026,11 @@ capn_ptr capn_new_list(struct capn_segment *seg, int sz, int datasz, int ptrs) {                                      
                new_object(&p, p.len * 4);                            
        } else {                   
                p.datasz = datasz; 
-               new_object(&p, p.len * datasz);                       
+               if (p.len > 0) {   
+                       new_object(&p, p.len * datasz);               
+               } else {           
+                       new_object(&p, 1);                            
+               }                  
        }                          
                                   
        return p;                  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant