This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 8728ce4ba9c41b1ae214808623111c5c869f31ad (commit) via 95609738c5d91412e53a1fadc18ed6200825ce1d (commit) via 43664f1f57cd6092e77765fa72234cf92d4ad074 (commit) via 082e5eed64755a0130dafab53ef3b5252ce745e6 (commit) from 0d714fd8292c2805d3cdc23d89345d41c9f23815 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/8728ce4ba9c41b1ae214808623111c5c869f3...
commit 8728ce4ba9c41b1ae214808623111c5c869f31ad Author: Cyril Hrubis metan@ucw.cz Date: Wed Dec 26 21:12:36 2012 +0100
core: Prepare for correct WritePixels implementation.
* The Write Pixels header is correctly generated now
* C sources are generated for Write Pixels functions that are not written by hand (currently the body is empty)
* The Write Pixels for 1BPP, 2BPP and 4BPP are now all correct and fast (hopefully)
TODO: Generated Write Pixels, tests
diff --git a/include/core/GP_WritePixel.gen.h.t b/include/core/GP_WritePixel.gen.h.t new file mode 100644 index 0000000..91237bc --- /dev/null +++ b/include/core/GP_WritePixel.gen.h.t @@ -0,0 +1,46 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +%% extends 'base.h.t' + +{% block description %}Write Pixels generated header{% endblock %} + +{% block body %} + +/* + * These functions writes cnt pixels using value val starting at start address + * and additionally (for pixel sizes that are not aligned to the whole bytes) + * at off offset in the first byte (i.e. byte at the start address). + */ + +%% for ps in pixelsizes +%% if ps.needs_bit_endian() +void GP_WritePixels_{{ ps.suffix }}(void *start, uint8_t off, + size_t cnt, unsigned int val); + +%% else +void GP_WritePixels_{{ ps.suffix }}(void *start, size_t cnt, unsigned int val); + +%% endif +%% endfor + +{% endblock body %} diff --git a/include/core/GP_WritePixel.h b/include/core/GP_WritePixel.h index bb79b1f..b5005ec 100644 --- a/include/core/GP_WritePixel.h +++ b/include/core/GP_WritePixel.h @@ -26,51 +26,9 @@ #ifndef CORE_GP_WRITEPIXEL_H #define CORE_GP_WRITEPIXEL_H
+#include <stddef.h> #include <stdint.h> -#include <unistd.h>
-/* - * Writes cnt pixels starting at offset off. - */ -void GP_WritePixels_1BPP_LE(uint8_t *start, uint8_t off, - size_t cnt, uint8_t val); - -/* - * Writes cnt pixels starting at offset off (offset is in pixel sizes not in - * bits). - */ -void GP_WritePixels_2BPP_LE(uint8_t *start, uint8_t off, - size_t cnt, uint8_t val); - -/* - * Writes cnt pixels starting at offset off (offset is in pixel sizes not in - * bits i.e. offset could be either 0 or 1). - */ -void GP_WritePixels_4BPP_LE(uint8_t *start, uint8_t off, - size_t cnt, uint8_t val); - -/* - * These calls are not byte aligned, thus need start offset. - */ -void GP_WritePixels_1BPP_BE(uint8_t *start, uint8_t off, - size_t cnt, uint8_t val); - -void GP_WritePixels_2BPP_BE(uint8_t *start, uint8_t off, - size_t cnt, uint8_t val); - -void GP_WritePixels_4BPP_BE(uint8_t *start, uint8_t off, - size_t cnt, uint8_t val); - -void GP_WritePixels_18BPP_BE(void *start, uint8_t off, - size_t count, uint32_t value); - -void GP_WritePixels_18BPP_LE(void *start, uint8_t off, - size_t count, uint32_t value); - -/* Byte-aligned calls. */ -void GP_WritePixels_8BPP(void *start, size_t count, uint8_t value); -void GP_WritePixels_16BPP(void *start, size_t count, uint16_t value); -void GP_WritePixels_24BPP(void *start, size_t count, uint32_t value); -void GP_WritePixels_32BPP(void *start, size_t count, uint32_t value); +#include "core/GP_WritePixel.gen.h"
#endif /* CORE_GP_WRITEPIXEL_H */ diff --git a/include/core/Makefile b/include/core/Makefile index 5606d74..0dac795 100644 --- a/include/core/Makefile +++ b/include/core/Makefile @@ -4,7 +4,8 @@ include $(TOPDIR)/pre.mk
GENHEADERS=GP_Convert_Scale.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h GP_Convert.gen.h GP_FnPerBpp.gen.h - GP_MixPixels.gen.h GP_GammaCorrection.gen.h GP_GammaPixel.gen.h + GP_MixPixels.gen.h GP_GammaCorrection.gen.h GP_GammaPixel.gen.h + GP_WritePixel.gen.h
include $(TOPDIR)/gen.mk include $(TOPDIR)/post.mk diff --git a/libs/core/GP_WritePixel.c b/libs/core/GP_WritePixel.c index a6829b0..916f9ef 100644 --- a/libs/core/GP_WritePixel.c +++ b/libs/core/GP_WritePixel.c @@ -30,8 +30,8 @@
static const uint8_t bytes_1BPP[] = {0x00, 0xff};
-void GP_WritePixels_1BPP_LE(uint8_t *start, uint8_t off, - size_t cnt, uint8_t val) +void GP_WritePixels_1BPP_LE(void *start, uint8_t off, + size_t cnt, unsigned int val) { int len = cnt;
@@ -104,10 +104,84 @@ void GP_WritePixels_1BPP_LE(uint8_t *start, uint8_t off, } }
+void GP_WritePixels_1BPP_BE(void *start, uint8_t off, + size_t cnt, unsigned int val) +{ + int len = cnt; + + /* Write start of the line */ + switch (off) { + case 0: + break; + case 1: + GP_SET_BITS1_ALIGNED(6, 1, start, val); + + if (--len == 0) + return; + case 2: + GP_SET_BITS1_ALIGNED(5, 1, start, val); + + if (--len == 0) + return; + case 3: + GP_SET_BITS1_ALIGNED(4, 1, start, val); + + if (--len == 0) + return; + case 4: + GP_SET_BITS1_ALIGNED(3, 1, start, val); + + if (--len == 0) + return; + case 5: + GP_SET_BITS1_ALIGNED(2, 1, start, val); + + if (--len == 0) + return; + case 6: + GP_SET_BITS1_ALIGNED(1, 1, start, val); + + if (--len == 0) + return; + case 7: + GP_SET_BITS1_ALIGNED(0, 1, start, val); + + if (--len == 0) + return; + + start++; + break; + } + + /* Write as many bytes as possible */ + memset(start, bytes_1BPP[val & 0x01], len/8); + + start+=len/8; + + /* And the rest */ + switch (len%8) { + case 7: + GP_SET_BITS1_ALIGNED(1, 1, start, val); + case 6: + GP_SET_BITS1_ALIGNED(2, 1, start, val); + case 5: + GP_SET_BITS1_ALIGNED(3, 1, start, val); + case 4: + GP_SET_BITS1_ALIGNED(4, 1, start, val); + case 3: + GP_SET_BITS1_ALIGNED(5, 1, start, val); + case 2: + GP_SET_BITS1_ALIGNED(6, 1, start, val); + case 1: + GP_SET_BITS1_ALIGNED(7, 1, start, val); + break; + } +} + static const uint8_t bytes_2BPP[] = {0x00, 0x55, 0xaa, 0xff};
-void GP_WritePixels_2BPP_LE(uint8_t *start, uint8_t off, - size_t cnt, uint8_t val) +void GP_WritePixels_2BPP_LE(void *start, uint8_t off, + size_t cnt, unsigned int val) { int len = cnt;
@@ -152,13 +226,59 @@ void GP_WritePixels_2BPP_LE(uint8_t *start, uint8_t off, } }
+void GP_WritePixels_2BPP_BE(void *start, uint8_t off, + size_t cnt, unsigned int val) +{ + int len = cnt; + + /* Write start of the line */ + switch (off) { + case 0: + break; + case 1: + GP_SET_BITS1_ALIGNED(6, 2, start, val); + + if (--len == 0) + return; + case 2: + GP_SET_BITS1_ALIGNED(4, 2, start, val); + + if (--len == 0) + return; + case 3: + GP_SET_BITS1_ALIGNED(2, 2, start, val); + + if (--len == 0) + return; + + start++; + break; + } + + /* Write as many bytes as possible */ + memset(start, bytes_2BPP[val & 0x03], len/4); + + start+=len/4; + + /* And the rest */ + switch (len%4) { + case 3: + GP_SET_BITS1_ALIGNED(0, 2, start, val); + case 2: + GP_SET_BITS1_ALIGNED(2, 2, start, val); + case 1: + GP_SET_BITS1_ALIGNED(4, 2, start, val); + break; + } +} + static const uint8_t bytes_4BPP[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
-void GP_WritePixels_4BPP_LE(uint8_t *start, uint8_t off, - size_t cnt, uint8_t val) +void GP_WritePixels_4BPP_LE(void *start, uint8_t off, + size_t cnt, unsigned int val) { int len = cnt;
@@ -189,116 +309,45 @@ void GP_WritePixels_4BPP_LE(uint8_t *start, uint8_t off, } }
-static const uint8_t chunks_1bpp[8] = { - 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, -}; - -void GP_WritePixels_1BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val) -{ - uint8_t s_off = off % 8; - uint8_t e_off = (cnt + s_off) % 8; - uint32_t len = (cnt + s_off) / 8; - uint8_t col = val ? 0xff : 0x00; - - /* handle special cases */ - if (cnt < 8) { - uint8_t u_chunk = chunks_1bpp[cnt] >> off; - uint8_t l_chunk = chunks_1bpp[cnt] << (8 - off); - - if (val) { - start[0] |= u_chunk; - start[1] |= l_chunk; - } else { - start[0] &= ~u_chunk; - start[1] &= ~l_chunk; - } - - return; - } - - /* write len - 2 bytes */ - if (len > 1) - GP_WritePixels_8BPP(start + 1, len - 2, col); - - /* deal with the start and end */ - if (val) { - start[0] |= ~chunks_1bpp[s_off]; - start[len] |= chunks_1bpp[e_off]; - } else { - start[0] &= chunks_1bpp[s_off]; - start[len] &= ~chunks_1bpp[e_off]; - } -} - -static const uint8_t colors_2bpp[4] = { - 0x00, 0x55, 0xaa, 0xff -}; - -#define PUT_PIXEL_2BPP(p, off, pix) *(p) = (*(p) & ~(0xc0>>(off))) | (pix<<(6 - off)) - -void GP_WritePixels_2BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val) +void GP_WritePixels_4BPP_BE(void *start, uint8_t off, + size_t cnt, unsigned int val) { - uint8_t s_off = off % 4; - uint8_t e_off = 2 * ((cnt + s_off) % 4); - uint8_t len = (cnt + s_off) / 4; - - s_off *= 2; - val %= 4; - - /* handle special cases */ - if (cnt < 4) { - uint8_t len = s_off + 2*cnt; - uint8_t max = GP_MIN(s_off + 2*cnt, 8u); + int len = cnt;
- for (off = s_off; off < max; off+=2) - PUT_PIXEL_2BPP(start, off, val); + /* Write start of the line */ + switch (off) { + case 0: + break; + case 1: + GP_SET_BITS1_ALIGNED(0, 4, start, val);
- if (len <= 8) + if (--len == 0) return;
- for (off = 0; off < len%8; off+=2) - PUT_PIXEL_2BPP(start+1, off, val); - - return; + start++; + break; }
- /* write len - 2 bytes */ - if (len > 1) - GP_WritePixels_8BPP(start + 1, len - 2, colors_2bpp[val]); - - /* handle start and end */ - start[0] = (start[0] & (0xff << (8 - s_off))) | - (colors_2bpp[val] >> s_off); - - start[len] = (start[len] & (0xff >> e_off)) | - (colors_2bpp[val] << (8 - e_off)); -} - - -void GP_WritePixels_4BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val) -{ - uint8_t s_off = off % 2; - uint8_t e_off = (cnt + s_off) % 2; - uint32_t len = (cnt - s_off - e_off) / 2; - - val %= 16; - uint8_t col = (val << 4)& val; + /* Write as many bytes as possible */ + memset(start, bytes_4BPP[val & 0x0f], len/2);
- if (len > 0) - GP_WritePixels_8BPP(start + s_off, len, val); + start+=len/2;
- /* handle start and end */ - if (s_off) GP_SET_BITS(4, 4, start[0], col); - if (e_off) GP_SET_BITS(0, 4, start[len+s_off], val); + /* And the rest */ + switch (len%2) { + case 1: + GP_SET_BITS1_ALIGNED(4, 4, start, val); + break; + } }
-void GP_WritePixels_8BPP(void *start, size_t count, uint8_t value) +void GP_WritePixels_8BPP(void *start, size_t count, unsigned int value) {
memset(start, value, count); }
-void GP_WritePixels_16BPP(void *start, size_t count, uint16_t value) +void GP_WritePixels_16BPP(void *start, size_t count, unsigned int value) { uint16_t *p = (uint16_t *) start; size_t i; @@ -323,17 +372,7 @@ void GP_WritePixels_16BPP(void *start, size_t count, uint16_t value) } }
-void GP_WritePixels_18BPP_LE(void *start, uint8_t off, size_t count, uint32_t value) -{ - #warning TODO -} - -void GP_WritePixels_18BPP_BE(void *start, uint8_t off, size_t count, uint32_t value) -{ - #warning TODO -} - -void GP_WritePixels_24BPP(void *start, size_t count, uint32_t value) +void GP_WritePixels_24BPP(void *start, size_t count, unsigned int value) { uint8_t *bytep = (uint8_t *) start;
@@ -453,7 +492,7 @@ void GP_WritePixels_24BPP(void *start, size_t count, uint32_t value) } }
-void GP_WritePixels_32BPP(void *start, size_t count, uint32_t value) +void GP_WritePixels_32BPP(void *start, size_t count, unsigned int value) { /* * Inspired by GNU libc's wmemset() (by Ulrich Drepper, licensed under LGPL). diff --git a/libs/core/GP_WritePixel.gen.c.t b/libs/core/GP_WritePixel.gen.c.t new file mode 100644 index 0000000..2bc89b3 --- /dev/null +++ b/libs/core/GP_WritePixel.gen.c.t @@ -0,0 +1,58 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +%% extends 'base.h.t' + +{% block description %}Write pixel{% endblock %} + +{% block body %} + +#include "core/GP_GetSetBits.h" +#include "core/GP_GetPutPixel.h" +#include "core/GP_WritePixel.gen.h" + +{# Some pixel types has hand written optimized functions #} +%% set hand_optimized = ['1BPP_LE', '1BPP_BE', + '2BPP_LE', '2BPP_BE', + '4BPP_LE', '4BPP_BE', + '8BPP', '16BPP', + '24BPP', '32BPP'] + +%% for ps in pixelsizes +%% if ps.suffix not in hand_optimized +%% if ps.needs_bit_endian() +void GP_WritePixels_{{ ps.suffix }}(void *start, uint8_t off, + size_t cnt, unsigned int val) +{ + //TODO: +} +%% else +void GP_WritePixels_{{ ps.suffix }}(void *start, size_t cnt, unsigned int val) +{ + //TODO: +} +%% endif + +%% endif +%% endfor + +{% endblock body %} diff --git a/libs/core/Makefile b/libs/core/Makefile index cd08e30..46a46d3 100644 --- a/libs/core/Makefile +++ b/libs/core/Makefile @@ -2,7 +2,8 @@ TOPDIR=../.. include $(TOPDIR)/pre.mk
GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c - GP_GammaCorrection.gen.c + GP_GammaCorrection.gen.c GP_WritePixel.gen.c + CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=core
http://repo.or.cz/w/gfxprim.git/commit/95609738c5d91412e53a1fadc18ed6200825c...
commit 95609738c5d91412e53a1fadc18ed6200825ce1d Author: Cyril Hrubis metan@ucw.cz Date: Wed Dec 26 21:02:59 2012 +0100
doc: gen: Add quick jinja2 help.
diff --git a/doc/gen.txt b/doc/gen.txt index 73e9e15..830a0d4 100644 --- a/doc/gen.txt +++ b/doc/gen.txt @@ -210,3 +210,27 @@ And most importantly objects generated from the configuration files:
* 'pixelsizes' list of all pixel size objects * 'pixeltypes' list of all pixel type objects + +Quick Syntax Help +^^^^^^^^^^^^^^^^^ + +Jinja2 basics: + +- Each written line is reproduces as it is unless it contains template + 'variable' or 'expression' + +- 'Variable' is text enclosed between +{{+ and +}}+ + * +{{ ps.size }}' or +{{ ps.suffix }}+ + * +{{ 2 ** i }}+ + * +{{ int(2 ** (7 - i)) }} >> {{ 8 - i }}+ + +- 'Expression' is either line that starts with +%%+ or a text enclosed between + +{%+ and +%}+ + * +%% for ps in pixel_size+ + * +%% endfor+ + * +{% if ps.needs_bit_endian() %} ... {% endif %}+ + +- Comments are enclosed in +{#+ and +#}+ + +More complete documentation could be found in +http://jinja.pocoo.org/docs/templates/%5BJinja official documentation]
http://repo.or.cz/w/gfxprim.git/commit/43664f1f57cd6092e77765fa72234cf92d4ad...
commit 43664f1f57cd6092e77765fa72234cf92d4ad074 Author: Cyril Hrubis metan@ucw.cz Date: Wed Dec 26 20:20:59 2012 +0100
doc: gen: Add needs_bit_endian() function.
diff --git a/doc/gen.txt b/doc/gen.txt index 1cdf906..73e9e15 100644 --- a/doc/gen.txt +++ b/doc/gen.txt @@ -25,7 +25,11 @@ class PixelSize(object): self.suffix = suffix
self.bit_endian = bit_endian - ... + + def needs_bit_endian(self): + ... + + ...
-------------------------------------------------------------------------------
@@ -41,10 +45,13 @@ The 'bit_endian' determines the ordering of pixel bits within a byte in bitmaps and graymaps. This is significant in pixel types with pixel boundaries within a byte, i.e. 1 bpp, 4 bpp or 17 bpp.
-It can be either 'BE' or 'LE' (i.e. most significant bit left or right in the bitmap). -Usually, the bitmap is ordered with left bits earlier in the memory, but the -earlier/later relationship is important. -This is defined in terms of natural pixel ordering within the memory. +The function 'needs_bit_endian()' returns true for pixel sizes that are not +aligned to the whole bytes. + +The bit endian can be either 'BE' or 'LE' (i.e. most significant bit left or +right in the bitmap). Usually, the bitmap is ordered with left bits earlier +in the memory, but the earlier/later relationship is important. This is +defined in terms of natural pixel ordering within the memory.
'BE' means that the earlier (usually left-most) pixels use the higher ("big") bits of the byte. I.e. in 1 bpp, the first pixel would have value 128, the second 64
http://repo.or.cz/w/gfxprim.git/commit/082e5eed64755a0130dafab53ef3b5252ce74...
commit 082e5eed64755a0130dafab53ef3b5252ce745e6 Author: Cyril Hrubis metan@ucw.cz Date: Wed Dec 26 19:18:40 2012 +0100
core: GP_Common: Reimplement the abort message.
Move the abort message code from the header to the C source.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile index cce46d8..cb6fe82 100644 --- a/demos/c_simple/Makefile +++ b/demos/c_simple/Makefile @@ -18,7 +18,7 @@ APPS=backend_example loaders_example loaders filters_symmetry gfx_koch virtual_backend_example meta_data meta_data_dump tmp_file showimage v4l2_show v4l2_grab convolution weighted_median shapetest koch input_example fileview linetest randomshapetest fonttest- loaders_register blittest textaligntest + loaders_register blittest textaligntest abort
ifeq ($(HAVE_LIBSDL),yes) APPS+=SDL_glue diff --git a/demos/c_simple/abort.c b/demos/c_simple/abort.c new file mode 100644 index 0000000..d9c3e18 --- /dev/null +++ b/demos/c_simple/abort.c @@ -0,0 +1,33 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <GP.h> + +int main(void) +{ + GP_Context *ctx; + + /* this call causes library to abort because of invalid parameters */ + ctx = GP_ContextAlloc(0, 0, -1); + + return 0; +} diff --git a/include/core/GP_Common.h b/include/core/GP_Common.h index 1140e76..1352c76 100644 --- a/include/core/GP_Common.h +++ b/include/core/GP_Common.h @@ -100,29 +100,19 @@ * GP_GENERAL_CHECK is a check with specified message prefix * (for assert and check) */ +#define GP_INTERNAL_ABORT(...) do { + GP_PrintAbortInfo(__FILE__, __FUNCTION__, __LINE__, __VA_ARGS__); + abort(); +} while (0)
/* * Print as much trace info as possible. Currently, the (C) call stack and * the Python stack if a Python interpreter is set up. In case more wrappers * are written, it should print a trace for the currently active. */ -void GP_PrintAbortInfo(void); - -#define GP_INTERNAL_ABORT_BUFSIZE 1024 -#define GP_INTERNAL_ABORT(str_abort_msg_, ...) do { - char bufstart[GP_INTERNAL_ABORT_BUFSIZE], *buf = bufstart; - char *bufend = buf + GP_INTERNAL_ABORT_BUFSIZE; - buf += snprintf(buf, bufend - buf, "*** gfxprim: %s:%d: in %s: %s", - __FILE__, __LINE__, __FUNCTION__, str_abort_msg_); - if (buf > bufend) buf = bufend; - if (! (#__VA_ARGS__ [0])) - buf += snprintf(buf, bufend - buf, "abort()"); - else - buf += snprintf(buf, bufend - buf, " " __VA_ARGS__); - fprintf(stderr, "%sn", bufstart); - GP_PrintAbortInfo(); - abort(); -} while (0) +void GP_PrintAbortInfo(const char *file, const char *function, unsigned int line, + const char *msg, const char *fmt, ...) + __attribute__ ((format (printf, 5, 6)));
#define GP_GENERAL_CHECK(check_cond_, check_message_, ...) do { if (unlikely(!(check_cond_))) { @@ -138,10 +128,11 @@ void GP_PrintAbortInfo(void); * Aborts and prints the message along with the location in code * to stderr. Used for fatal errors. * - * Use as either GP_ABORT(), GP_ABORT(msg) or GP_ABORT(format, params...) where + * Use as either GP_ABORT(msg) or GP_ABORT(format, params...) where * msg and format must be string constants. */ -#define GP_ABORT(...) GP_INTERNAL_ABORT("", ##__VA_ARGS__) +#define GP_ABORT(...) + GP_INTERNAL_ABORT("n", __VA_ARGS__)
/* * Checks the condition and aborts immediately if it is not satisfied, @@ -153,7 +144,7 @@ void GP_PrintAbortInfo(void); * constants. */ #define GP_ASSERT(check_cond_, ...) - GP_GENERAL_CHECK(check_cond_, "assertion failed: ", ##__VA_ARGS__); + GP_GENERAL_CHECK(check_cond_, "assertion failed: ", ##__VA_ARGS__)
/* * Perform a runtime check, on failure abort and print a message. @@ -164,6 +155,6 @@ void GP_PrintAbortInfo(void); * constants. */ #define GP_CHECK(check_cond_, ...) - GP_GENERAL_CHECK(check_cond_, "check failed: ", ##__VA_ARGS__); + GP_GENERAL_CHECK(check_cond_, "check failed: ", ##__VA_ARGS__)
#endif /* CORE_GP_COMMON_H */ diff --git a/libs/core/GP_Common.c b/libs/core/GP_Common.c index ae1365e..1d608ff 100644 --- a/libs/core/GP_Common.c +++ b/libs/core/GP_Common.c @@ -26,6 +26,7 @@ #include "../config.h"
#include <stdio.h> +#include <stdarg.h>
#ifdef HAVE_BACKTRACE #include <execinfo.h> @@ -70,9 +71,20 @@ static void print_python_stack(void) #endif /* HAVE_DL */ }
-void GP_PrintAbortInfo(void) +void GP_PrintAbortInfo(const char *file, const char *func, unsigned int line, + const char *msg, const char *fmt, ...) { + va_list va; + + fprintf(stderr, "*** gfxprim: %s:%d: in %s: %sn", + file, line, func, msg); + + va_start(va, fmt); + vfprintf(stderr, fmt, va); + va_end(va); + + fprintf(stderr, "n"); + print_python_stack(); print_c_stack(); } -
-----------------------------------------------------------------------
Summary of changes: demos/c_simple/Makefile | 2 +- .../GP_Grabbers.h => demos/c_simple/abort.c | 14 +- doc/gen.txt | 41 +++- include/core/GP_Common.h | 33 +-- .../core/GP_WritePixel.gen.h.t | 24 +- include/core/GP_WritePixel.h | 46 +---- include/core/Makefile | 3 +- libs/core/GP_Common.c | 16 +- libs/core/GP_WritePixel.c | 263 +++++++++++--------- .../GP_WritePixel.gen.c.t} | 30 ++- libs/core/Makefile | 3 +- 11 files changed, 264 insertions(+), 211 deletions(-) copy include/grabbers/GP_Grabbers.h => demos/c_simple/abort.c (90%) copy libs/gfx/GP_VLine.gen.c.t => include/core/GP_WritePixel.gen.h.t (76%) copy libs/{gfx/GP_VLine.gen.c.t => core/GP_WritePixel.gen.c.t} (71%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.