compile and runtime fixes
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 1 Dec 2005 18:44:50 +0000 (18:44 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 1 Dec 2005 18:44:50 +0000 (18:44 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@1349 04897980-b3bd-0310-b5e0-8ef037075253

genevent-new/genevent.c
genevent-new/parser.c
genevent-new/parser.h
genevent-new/test.xml

index 4042dafafdeda23986643873853d0e60e71b8c3b..15518d80507f4c592d38f9b350cd5f9b0e277e4b 100644 (file)
 #define dprintf(...)
 #endif
 
-void preset_field_type_size(event_t *event_type,
-    off_t offset_root, off_t offset_parent,
-    enum field_status *fixed_root, enum field_status *fixed_parent,
-    field_t *field);
-
 /* Code printing */
 
 void print_tabs(unsigned int tabs, FILE *fd)
@@ -99,11 +94,6 @@ void print_tabs(unsigned int tabs, FILE *fd)
                fprintf(fd, "\t");
 }
 
-/* Type size checking */
-/* Uses #error in the generated code to signal error and stop the compiler */
-int print_check(int fd);
-
-
 /* print type.
  *
  * Copied from construct_types_and_fields in LTTV facility.c */
@@ -372,9 +362,14 @@ int has_type_fixed_size(type_descriptor_t *td)
                        break;
                case ARRAY:
                        assert(td->size >= 0);
-                       return has_type_fixed(((field_t*)td->fields.array[0])->type);
+                       return has_type_fixed_size(((field_t*)td->fields.array[0])->type);
+                       break;
+               case NONE:
+                       printf("There is a type defined to NONE : bad.\n");
+                       assert(0);
                        break;
        }
+       return 0; //make gcc happy.
 }
 
 
@@ -431,7 +426,7 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                                if(print_type_declaration(((field_t*)td->fields.array[0])->type,
                                                                                                                                        fd,     0, basename, "")) return 1;
                        }
-                       fprintf(fd, "#define LTTNG_ARRAY_SIZE_%s %llu\n", basename,
+                       fprintf(fd, "#define LTTNG_ARRAY_SIZE_%s %zu\n", basename,
                                        td->size);
                        fprintf(fd, "typedef ");
                        if(print_type(((field_t*)td->fields.array[0])->type,
@@ -573,8 +568,7 @@ int print_type_alignment(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                case OFF_T:
                case ENUM:
                        fprintf(fd, "sizeof(");
-                       if(print_type(td->type,
-                                               fd, 0, basename, "")) return 1;
+                       if(print_type(td, fd, 0, basename, "")) return 1;
                        fprintf(fd, ")");
                        break;
                case STRING:
@@ -596,6 +590,10 @@ int print_type_alignment(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                        fprintf(fd, "lttng_get_alignment_array_%s(obj->%s)", basename,
                                        field_name);
                        break;
+               case NONE:
+                       printf("error : type NONE unexpected\n");
+                       return 1;
+                       break;
        }
 
        return 0;
@@ -653,8 +651,7 @@ int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                        print_tabs(tabs, fd);
                        fprintf(fd, "size = ");
                        fprintf(fd, "sizeof(");
-                       if(print_type(td->type,
-                                               fd, 0, basename, "")) return 1;
+                       if(print_type(td, fd, 0, basename, "")) return 1;
                        fprintf(fd, ");\n");
                        print_tabs(tabs, fd);
                        fprintf(fd, "size += ltt_align(*to+*len, size) + size;");
@@ -663,7 +660,7 @@ int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                        break;
                case STRING:
                        print_tabs(tabs, fd);
-                       fprintf(fd, "lttng_write_string_%s(buffer, to_base, to, from, len, obj->%s);\n");
+                       fprintf(fd, "lttng_write_string_%s(buffer, to_base, to, from, len, obj->%s);\n", basename, field_name);
                        break;
                case SEQUENCE:
                        print_tabs(tabs, fd);
@@ -685,6 +682,10 @@ int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                        fprintf(fd, "lttng_write_array_%s(buffer, to_base, to, from, len, obj->%s)", basename,
                                        field_name);
                        break;
+               case NONE:
+                       printf("Error : type NONE unexpected\n");
+                       return 1;
+                       break;
        }
 
        return 0;
@@ -731,7 +732,7 @@ int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
                        fprintf(fd, "static inline size_t lttng_get_alignment_sequence_%s(\n",
                                        basename);
                        print_tabs(2, fd);
-                       if(print_type(td->type, fd, 0, basename, "")) return 1;
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
                        fprintf(fd, " *obj)\n");
                        fprintf(fd, "{\n");
                        print_tabs(1, fd);
@@ -740,7 +741,7 @@ int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
                        print_tabs(1, fd);
                        fprintf(fd, "localign = ");
                        if(print_type_alignment(((field_t*)td->fields.array[0])->type,
-                                               fd, 0, basename, field->name)) return 1;
+                                               fd, 0, basename, ((field_t*)td->fields.array[0])->name)) return 1;
                        fprintf(fd, ";\n");
                        print_tabs(1, fd);
                        fprintf(fd, "align = max(align, localign);\n");
@@ -748,7 +749,7 @@ int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
                        print_tabs(1, fd);
                        fprintf(fd, "localign = ");
                        if(print_type_alignment(((field_t*)td->fields.array[1])->type,
-                                               fd, 0, basename, field->name)) return 1;
+                                               fd, 0, basename, ((field_t*)td->fields.array[1])->name)) return 1;
                        fprintf(fd, ";\n");
                        print_tabs(1, fd);
                        fprintf(fd, "align = max(align, localign);\n");
@@ -761,7 +762,7 @@ int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
                        fprintf(fd, "static inline size_t lttng_get_alignment_struct_%s(\n",
                                        basename);
                        print_tabs(2, fd);
-                       if(print_type(td->type, fd, 0, basename, "")) return 1;
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
                        fprintf(fd, " *obj)\n");
                        fprintf(fd, "{\n");
                        print_tabs(1, fd);
@@ -787,7 +788,7 @@ int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
                        fprintf(fd, "static inline size_t lttng_get_alignment_union_%s(\n",
                                        basename);
                        print_tabs(2, fd);
-                       if(print_type(td->type, fd, 0, basename, "")) return 1;
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
                        fprintf(fd, " *obj)\n");
                        fprintf(fd, "{\n");
                        print_tabs(1, fd);
@@ -813,13 +814,13 @@ int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
                        fprintf(fd, "static inline size_t lttng_get_alignment_array_%s(\n",
                                        basename);
                        print_tabs(2, fd);
-                       if(print_type(td->type, fd, 0, basename, "")) return 1;
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
                        fprintf(fd, " obj)\n");
                        fprintf(fd, "{\n");
                        print_tabs(1, fd);
                        fprintf(fd, "return \n");
                        if(print_type_alignment(((field_t*)td->fields.array[0])->type,
-                                               fd, 0, basename, field->name)) return 1;
+                                               fd, 0, basename, ((field_t*)td->fields.array[0])->name)) return 1;
                        fprintf(fd, ";\n");
                        break;
                default:
@@ -832,6 +833,7 @@ int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
        fprintf(fd, "}\n");
        fprintf(fd, "\n");
 
+       return 0;
 }
 
 /* print type write function.
@@ -903,7 +905,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
        print_tabs(2, fd);
        fprintf(fd, "size_t *len,\n");
        print_tabs(2, fd);
-       if(print_type(td->type, fd, 0, basename, "")) return 1;
+       if(print_type(td,       fd, 0, basename, "")) return 1;
 
        switch(td->type) {
                case SEQUENCE:
@@ -958,7 +960,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
        
        print_tabs(1, fd);
        fprintf(fd, "align = \n");
-       if(print_type_alignment(td, fd, 0, basename, field->name)) return 1;
+       if(print_type_alignment(td, fd, 0, basename, field_name)) return 1;
        fprintf(fd, ";\n");
        fprintf(fd, "\n");
        print_tabs(1, fd);
@@ -981,7 +983,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                fprintf(fd, "\n");
                print_tabs(1, fd);
                fprintf(fd, "*len += sizeof(");
-               if(print_type(td, fd, 0, basename, field->name)) return 1;
+               if(print_type(td, fd, 0, basename, field_name)) return 1;
                fprintf(fd, ");\n");
        } else {
                /* The type contains nested variable size subtypes :
@@ -997,7 +999,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                                print_tabs(1, fd);
                                fprintf(fd, "size = sizeof(\n");
                                if(print_type_write(((field_t*)td->fields.array[0])->type,
-                                               fd, 1, basename, field->name)) return 1;
+                                               fd, 1, basename, ((field_t*)td->fields.array[0])->name)) return 1;
                                fprintf(fd, ");\n");
                                print_tabs(1, fd);
                                fprintf(fd, "*to += ltt_align(*to, size);\n");
@@ -1015,7 +1017,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                                        print_tabs(1, fd);
                                        fprintf(fd, "size = sizeof(\n");
                                        if(print_type_write(((field_t*)td->fields.array[1])->type,
-                                                       fd, 1, basename, field->name)) return 1;
+                                                       fd, 1, basename, ((field_t*)td->fields.array[1])->name)) return 1;
                                        fprintf(fd, ");\n");
                                        print_tabs(1, fd);
                                        fprintf(fd, "*to += ltt_align(*to, size);\n");
@@ -1034,7 +1036,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                                        print_tabs(1, fd);
                                        fprintf(fd, "for(unsigned int i=0; i<obj->len; i++) {\n");
                                        if(print_type_write(((field_t*)td->fields.array[1])->type,
-                                                       fd, 2, basename, field->name)) return 1;
+                                                       fd, 2, basename, ((field_t*)td->fields.array[1])->name)) return 1;
                                        print_tabs(1, fd);
                                        fprintf(fd, "}\n");
                                }
@@ -1099,7 +1101,7 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
                                        print_tabs(1, fd);
                                        fprintf(fd, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename);
                                        if(print_type_write(((field_t*)td->fields.array[1])->type,
-                                                       fd, 2, basename, field->name)) return 1;
+                                                       fd, 2, basename, ((field_t*)td->fields.array[1])->name)) return 1;
                                        print_tabs(1, fd);
                                        fprintf(fd, "}\n");
                                }
@@ -1193,7 +1195,7 @@ int print_event_logging_function(char *basename, facility_t *fac,
        fprintf(fd, "\n");
 
        for(unsigned int i=0;i<event->fields.position;i++){
-               field_t *field = (field_t*)(td->fields.array[i]);
+               field_t *field = (field_t*)(event->fields.array[i]);
                type_descriptor_t *type = field->type;
                if(print_type_write(type,
                                fd, 1, basename, field->name)) return 1;
@@ -1234,7 +1236,7 @@ int print_event_logging_function(char *basename, facility_t *fac,
        }
  
        print_tabs(2, fd);
-       fprintf(fp, "channel = ltt_get_channel_from_index(trace, index);\n");
+       fprintf(fd, "channel = ltt_get_channel_from_index(trace, index);\n");
        print_tabs(2, fd);
        fprintf(fd, "relayfs_buf = channel->rchan->buf[channel->rchan->buf->cpu];\n");
        fprintf(fd, "\n");
@@ -1255,12 +1257,12 @@ int print_event_logging_function(char *basename, facility_t *fac,
        /* write data : assume stack alignment is the same as struct alignment. */
 
        for(unsigned int i=0;i<event->fields.position;i++){
-               field_t *field = (field_t*)(td->fields.array[i]);
+               field_t *field = (field_t*)(event->fields.array[i]);
                type_descriptor_t *type = field->type;
 
                /* Set from */
                print_tabs(3, fd);
-               fprintf(fd, "from = %s;\n", f->name);
+               fprintf(fd, "from = %s;\n", field->name);
 
                if(print_type_write(type,
                                fd, 2, basename, field->name)) return 1;
@@ -1536,7 +1538,6 @@ facility_t *ltt_facility_open(char * pathname)
        char *token;
        parse_file_t in;
        facility_t * fac = NULL;
-       unsigned long checksum;
        char buffer[BUFFER_SIZE];
        int generated = FALSE;
 
@@ -1577,7 +1578,7 @@ facility_t *ltt_facility_open(char * pathname)
                        //check if any namedType is not defined
                        checkNamedTypesImplemented(&fac->named_types);
                
-                       generateChecksum(fac->name, &checksum, &fac->events);
+                       generateChecksum(fac->name, &fac->checksum, &fac->events);
                        
                        generated = TRUE;
                }
index e5e64ab17d0564bcca8a18b0291f425370bceb7a..1b746c309b8af8cb22b2d62887dac0b692df55a1 100644 (file)
@@ -558,11 +558,6 @@ void parseFields(parse_file_t *in, field_t *f,
   getLAnglebracket(in);
   f->type = parseType(in,NULL, unnamed_types, named_types);
 
-       /* Those will be set later by preset_field_type_size */
-       f->fixed_root = FIELD_UNKNOWN;
-       f->fixed_parent = FIELD_UNKNOWN;
-       f->fixed_size = FIELD_UNKNOWN;
-
        if(tag) {
                getLAnglebracket(in);
                getForwardslash(in);
@@ -665,7 +660,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
     getForwardslash(in);
     getRAnglebracket(in); //<array size=n>
 
-    getLAnglebracket(in); //<subtype> 
+    //getLAnglebracket(in); //<subtype> 
                /* subfield */
                f = (field_t *)memAlloc(sizeof(field_t));
                sequence_push(&(t->fields),f);
@@ -687,13 +682,13 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
     //getForwardslash(in);
     getRAnglebracket(in); //<sequence>
 
-    getLAnglebracket(in); //<sequence size type> 
+    //getLAnglebracket(in); //<sequence size type> 
                /* subfield */
                f = (field_t *)memAlloc(sizeof(field_t));
                sequence_push(&(t->fields),f);
     parseFields(in, f, unnamed_types, named_types, 0);
 
-    getLAnglebracket(in); //<subtype> 
+    //getLAnglebracket(in); //<subtype> 
                /* subfield */
                f = (field_t *)memAlloc(sizeof(field_t));
                sequence_push(&(t->fields),f);
@@ -1337,12 +1332,12 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type)
       flag = 1;
       break;
     case ARRAY:
-      sprintf(buf,"%llu", type->size);
+      sprintf(buf,"%zu", type->size);
       str = appendString("array ",buf);
       flag = 1;
       break;
     case SEQUENCE:
-      sprintf(buf,"%llu", type->size);
+      sprintf(buf,"%zu", type->size);
       str = appendString("sequence ",buf);
       flag = 1;
       break;
@@ -1364,9 +1359,12 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type)
 
   if(type->fmt) crc = partial_crc32(type->fmt,crc);
     
-  if(type->type == ARRAY || type->type == SEQUENCE){
-    crc = getTypeChecksum(crc,type->nested_type);
-  }else if(type->type == STRUCT || type->type == UNION){
+  if(type->type == ARRAY){
+    crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
+  } else if(type->type ==SEQUENCE) {
+    crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
+    crc = getTypeChecksum(crc,((field_t*)type->fields.array[1])->type);
+       } else if(type->type == STRUCT || type->type == UNION){
     for(pos =0; pos < type->fields.position; pos++){
       fld = (field_t *) type->fields.array[pos];
       crc = partial_crc32(fld->name,crc);
index edcaeb041352afda280dd588ea77795b61c5ed00..45d7f801849dee35cbb87f35b20642d4c1046f39 100644 (file)
@@ -141,6 +141,7 @@ typedef struct _facility {
   sequence_t events;
   sequence_t unnamed_types;
   table_t named_types;
+       unsigned long checksum;
 } facility_t;
 
 int getSizeindex(unsigned int value);
@@ -155,7 +156,9 @@ void parseTypeDefinition(parse_file_t *in,
 type_descriptor_t *parseType(parse_file_t *in,
     type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
 void parseFields(parse_file_t *in, field_t *f,
-    sequence_t * unnamed_types, table_t * named_types);
+    sequence_t * unnamed_types,
+               table_t * named_types,
+               int tag);
 void checkNamedTypesImplemented(table_t * namedTypes);
 type_descriptor_t * find_named_type(char *name, table_t * named_types);
 void generateChecksum(char * facName,
index 6a328bdd1057610c94601e2d8b138acb62e2b418..343c4625324a766969b3599f24ca889bb008b7f9 100644 (file)
@@ -56,8 +56,9 @@
   </event>
 
        <event name=big_array>
-       <field name="myarray"><array size=10000>
-                       <array size = 2>
+       <field name="myarray">
+               <array size=10000>
+                       <array size=2>
                                <struct>
                                        <field name=a><pointer></field>
                                        <field name=b><union>
@@ -65,7 +66,9 @@
                                                                                                </union>
                                        </field>
                                </struct>
-                       </array></array></field>
+                       </array>
+               </array>
+       </field>
        </event>
 
   <type name=tasklet_priority>
This page took 0.032497 seconds and 4 git commands to generate.