From ff6000745886cb085ca80e42498020497bc7f95f Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 3 Apr 2011 22:23:14 +0000 Subject: Fix build with NDEBUG defined svn path=/trunk/netsurf/; revision=12154 --- desktop/knockout.c | 9 +++-- desktop/textinput.c | 11 ++++-- render/box_normalise.c | 31 +++++++++++++++-- render/layout.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++-- render/table.c | 7 ++-- utils/log.c | 13 +++++--- utils/log.h | 9 +++-- utils/utils.c | 3 -- 8 files changed, 152 insertions(+), 22 deletions(-) diff --git a/desktop/knockout.c b/desktop/knockout.c index 3525df972..5d0ecbc2a 100644 --- a/desktop/knockout.c +++ b/desktop/knockout.c @@ -67,9 +67,10 @@ #include "desktop/knockout.h" #include "desktop/plotters.h" #include "image/bitmap.h" -#define NDEBUG #include "utils/log.h" -#undef NDEBUG + +/* Define to enable knockout debug */ +#undef KNOCKOUT_DEBUG #define KNOCKOUT_ENTRIES 3072 /* 40 bytes each */ #define KNOCKOUT_BOXES 768 /* 28 bytes each */ @@ -278,10 +279,12 @@ bool knockout_plot_flush(void) struct knockout_box *box; /* debugging information */ +#ifdef KNOCKOUT_DEBUG LOG(("Entries are %i/%i, %i/%i, %i/%i", knockout_entry_cur, KNOCKOUT_ENTRIES, knockout_box_cur, KNOCKOUT_BOXES, knockout_polygon_cur, KNOCKOUT_POLYGONS)); +#endif /* release our plotter */ plot = real_plot; @@ -690,8 +693,10 @@ bool knockout_plot_path(const float *p, unsigned int n, colour fill, bool knockout_plot_clip(const struct rect *clip) { if (clip->x1 < clip->x0 || clip->y0 > clip->y1) { +#ifdef KNOCKOUT_DEBUG LOG(("bad clip rectangle %i %i %i %i", clip->x0, clip->y0, clip->x1, clip->y1)); +#endif return false; } diff --git a/desktop/textinput.c b/desktop/textinput.c index 55b81b053..920d8fa99 100644 --- a/desktop/textinput.c +++ b/desktop/textinput.c @@ -38,13 +38,14 @@ #include "render/font.h" #include "render/form.h" #include "render/layout.h" -#define NDEBUG #include "utils/log.h" -#undef NDEBUG #include "utils/talloc.h" #include "utils/utf8.h" #include "utils/utils.h" +/* Define to enable textinput debug */ +#undef TEXTINPUT_DEBUG + /** ghost caret used to indicate the insertion point when dragging text into a textarea/input field */ struct caret ghost_caret; @@ -335,8 +336,10 @@ bool browser_window_textarea_callback(struct browser_window *bw, plot_font_style_t fstyle; /* box_dump(textarea, 0); */ +#ifdef TEXTINPUT_DEBUG LOG(("key %i at %i in '%.*s'", key, char_offset, (int) text_box->length, text_box->text)); +#endif box_coords(textarea, &box_x, &box_y); box_x -= scroll_get_offset(textarea->scroll_x); @@ -1380,9 +1383,11 @@ bool browser_window_textarea_paste_text(struct browser_window *bw, while ((char_offset > text_box->length + SPACE_LEN(text_box)) && (text_box->next) && (text_box->next->type == BOX_TEXT)) { +#ifdef TEXTINPUT_DEBUG LOG(("Caret out of range: Was %d in boxlen %d " "space %d", char_offset, text_box->length, SPACE_LEN(text_box))); +#endif char_offset -= text_box->length + SPACE_LEN(text_box); text_box = text_box->next; } @@ -1390,9 +1395,11 @@ bool browser_window_textarea_paste_text(struct browser_window *bw, /* not sure if this will happen or not... * but won't stick an assert here as we can recover from it */ if (char_offset > text_box->length) { +#ifdef TEXTINPUT_DEBUG LOG(("Caret moved beyond end of line: " "Was %d in boxlen %d", char_offset, text_box->length)); +#endif char_offset = text_box->length; } diff --git a/render/box_normalise.c b/render/box_normalise.c index b4c005c8e..21ede6dd4 100644 --- a/render/box_normalise.c +++ b/render/box_normalise.c @@ -30,11 +30,11 @@ #include "render/box.h" #include "render/table.h" #include "desktop/gui.h" -#define NDEBUG #include "utils/log.h" -#undef NDEBUG #include "utils/talloc.h" +/* Define to enable box normalise debug */ +#undef BOX_NORMALISE_DEBUG /** * Row spanning information for a cell @@ -105,7 +105,9 @@ bool box_normalise_block(struct box *block, struct content *c) assert(block != NULL); +#ifdef BOX_NORMALISE_DEBUG LOG(("block %p, block->type %u", block, block->type)); +#endif assert(block->type == BOX_BLOCK || block->type == BOX_INLINE_BLOCK || block->type == BOX_TABLE_CELL); @@ -113,7 +115,9 @@ bool box_normalise_block(struct box *block, struct content *c) gui_multitask(); for (child = block->children; child != NULL; child = next_child) { +#ifdef BOX_NORMALISE_DEBUG LOG(("child %p, child->type = %d", child, child->type)); +#endif next_child = child->next; /* child may be destroyed */ @@ -210,7 +214,9 @@ bool box_normalise_table(struct box *table, struct content * c) assert(table != NULL); assert(table->type == BOX_TABLE); +#ifdef BOX_NORMALISE_DEBUG LOG(("table %p", table)); +#endif col_info.num_columns = 1; col_info.current_column = 0; @@ -318,7 +324,9 @@ bool box_normalise_table(struct box *table, struct content * c) if (table->children == NULL) { struct box *row; +#ifdef BOX_NORMALISE_DEBUG LOG(("table->children == 0, creating implied row")); +#endif assert(table->style != NULL); @@ -375,7 +383,9 @@ bool box_normalise_table(struct box *table, struct content * c) if (table_calculate_column_types(table) == false) return false; +#ifdef BOX_NORMALISE_DEBUG LOG(("table %p done", table)); +#endif return true; } @@ -531,7 +541,9 @@ bool box_normalise_table_row_group(struct box *row_group, assert(row_group != 0); assert(row_group->type == BOX_TABLE_ROW_GROUP); +#ifdef BOX_NORMALISE_DEBUG LOG(("row_group %p", row_group)); +#endif for (child = row_group->children; child != NULL; child = next_child) { next_child = child->next; @@ -615,7 +627,9 @@ bool box_normalise_table_row_group(struct box *row_group, } if (row_group->children == NULL) { +#ifdef BOX_NORMALISE_DEBUG LOG(("row_group->children == 0, inserting implied row")); +#endif assert(row_group->style != NULL); @@ -640,7 +654,9 @@ bool box_normalise_table_row_group(struct box *row_group, col_info->num_rows++; } +#ifdef BOX_NORMALISE_DEBUG LOG(("row_group %p done", row_group)); +#endif return true; } @@ -658,7 +674,10 @@ bool box_normalise_table_row(struct box *row, assert(row != NULL); assert(row->type == BOX_TABLE_ROW); + +#ifdef BOX_NORMALISE_DEBUG LOG(("row %p", row)); +#endif for (child = row->children; child != NULL; child = next_child) { next_child = child->next; @@ -761,7 +780,9 @@ bool box_normalise_table_row(struct box *row, /* Increment row counter */ col_info->num_rows++; +#ifdef BOX_NORMALISE_DEBUG LOG(("row %p done", row)); +#endif return true; } @@ -842,7 +863,10 @@ bool box_normalise_inline_container(struct box *cont, struct content * c) assert(cont != NULL); assert(cont->type == BOX_INLINE_CONTAINER); + +#ifdef BOX_NORMALISE_DEBUG LOG(("cont %p", cont)); +#endif for (child = cont->children; child != NULL; child = next_child) { next_child = child->next; @@ -902,7 +926,10 @@ bool box_normalise_inline_container(struct box *cont, struct content * c) assert(0); } } + +#ifdef BOX_NORMALISE_DEBUG LOG(("cont %p done", cont)); +#endif return true; } diff --git a/render/layout.c b/render/layout.c index 2270bdfd8..d99fa0056 100644 --- a/render/layout.c +++ b/render/layout.c @@ -51,13 +51,14 @@ #include "render/form.h" #include "render/layout.h" #include "render/table.h" -#define NDEBUG #include "utils/log.h" -#undef NDEBUG #include "utils/talloc.h" #include "utils/utils.h" +/* Define to enable layout debugging */ +#undef LAYOUT_DEBUG + #define AUTO INT_MIN /* Fixed point value percentage of an integer, to an integer */ @@ -489,7 +490,9 @@ bool layout_block_context(struct box *block, int viewport_height, max_pos_margin = max_neg_margin = 0; } +#ifdef LAYOUT_DEBUG LOG(("box %p, cx %i, cy %i", box, cx, cy)); +#endif /* Layout (except tables). */ if (box->object) { @@ -836,8 +839,10 @@ bool layout_block_object(struct box *block) block->type == BOX_TABLE_CELL); assert(block->object); +#ifdef LAYOUT_DEBUG LOG(("block %p, object %s, width %i", block, content_get_url(block->object), block->width)); +#endif if (content_get_type(block->object) == CONTENT_HTML) { content_reformat(block->object, block->width, 1); @@ -1756,7 +1761,11 @@ void find_sides(struct box *fl, int y0, int y1, int *x0, int *x1, struct box **left, struct box **right) { int fy0, fy1, fx0, fx1; + +#ifdef LAYOUT_DEBUG LOG(("y0 %i, y1 %i, x0 %i, x1 %i", y0, y1, *x0, *x1)); +#endif + *left = *right = 0; for (; fl; fl = fl->next_float) { fy0 = fl->y; @@ -1777,7 +1786,10 @@ void find_sides(struct box *fl, int y0, int y1, } } } + +#ifdef LAYOUT_DEBUG LOG(("x0 %i, x1 %i, left %p, right %p", *x0, *x1, *left, *right)); +#endif } @@ -1804,8 +1816,10 @@ bool layout_inline_container(struct box *inline_container, int width, assert(inline_container->type == BOX_INLINE_CONTAINER); +#ifdef LAYOUT_DEBUG LOG(("inline_container %p, width %i, cont %p, cx %i, cy %i", inline_container, width, cont, cx, cy)); +#endif has_text_children = false; for (c = inline_container->children; c; c = c->next) { @@ -1831,7 +1845,9 @@ bool layout_inline_container(struct box *inline_container, int width, * curwidth = width and have the multiword lines wrap to the min width) */ for (c = inline_container->children; c; ) { +#ifdef LAYOUT_DEBUG LOG(("c %p", c)); +#endif curwidth = inline_container->width; if (!layout_line(c, &curwidth, &y, cx, cy + y, cont, first_line, has_text_children, content, &next)) @@ -2049,9 +2065,11 @@ bool layout_line(struct box *first, int *width, int *y, const struct font_functions *font_func = content->data.html.font_func; plot_font_style_t fstyle; +#ifdef LAYOUT_DEBUG LOG(("first %p, first->text '%.*s', width %i, y %i, cx %i, cy %i", first, (int) first->length, first->text, *width, *y, cx, cy)); +#endif /* find sides at top of line */ x0 += cx; @@ -2080,7 +2098,10 @@ bool layout_line(struct box *first, int *width, int *y, /* pass 1: find height of line assuming sides at top of line: loop * body executed at least once * keep in sync with the loop in layout_minmax_line() */ +#ifdef LAYOUT_DEBUG LOG(("x0 %i, x1 %i, x1 - x0 %i", x0, x1, x1 - x0)); +#endif + for (x = 0, b = first; x <= x1 - x0 && b != 0; b = b->next) { enum css_width_e wtype; enum css_height_e htype; @@ -2092,7 +2113,10 @@ bool layout_line(struct box *first, int *width, int *y, b->type == BOX_FLOAT_RIGHT || b->type == BOX_BR || b->type == BOX_TEXT || b->type == BOX_INLINE_END); + +#ifdef LAYOUT_DEBUG LOG(("pass 1: b %p, x %i", b, x)); +#endif if (b->type == BOX_BR) break; @@ -2305,9 +2329,15 @@ bool layout_line(struct box *first, int *width, int *y, space_after = space_before = 0; /* pass 2: place boxes in line: loop body executed at least once */ +#ifdef LAYOUT_DEBUG LOG(("x0 %i, x1 %i, x1 - x0 %i", x0, x1, x1 - x0)); +#endif + for (x = x_previous = 0, b = first; x <= x1 - x0 && b; b = b->next) { +#ifdef LAYOUT_DEBUG LOG(("pass 2: b %p, x %i", b, x)); +#endif + if (b->type == BOX_INLINE_BLOCK && (css_computed_position(b->style) == CSS_POSITION_ABSOLUTE || @@ -2373,15 +2403,22 @@ bool layout_line(struct box *first, int *width, int *y, } else { /* float */ +#ifdef LAYOUT_DEBUG LOG(("float %p", b)); +#endif + d = b->children; d->float_children = 0; b->float_container = d->float_container = cont; if (!layout_float(d, *width, content)) return false; + +#ifdef LAYOUT_DEBUG LOG(("%p : %d %d", d, d->margin[TOP], d->border[TOP].width)); +#endif + d->x = d->margin[LEFT] + d->border[LEFT].width; d->y = d->margin[TOP] + d->border[TOP].width; b->width = d->margin[LEFT] + d->border[LEFT].width + @@ -2468,7 +2505,10 @@ bool layout_line(struct box *first, int *width, int *y, right = b; } if (cont->float_children == b) { +#ifdef LAYOUT_DEBUG LOG(("float %p already placed", b)); +#endif + box_dump(stderr, cont, 0); assert(0); } @@ -2514,11 +2554,13 @@ bool layout_line(struct box *first, int *width, int *y, space, &w); } +#ifdef LAYOUT_DEBUG LOG(("splitting: split_box %p \"%.*s\", space %zu, w %i, " "left %p, right %p, inline_count %u", split_box, (int) split_box->length, split_box->text, space, w, left, right, inline_count)); +#endif if ((space == 0 || x1 - x0 <= x + space_before + w) && !left && !right && inline_count == 1) { @@ -2535,7 +2577,9 @@ bool layout_line(struct box *first, int *width, int *y, b = split_box->next; } x += space_before + w; +#ifdef LAYOUT_DEBUG LOG(("forcing")); +#endif } else if ((space == 0 || x1 - x0 <= x + space_before + w) && inline_count == 1) { /* first word of first box doesn't fit, but a float is @@ -2543,22 +2587,30 @@ bool layout_line(struct box *first, int *width, int *y, assert(left || right); used_height = 0; if (left) { +#ifdef LAYOUT_DEBUG LOG(("cy %i, left->y %i, left->height %i", cy, left->y, left->height)); +#endif used_height = left->y + left->height - cy + 1; +#ifdef LAYOUT_DEBUG LOG(("used_height %i", used_height)); +#endif } if (right && used_height < right->y + right->height - cy + 1) used_height = right->y + right->height - cy + 1; assert(0 < used_height); b = split_box; +#ifdef LAYOUT_DEBUG LOG(("moving below float")); +#endif } else if (space == 0 || x1 - x0 <= x + space_before + w) { /* first word of box doesn't fit so leave box for next * line */ b = split_box; +#ifdef LAYOUT_DEBUG LOG(("leaving for next line")); +#endif } else { /* fit as many words as possible */ assert(space != 0); @@ -2567,8 +2619,10 @@ bool layout_line(struct box *first, int *width, int *y, font_func->font_split(&fstyle, split_box->text, split_box->length, x1 - x0 - x - space_before, &space, &w); +#ifdef LAYOUT_DEBUG LOG(("'%.*s' %i %zu %i", (int) split_box->length, split_box->text, x1 - x0, space, w)); +#endif if (space == 0) space = 1; if (space != split_box->length) { @@ -2578,7 +2632,9 @@ bool layout_line(struct box *first, int *width, int *y, b = split_box->next; } x += space_before + w; +#ifdef LAYOUT_DEBUG LOG(("fitting words")); +#endif } move_y = true; } @@ -2743,7 +2799,9 @@ struct box *layout_minmax_line(struct box *first, b->type == BOX_BR || b->type == BOX_TEXT || b->type == BOX_INLINE_END); +#ifdef LAYOUT_DEBUG LOG(("%p: min %i, max %i", b, min, max)); +#endif if (b->type == BOX_BR) { b = b->next; @@ -2937,7 +2995,10 @@ struct box *layout_minmax_line(struct box *first, *line_min = min; *line_max = max; + +#ifdef LAYOUT_DEBUG LOG(("line_min %i, line_max %i", min, max)); +#endif assert(b != first); assert(0 <= *line_min && *line_min <= *line_max); @@ -3015,7 +3076,11 @@ void place_float_below(struct box *c, int width, int cx, int y, int x0, x1, yy = y; struct box *left; struct box *right; + +#ifdef LAYOUT_DEBUG LOG(("c %p, width %i, cx %i, y %i, cont %p", c, width, cx, y, cont)); +#endif + do { y = yy; x0 = cx; @@ -3231,11 +3296,14 @@ bool layout_table(struct box *table, int available_width, /* calculate width required by cells */ for (i = 0; i != columns; i++) { +#ifdef LAYOUT_DEBUG LOG(("table %p, column %u: type %s, width %i, min %i, max %i", table, i, ((const char *[]) {"UNKNOWN", "FIXED", "AUTO", "PERCENT", "RELATIVE"})[col[i].type], col[i].width, col[i].min, col[i].max)); +#endif + if (col[i].positioned) { positioned_columns++; continue; @@ -3251,14 +3319,19 @@ bool layout_table(struct box *table, int available_width, col[i].min; } else required_width += col[i].min; + +#ifdef LAYOUT_DEBUG LOG(("required_width %i", required_width)); +#endif } required_width += (columns + 1 - positioned_columns) * border_spacing_h; +#ifdef LAYOUT_DEBUG LOG(("width %i, min %i, max %i, auto %i, required %i", table_width, table->min_width, table->max_width, auto_width, required_width)); +#endif if (auto_width < required_width) { /* table narrower than required width for columns: @@ -4072,7 +4145,9 @@ void layout_compute_relative_offset(struct box *box, int *x, int *y) else bottom = -top; +#ifdef LAYOUT_DEBUG LOG(("left %i, right %i, top %i, bottom %i", left, right, top, bottom)); +#endif *x = left; *y = top; @@ -4207,11 +4282,14 @@ bool layout_absolute(struct box *box, struct box *containing_block, box->float_container = NULL; /* 10.3.7 */ +#ifdef LAYOUT_DEBUG LOG(("%i + %i + %i + %i + %i + %i + %i + %i + %i = %i", left, margin[LEFT], border[LEFT].width, padding[LEFT], width, padding[RIGHT], border[RIGHT].width, margin[RIGHT], right, containing_block->width)); +#endif + if (left == AUTO && width == AUTO && right == AUTO) { if (margin[LEFT] == AUTO) margin[LEFT] = 0; @@ -4372,11 +4450,14 @@ bool layout_absolute(struct box *box, struct box *containing_block, border[RIGHT].width - margin[RIGHT]; } } + +#ifdef LAYOUT_DEBUG LOG(("%i + %i + %i + %i + %i + %i + %i + %i + %i = %i", left, margin[LEFT], border[LEFT].width, padding[LEFT], width, padding[RIGHT], border[RIGHT].width, margin[RIGHT], right, containing_block->width)); +#endif box->x = left + margin[LEFT] + border[LEFT].width - cx; if (containing_block->type == BOX_BLOCK || @@ -4404,11 +4485,14 @@ bool layout_absolute(struct box *box, struct box *containing_block, } /* 10.6.4 */ +#ifdef LAYOUT_DEBUG LOG(("%i + %i + %i + %i + %i + %i + %i + %i + %i = %i", top, margin[TOP], border[TOP].width, padding[TOP], height, padding[BOTTOM], border[BOTTOM].width, margin[BOTTOM], bottom, containing_block->height)); +#endif + if (top == AUTO && height == AUTO && bottom == AUTO) { top = static_top; height = box->height; @@ -4492,11 +4576,14 @@ bool layout_absolute(struct box *box, struct box *containing_block, margin[BOTTOM]; } } + +#ifdef LAYOUT_DEBUG LOG(("%i + %i + %i + %i + %i + %i + %i + %i + %i = %i", top, margin[TOP], border[TOP].width, padding[TOP], height, padding[BOTTOM], border[BOTTOM].width, margin[BOTTOM], bottom, containing_block->height)); +#endif box->y = top + margin[TOP] + border[TOP].width - cy; if (containing_block->type == BOX_BLOCK || diff --git a/render/table.c b/render/table.c index ad7e3bd3c..f9bac2ac8 100644 --- a/render/table.c +++ b/render/table.c @@ -26,11 +26,12 @@ #include "css/utils.h" #include "render/box.h" #include "render/table.h" -#define NDEBUG #include "utils/log.h" -#undef NDEBUG #include "utils/talloc.h" +/* Define to enable verbose table debug */ +#undef TABLE_DEBUG + /** * Container for border values during table border calculations */ @@ -214,11 +215,13 @@ bool table_calculate_column_types(struct box *table) col[i].type = COLUMN_WIDTH_AUTO; } +#ifdef TABLE_DEBUG for (i = 0; i != table->columns; i++) LOG(("table %p, column %u: type %s, width %i", table, i, ((const char *[]) {"UNKNOWN", "FIXED", "AUTO", "PERCENT", "RELATIVE"})[col[i].type], col[i].width)); +#endif return true; } diff --git a/utils/log.c b/utils/log.c index 31ca89d13..0f9290bf7 100644 --- a/utils/log.c +++ b/utils/log.c @@ -28,9 +28,6 @@ #include "utils/utils.h" #include "utils/log.h" -static struct timeval start_tv; -static char buff[32]; - nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv) { nserror ret = NSERROR_OK; @@ -59,9 +56,13 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv) return ret; } +#ifndef NDEBUG const char *nslog_gettime(void) { + static struct timeval start_tv; + static char buff[32]; + struct timeval tv; struct timeval now_tv; @@ -72,7 +73,9 @@ const char *nslog_gettime(void) timeval_subtract(&tv, &now_tv, &start_tv); - snprintf(buff, sizeof(buff),"(%ld.%ld)", (long)tv.tv_sec, (long)tv.tv_usec); + snprintf(buff, sizeof(buff),"(%ld.%ld)", + (long)tv.tv_sec, (long)tv.tv_usec); + return buff; } @@ -89,3 +92,5 @@ void nslog_log(const char *format, ...) } } +#endif + diff --git a/utils/log.h b/utils/log.h index 84a211d95..b49f439db 100644 --- a/utils/log.h +++ b/utils/log.h @@ -24,11 +24,6 @@ #include "desktop/netsurf.h" #include "utils/errors.h" -#ifdef NDEBUG -# define LOG(x) ((void) 0) -#else - - /** * Ensures the FILE handle is available to write logging to. * @@ -45,6 +40,10 @@ typedef bool(nslog_ensure_t)(FILE *fptr); */ extern nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv); +#ifdef NDEBUG +# define LOG(x) ((void) 0) +#else + /** * Obtain a formatted string suitable for prepending to a log message * diff --git a/utils/utils.c b/utils/utils.c index 66c020f1d..f632af9e4 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -33,9 +33,6 @@ #include #include "utils/config.h" -#define NDEBUG -#include "utils/log.h" -#undef NDEBUG #include "utils/messages.h" #include "utils/utf8.h" #include "utils/utils.h" -- cgit v1.2.3