Fix:Core:Replaced g_assert with dbg_assert
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 15 Oct 2008 18:39:03 +0000 (18:39 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 15 Oct 2008 18:39:03 +0000 (18:39 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1477 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/coord.c
navit/navit/debug.c
navit/navit/debug.h
navit/navit/file.c
navit/navit/map.c
navit/navit/route.c

index ba825e2..fc262bb 100644 (file)
@@ -68,8 +68,8 @@ coord_rect_new(struct coord *lu, struct coord *rl)
 {
        struct coord_rect *r=g_new(struct coord_rect, 1);
 
-       g_assert(lu->x <= rl->x);
-       g_assert(lu->y >= rl->y);
+       dbg_assert(lu->x <= rl->x);
+       dbg_assert(lu->y >= rl->y);
 
        r->lu=*lu;
        r->rl=*rl;
@@ -87,10 +87,10 @@ coord_rect_destroy(struct coord_rect *r)
 int 
 coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2)
 {
-       g_assert(r1->lu.x <= r1->rl.x);
-       g_assert(r1->lu.y >= r1->rl.y);
-       g_assert(r2->lu.x <= r2->rl.x);
-       g_assert(r2->lu.y >= r2->rl.y);
+       dbg_assert(r1->lu.x <= r1->rl.x);
+       dbg_assert(r1->lu.y >= r1->rl.y);
+       dbg_assert(r2->lu.x <= r2->rl.x);
+       dbg_assert(r2->lu.y >= r2->rl.y);
        dbg(1,"0x%x,0x%x - 0x%x,0x%x vs 0x%x,0x%x - 0x%x,0x%x\n", r1->lu.x, r1->lu.y, r1->rl.x, r1->rl.y, r2->lu.x, r2->lu.y, r2->rl.x, r2->rl.y);
        if (r1->lu.x > r2->rl.x)
                return 0;
@@ -106,8 +106,8 @@ coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2)
 int
 coord_rect_contains(struct coord_rect *r, struct coord *c)
 {
-       g_assert(r->lu.x <= r->rl.x);
-       g_assert(r->lu.y >= r->rl.y);
+       dbg_assert(r->lu.x <= r->rl.x);
+       dbg_assert(r->lu.y >= r->rl.y);
        if (c->x < r->lu.x)
                return 0;
        if (c->x > r->rl.x)
index 7c552d6..cfe1420 100644 (file)
@@ -106,4 +106,9 @@ debug_printf(int level, const char *module, const int mlen,const char *function,
        va_end(ap);
 }
 
-
+void
+debug_assert_fail(char *module, const int mlen,const char *function, const int flen, char *file, int line, char *expr)
+{
+       debug_printf(0,module,mlen,function,flen,1,"%s:%d assertion failed:%s\n", file, line, expr);
+       abort();
+}
index 4bb7d52..0d95123 100644 (file)
@@ -30,6 +30,7 @@ extern int debug_level;
 #define dbg_str1(x) dbg_str2(x)
 #define dbg_module dbg_str1(MODULE)
 #define dbg(level,fmt...) ({ if (debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,fmt); })
+#define dbg_assert(expr) ((expr) ? (void) 0 : debug_assert_fail(dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),__FILE__,__LINE__,dbg_str1(expr)))
 
 /* prototypes */
 void debug_init(const char *program_name);
@@ -37,6 +38,7 @@ void debug_level_set(const char *name, int level);
 int debug_level_get(const char *name);
 void debug_vprintf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap);
 void debug_printf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, ...);
+void debug_assert_fail(char *module, const int mlen,const char *function, const int flen, char *file, int line, char *expr);
 /* end of prototypes */
 
 #ifdef __cplusplus
index b95c418..ffe79f7 100644 (file)
@@ -72,7 +72,7 @@ file_create(char *name)
        fstat(file->fd, &stat);
        file->size=stat.st_size;
        file->name = g_strdup(name);
-       g_assert(file != NULL);
+       dbg_assert(file != NULL);
        file->next=file_list;
        file_list=file;
        return file;
@@ -122,13 +122,13 @@ file_mmap(struct file *file)
     file->begin = (char*)mmap_readonly_win32( file->name, &file->map_handle, &file->map_file );
 #else
        file->begin=mmap(NULL, file->size, PROT_READ|PROT_WRITE, MAP_PRIVATE, file->fd, 0);
-       g_assert(file->begin != NULL);
+       dbg_assert(file->begin != NULL);
        if (file->begin == (void *)0xffffffff) {
                perror("mmap");
                return 0;
        }
 #endif
-       g_assert(file->begin != (void *)0xffffffff);
+       dbg_assert(file->begin != (void *)0xffffffff);
        file->end=file->begin+file->size;
 
        return 1;
index dbb25e7..934da5f 100644 (file)
@@ -297,9 +297,9 @@ struct item *
 map_rect_get_item(struct map_rect *mr)
 {
        struct item *ret;
-       g_assert(mr != NULL);
-       g_assert(mr->m != NULL);
-       g_assert(mr->m->meth.map_rect_get_item != NULL);
+       dbg_assert(mr != NULL);
+       dbg_assert(mr->m != NULL);
+       dbg_assert(mr->m->meth.map_rect_get_item != NULL);
        ret=mr->m->meth.map_rect_get_item(mr->priv);
        if (ret)
                ret->map=mr->m;
@@ -318,8 +318,8 @@ struct item *
 map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
 {
        struct item *ret=NULL;
-       g_assert(mr != NULL);
-       g_assert(mr->m != NULL);
+       dbg_assert(mr != NULL);
+       dbg_assert(mr->m != NULL);
        if (mr->m->meth.map_rect_get_item_byid)
                ret=mr->m->meth.map_rect_get_item_byid(mr->priv, id_hi, id_lo);
        if (ret)
index cfe4f07..1a465f3 100644 (file)
@@ -748,7 +748,7 @@ route_graph_add_segment(struct route_graph *this, struct route_graph_point *star
        s->end=end;
        s->end_next=end->end;
        end->end=s;
-       g_assert(len >= 0);
+       dbg_assert(len >= 0);
        s->len=len;
        s->item=*item;
        s->flags=flags;
@@ -1028,7 +1028,7 @@ route_value(int *speedlist, struct item *item, int len)
        if (len < 0) {
                printf("len=%d\n", len);
        }
-       g_assert(len >= 0);
+       dbg_assert(len >= 0);
        ret=route_time(speedlist, item, len);
        dbg(1, "route_value(0x%x, %d)=%d\n", item->type, len, ret);
        return ret;
@@ -1071,7 +1071,7 @@ route_process_street_graph(struct route_graph *this, struct item *item)
                                l=c;
                        }
                        e_pnt=route_graph_add_point(this,&l);
-                       g_assert(len >= 0);
+                       dbg_assert(len >= 0);
                        route_graph_add_segment(this, s_pnt, e_pnt, len, item, flags, offset);
                } else {
                        int isseg,rc;
@@ -1092,7 +1092,7 @@ route_process_street_graph(struct route_graph *this, struct item *item)
                                }
                        } while(rc);
                        e_pnt=route_graph_add_point(this,&l);
-                       g_assert(len >= 0);
+                       dbg_assert(len >= 0);
                        sc++;
                        route_graph_add_segment(this, s_pnt, e_pnt, len, item, flags, offset);
                }
@@ -1145,14 +1145,14 @@ route_graph_flood(struct route_graph *this, struct route_info *dst, int *speedli
 
        if (! (sd->flags & AF_ONEWAYREV)) { /* If we may drive in the direction of the coordinates of the item, the first coordinate is one starting point */
                end=route_graph_get_point(this, &sd->c[0]);
-               g_assert(end != 0);
+               dbg_assert(end != 0);
                end->value=route_value(speedlist, &sd->item, dst->lenneg);
                end->el=fh_insert(heap, end);
        }
 
        if (! (sd->flags & AF_ONEWAY)) { /* If we may drive against the direction of the coordinates, the last coordinate is another starting point */
                end=route_graph_get_point(this, &sd->c[sd->count-1]);
-               g_assert(end != 0);
+               dbg_assert(end != 0);
                end->value=route_value(speedlist, &sd->item, dst->lenpos);
                end->el=fh_insert(heap, end);
        }
@@ -1619,7 +1619,7 @@ street_get_data (struct item *item)
                if (item_attr_get(item, attr_debug, &attr)) 
                        dbg(0,"debug='%s'\n", attr.u.str);
        }
-       g_assert(count < maxcount);
+       dbg_assert(count < maxcount);
        ret=g_malloc(sizeof(struct street_data)+count*sizeof(struct coord));
        ret->item=*item;
        ret->count=count;