Fri, 06 Sep 2013 13:20:20 +0200
minor code fixes + added clang support + improved build system
--- a/Makefile Thu Sep 05 13:55:04 2013 +0200 +++ b/Makefile Fri Sep 06 13:20:20 2013 +0200 @@ -29,20 +29,20 @@ # # available configurations: -# gcc -# suncc +# clang, clang-debug +# gcc, gcc-debug +# g++, g++-debug +# osx, osx-debug +# suncc, suncc-debug # windows -# osx # -#ifndef CONF - CONF=gcc -#endif +CONF=gcc +PREFIX=/usr/local +include unix.mk include $(CONF).mk -all: ucx test - ucx: FORCE cd ucx; $(MAKE) CONF=$(CONF) all @@ -52,9 +52,22 @@ run: FORCE test ./build/test$(APP_EXT) +install: ucx | $(PREFIX)/include/ucx $(PREFIX)/lib + cp ./build/libucx$(LIB_EXT) $(PREFIX)/lib && \ + cp ./ucx/*.h $(PREFIX)/include/ucx + +uninstall: + $(RM) $(RMFLAGS) $(PREFIX)/include/ucx &&\ + $(RM) $(RMFLAGS) $(PREFIX)/lib/libucx$(LIB_EXT) + +$(PREFIX)/lib: + mkdir -p $(PREFIX)/lib + +$(PREFIX)/include/ucx: + mkdir -p $(PREFIX)/include/ucx + clean: FORCE - $(RM) $(RMFLAGS) build/*.${OBJ_EXT} - $(RM) $(RMFLAGS) build/*.${LIB_EXT} + $(RM) $(RMFLAGS) build FORCE:
--- a/README Thu Sep 05 13:55:04 2013 +0200 +++ b/README Fri Sep 06 13:20:20 2013 +0200 @@ -31,10 +31,10 @@ make -The further available configurations are gcc-debug, g++, g++-debug, osx, -osx-debug, suncc, suncc-debug and windows. The later uses microsoft visual C++ -compiler. If you want to use mingw oder cygwin, you can use the default gcc -configuration. +The available configurations are clang, clang-debug, gcc, gcc-debug, g++, +g++-debug, osx, osx-debug, suncc, suncc-debug and windows. The later uses +microsoft visual C++ compiler. If you want to use mingw oder cygwin, you can +use the default gcc configuration. The build files are placed into a build subdirectory, which is created if it does not exists. @@ -49,7 +49,7 @@ The default prefix is /usr/local. -If you want to test you build, run +If you want to test your build, run make run CONF=<yourconfig>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clang-debug.mk Fri Sep 06 13:20:20 2013 +0200 @@ -0,0 +1,34 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2013 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +CC = clang +LD = clang + +CFLAGS = -std=gnu99 -g -fstrict-aliasing -Wall -pedantic -c +LDFLAGS = -lm +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clang.mk Fri Sep 06 13:20:20 2013 +0200 @@ -0,0 +1,34 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2013 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +CC = clang +LD = clang + +CFLAGS = -std=gnu99 -O2 -fstrict-aliasing -c +LDFLAGS = -lm +
--- a/gcc-debug.mk Thu Sep 05 13:55:04 2013 +0200 +++ b/gcc-debug.mk Fri Sep 06 13:20:20 2013 +0200 @@ -28,16 +28,7 @@ CC = gcc LD = gcc -AR = ar -RM = rm CFLAGS = -std=gnu99 -g -fstrict-aliasing -Wall -pedantic -c -COFLAGS = -o LDFLAGS = -LOFLAGS = -o -ARFLAGS = -r -RMFLAGS = -f -OBJ_EXT = o -LIB_EXT = a -APP_EXT =
--- a/gcc.mk Thu Sep 05 13:55:04 2013 +0200 +++ b/gcc.mk Fri Sep 06 13:20:20 2013 +0200 @@ -28,17 +28,7 @@ CC = gcc LD = gcc -AR = ar -RM = rm CFLAGS = -std=gnu99 -O2 -fstrict-aliasing -c -COFLAGS = -o LDFLAGS = -LOFLAGS = -o -ARFLAGS = -r -RMFLAGS = -f -OBJ_EXT = o -LIB_EXT = a -APP_EXT = -
--- a/osx-debug.mk Thu Sep 05 13:55:04 2013 +0200 +++ b/osx-debug.mk Fri Sep 06 13:20:20 2013 +0200 @@ -28,17 +28,7 @@ CC = cc LD = cc -AR = ar -RM = rm CFLAGS = -g -c -COFLAGS = -o ./ LDFLAGS = -LOFLAGS = -o ./ -ARFLAGS = -r -RMFLAGS = -f -OBJ_EXT = o -LIB_EXT = a -APP_EXT = -
--- a/osx.mk Thu Sep 05 13:55:04 2013 +0200 +++ b/osx.mk Fri Sep 06 13:20:20 2013 +0200 @@ -28,17 +28,7 @@ CC = cc LD = cc -AR = ar -RM = rm CFLAGS = -O2 -c -COFLAGS = -o ./ LDFLAGS = -LOFLAGS = -o ./ -ARFLAGS = -r -RMFLAGS = -f -OBJ_EXT = o -LIB_EXT = a -APP_EXT = -
--- a/suncc-debug.mk Thu Sep 05 13:55:04 2013 +0200 +++ b/suncc-debug.mk Fri Sep 06 13:20:20 2013 +0200 @@ -26,19 +26,9 @@ # POSSIBILITY OF SUCH DAMAGE. # -CC = CC +CC = cc LD = cc -AR = ar -RM = rm CFLAGS = -g -c -COFLAGS = -o LDFLAGS = -lm -LOFLAGS = -o -ARFLAGS = -r -RMFLAGS = -f -OBJ_EXT = o -LIB_EXT = a -APP_EXT = -
--- a/suncc.mk Thu Sep 05 13:55:04 2013 +0200 +++ b/suncc.mk Fri Sep 06 13:20:20 2013 +0200 @@ -28,17 +28,7 @@ CC = cc LD = cc -AR = ar -RM = rm CFLAGS = -O -c -COFLAGS = -o LDFLAGS = -lm -LOFLAGS = -o -ARFLAGS = -r -RMFLAGS = -f -OBJ_EXT = o -LIB_EXT = a -APP_EXT = -
--- a/test/Makefile Thu Sep 05 13:55:04 2013 +0200 +++ b/test/Makefile Fri Sep 06 13:20:20 2013 +0200 @@ -26,6 +26,7 @@ # POSSIBILITY OF SUCH DAMAGE. # +include ../unix.mk include ../$(CONF).mk SRC = main.c @@ -38,16 +39,14 @@ SRC += buffer_tests.c SRC += utils_tests.c -OBJ = $(SRC:%.c=../build/%.$(OBJ_EXT)) - -all: ../build/test1 +OBJ = $(SRC:%.c=../build/%$(OBJ_EXT)) -../build/test1: $(OBJ) +all: $(OBJ) $(LD) $(LDFLAGS) $(LOFLAGS)../build/test$(APP_EXT) $(OBJ) \ - ../build/libucx.$(LIB_EXT) + ../build/libucx$(LIB_EXT) -../build/%.$(OBJ_EXT): %.c ../build +../build/%$(OBJ_EXT): %.c | ../build $(CC) $(CFLAGS) -I../ $(COFLAGS)$@ $< ../build: - mkdir -p build + $(MKDIR) $(MKDIRFLAGS) build
--- a/test/map_tests.c Thu Sep 05 13:55:04 2013 +0200 +++ b/test/map_tests.c Fri Sep 06 13:20:20 2013 +0200 @@ -178,9 +178,9 @@ int check = 0; int hit = 0; - int* v; + void* v; UCX_MAP_FOREACH(key, v, i) { - check += *v; + check += *((int*)v); hit++; }
--- a/ucx/Makefile Thu Sep 05 13:55:04 2013 +0200 +++ b/ucx/Makefile Fri Sep 06 13:20:20 2013 +0200 @@ -26,6 +26,7 @@ # POSSIBILITY OF SUCH DAMAGE. # +include ../unix.mk include ../$(CONF).mk # list of source files @@ -40,15 +41,15 @@ SRC += logging.c SRC += buffer.c -OBJ = $(SRC:%.c=../build/%.$(OBJ_EXT)) +OBJ = $(SRC:%.c=../build/ucx/%$(OBJ_EXT)) all: libucx libucx: $(OBJ) - $(AR) $(ARFLAGS) $(AOFLAGS)../build/libucx.$(LIB_EXT) $(OBJ) + $(AR) $(ARFLAGS) $(AOFLAGS)../build/libucx$(LIB_EXT) $(OBJ) -../build/%.$(OBJ_EXT): %.c ../build +../build/ucx/%$(OBJ_EXT): %.c | ../build/ucx $(CC) $(CFLAGS) $(COFLAGS)$@ $< -../build: - mkdir -p ../build +../build/ucx: + $(MKDIR) $(MKDIRFLAGS) ../build/ucx
--- a/ucx/logging.c Thu Sep 05 13:55:04 2013 +0200 +++ b/ucx/logging.c Fri Sep 06 13:20:20 2013 +0200 @@ -61,11 +61,13 @@ free(logger); } +// estimated max. message length (documented) +#define UCX_LOGGER_MSGMAX 4096 + void ucx_logger_logf(UcxLogger *logger, unsigned int level, const char* file, const unsigned int line, const char *format, ...) { if (level <= logger->level) { - const size_t max = 4096; // estimated max. message length (documented) - char msg[max]; + char msg[UCX_LOGGER_MSGMAX]; char *text; size_t k = 0; size_t n; @@ -85,14 +87,14 @@ n = strlen(file); memcpy(msg+k, file, n); k += n; - k += sprintf(msg+k, ":%d ", line); + k += snprintf(msg+k, UCX_LOGGER_MSGMAX-k, ":%d ", line); } msg[k++] = '-'; msg[k++] = ' '; va_list args; va_start (args, format); - k += vsnprintf(msg+k, max-k-1, format, args); + k += vsnprintf(msg+k, UCX_LOGGER_MSGMAX-k-1, format, args); va_end (args); msg[k++] = '\n';
--- a/ucx/properties.c Thu Sep 05 13:55:04 2013 +0200 +++ b/ucx/properties.c Fri Sep 06 13:20:20 2013 +0200 @@ -217,38 +217,36 @@ } } +// buffer size is documented - change doc, when you change bufsize! +#define UCX_PROPLOAD_BUFSIZE 1024 int ucx_properties_load(UcxMap *map, FILE *file) { UcxProperties *parser = ucx_properties_new(); if(!(parser && map && file)) { return 1; } - // buffer size is documented - change doc, when you change bufsize! - const size_t bufsize = 1024; - int error = 0; size_t r; - char buf[bufsize]; - while((r = fread(buf, 1, bufsize, file)) != 0) { + char buf[UCX_PROPLOAD_BUFSIZE]; + while((r = fread(buf, 1, UCX_PROPLOAD_BUFSIZE, file)) != 0) { ucx_properties_fill(parser, buf, r); error = ucx_properties2map(parser, map); if (error) { break; } } - ucx_properties_free(parser); return error; } int ucx_properties_store(UcxMap *map, FILE *file) { UcxMapIterator iter = ucx_map_iterator(map); - char *v; + void *v; sstr_t value; size_t written; UCX_MAP_FOREACH(k, v, iter) { - value = sstr(v); + value = sstr((char*)v); written = 0; written += fwrite(k.data, 1, k.len, file);
--- a/ucx/string.c Thu Sep 05 13:55:04 2013 +0200 +++ b/ucx/string.c Fri Sep 06 13:20:20 2013 +0200 @@ -121,9 +121,9 @@ sstr_t sstrrchr(sstr_t s, int c) { if (s.length > 0) { - for(size_t i=s.length-1;i>=0;i--) { - if(s.ptr[i] == c) { - return sstrsubs(s, i); + for(size_t i=s.length;i>0;i--) { + if(s.ptr[i-1] == c) { + return sstrsubs(s, i-1); } } }
--- a/ucx/ucx.h Thu Sep 05 13:55:04 2013 +0200 +++ b/ucx/ucx.h Fri Sep 06 13:20:20 2013 +0200 @@ -63,9 +63,11 @@ #define _Bool bool #define restrict #endif +/** Use C naming even when compiling with C++. */ #define UCX_EXTERN extern "C" extern "C" { #else +/** Pointless in C. */ #define UCX_EXTERN #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unix.mk Fri Sep 06 13:20:20 2013 +0200 @@ -0,0 +1,44 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2013 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +CC = @echo "\nInvalid configuration.\n" && /bin/false +LD = @echo "\nInvalid configuration.\n" && /bin/false +AR = ar +RM = rm +MKDIR = mkdir + +COFLAGS = -o ./ +LOFLAGS = -o ./ +ARFLAGS = -r +RMFLAGS = -f -R +MKDIRFLAGS = -p + +OBJ_EXT = .o +LIB_EXT = .a +APP_EXT = +
--- a/windows.mk Thu Sep 05 13:55:04 2013 +0200 +++ b/windows.mk Fri Sep 06 13:20:20 2013 +0200 @@ -29,7 +29,8 @@ CC = cl LD = link AR = lib -RM = rm +RM = del +MKDIR = mkdir CFLAGS = -c -TP -I../msc COFLAGS = -Fo @@ -37,9 +38,10 @@ LOFLAGS = -OUT: ARFLAGS = AOFLAGS = -OUT: -RMFLAGS = -f +RMFLAGS = /F /S /Q +MKDIRFLAGS = -OBJ_EXT = obj -LIB_EXT = lib +OBJ_EXT = .obj +LIB_EXT = .lib APP_EXT = .exe