libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

commit b1f4c622db4eb643b14aa7f8520fbc27c8160d46
parent bd7b119ba110622815d1bfca2ed8ac7097274098
Author: Remy Noulin <loader2x@gmail.com>
Date:   Fri,  6 Sep 2019 10:45:10 +0200

compile libsheepyMemcheck with container recycling disabled for memcheck tests, add MACRO and FUNC macros, add is, equals, shr, shr ic, dec, ptr_to and val_of defines

.gitignore                |  2 ++
buildMemcheck.sh          | 32 ++++++++++++++++++++++++++++++++
buildMuslMemcheck.sh      | 32 ++++++++++++++++++++++++++++++++
clean.sh                  |  2 +-
cleanObjects.sh           |  2 ++
homeMake.sh               |  9 ++++++---
install.sh                |  2 ++
make.sh                   |  3 +++
release/libsheepy.c       |  2 +-
release/libsheepy.h       | 36 ++++++++++++++++++++++++++++++++++++
release/libsheepyObject.h |  4 +++-
src/libsheepy.c           |  2 +-
src/libsheepy.h           | 36 ++++++++++++++++++++++++++++++++++++
src/libsheepyObject.h     |  4 +++-
14 files changed, 160 insertions(+), 8 deletions(-)

Diffstat:
M.gitignore | 2++
AbuildMemcheck.sh | 32++++++++++++++++++++++++++++++++
AbuildMuslMemcheck.sh | 32++++++++++++++++++++++++++++++++
Mclean.sh | 2+-
AcleanObjects.sh | 2++
MhomeMake.sh | 9++++++---
Minstall.sh | 2++
Mmake.sh | 3+++
Mrelease/libsheepy.c | 2+-
Mrelease/libsheepy.h | 36++++++++++++++++++++++++++++++++++++
Mrelease/libsheepyObject.h | 4+++-
Msrc/libsheepy.c | 2+-
Msrc/libsheepy.h | 36++++++++++++++++++++++++++++++++++++
Msrc/libsheepyObject.h | 4+++-
14 files changed, 160 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -50,6 +50,8 @@ doxygen/doxygen/* example/demoStatic release/libsheepy.a release/libsheepy.so +release/libsheepyMemcheck.a +release/libsheepyMemcheck.so src/json/ar.log src/json/demoDynamic src/json/demoStatic diff --git a/buildMemcheck.sh b/buildMemcheck.sh @@ -0,0 +1,32 @@ +# compile libsheepy without recycling (see libsheepyObject.h for more information) + +CC="gcc -g3 -std=gnu99 -fPIC -pipe -mrdrnd -pthread -DrecycleContainers=0" +STATIC="ar -cvq" +DYNAMIC="-shared" + +echo "Compiling C files" +$CC -c release/libsheepy.c +$CC -c release/libsheepySmall.c +$CC -c src/json/libsheepyObject.c +$CC -c src/json/libsheepyCSmallJson.c +$CC -c src/json/libsheepyCUndefined.c +$CC -c src/json/libsheepyCSmallDict.c +$CC -c src/json/libsheepyCSmallArray.c +$CC -c src/json/libsheepyCSmallBytes.c +$CC -c src/json/libsheepyCSmallBool.c +$CC -c src/json/libsheepyCSmallContainer.c +$CC -c src/json/libsheepyCSmallDouble.c +$CC -c src/json/libsheepyCSmallInt.c +$CC -c src/json/libsheepyCSmallString.c +$CC -c src/json/laxjson.c +$CC -c src/json/ymlParser.c +$CC -c src/json/ymlApi.c +$CC -c src/json/ymlScanner.c +$CC -c src/json/ymlReader.c +$CC -c src/tpool.c + +echo "Building static lib" +$STATIC release/libsheepyMemcheck.a libsheepy.o libsheepySmall.o libsheepyObject.o libsheepyCSmallJson.o libsheepyCUndefined.o libsheepyCSmallDict.o libsheepyCSmallArray.o libsheepyCSmallBytes.o libsheepyCSmallBool.o libsheepyCSmallContainer.o libsheepyCSmallDouble.o libsheepyCSmallInt.o libsheepyCSmallString.o laxjson.o ymlParser.o ymlApi.o ymlScanner.o ymlReader.o tpool.o + +echo "Building dynamic lib" +$CC $DYNAMIC -o release/libsheepyMemcheck.so release/libsheepy.c release/libsheepySmall.c src/json/libsheepyObject.c src/json/libsheepyCSmallJson.c src/json/libsheepyCUndefined.c src/json/libsheepyCSmallDict.c src/json/libsheepyCSmallArray.c src/json/libsheepyCSmallBytes.c src/json/libsheepyCSmallBool.c src/json/libsheepyCSmallContainer.c src/json/libsheepyCSmallDouble.c src/json/libsheepyCSmallInt.c src/json/libsheepyCSmallString.c src/json/laxjson.c src/json/ymlParser.c src/json/ymlApi.c src/json/ymlScanner.c src/json/ymlReader.c src/tpool.c diff --git a/buildMuslMemcheck.sh b/buildMuslMemcheck.sh @@ -0,0 +1,32 @@ +# compile libsheepy without recycling (see libsheepyObject.h for more information) + +CC="gcc -g3 -std=gnu99 -fPIC -pipe -mrdrnd -pthread -specs /usr/local/musl/lib/musl-gcc.specs -DMUSL_LIBC=1 -DrecycleContainers=0" +STATIC="ar -cvq" +DYNAMIC="-shared" + +echo "Compiling C files" +$CC -c release/libsheepy.c +$CC -c release/libsheepySmall.c +$CC -c src/json/libsheepyObject.c +$CC -c src/json/libsheepyCSmallJson.c +$CC -c src/json/libsheepyCUndefined.c +$CC -c src/json/libsheepyCSmallDict.c +$CC -c src/json/libsheepyCSmallArray.c +$CC -c src/json/libsheepyCSmallBytes.c +$CC -c src/json/libsheepyCSmallBool.c +$CC -c src/json/libsheepyCSmallContainer.c +$CC -c src/json/libsheepyCSmallDouble.c +$CC -c src/json/libsheepyCSmallInt.c +$CC -c src/json/libsheepyCSmallString.c +$CC -c src/json/laxjson.c +$CC -c src/json/ymlParser.c +$CC -c src/json/ymlApi.c +$CC -c src/json/ymlScanner.c +$CC -c src/json/ymlReader.c +$CC -c src/tpool.c + +echo "Building static lib" +$STATIC release/libsheepyMemcheck.a libsheepy.o libsheepySmall.o libsheepyObject.o libsheepyCSmallJson.o libsheepyCUndefined.o libsheepyCSmallDict.o libsheepyCSmallArray.o libsheepyCSmallBytes.o libsheepyCSmallBool.o libsheepyCSmallContainer.o libsheepyCSmallDouble.o libsheepyCSmallInt.o libsheepyCSmallString.o laxjson.o ymlParser.o ymlApi.o ymlScanner.o ymlReader.o tpool.o + +echo "Building dynamic lib" +$CC $DYNAMIC -o release/libsheepyMemcheck.so release/libsheepy.c release/libsheepySmall.c src/json/libsheepyObject.c src/json/libsheepyCSmallJson.c src/json/libsheepyCUndefined.c src/json/libsheepyCSmallDict.c src/json/libsheepyCSmallArray.c src/json/libsheepyCSmallBytes.c src/json/libsheepyCSmallBool.c src/json/libsheepyCSmallContainer.c src/json/libsheepyCSmallDouble.c src/json/libsheepyCSmallInt.c src/json/libsheepyCSmallString.c src/json/laxjson.c src/json/ymlParser.c src/json/ymlApi.c src/json/ymlScanner.c src/json/ymlReader.c src/tpool.c diff --git a/clean.sh b/clean.sh @@ -1 +1 @@ -rm libsheepy.o libsheepySmall.o libsheepyObject.o libsheepyCSmallJson.o libsheepyCUndefined.o libsheepyCSmallDict.o libsheepyCSmallArray.o libsheepyCSmallBytes.o libsheepyCSmallBool.o libsheepyCSmallContainer.o libsheepyCSmallDouble.o libsheepyCSmallInt.o libsheepyCSmallString.o laxjson.o ymlParser.o ymlApi.o ymlScanner.o ymlReader.o tpool.o release/libsheepy.a release/libsheepy.so +rm libsheepy.o libsheepySmall.o libsheepyObject.o libsheepyCSmallJson.o libsheepyCUndefined.o libsheepyCSmallDict.o libsheepyCSmallArray.o libsheepyCSmallBytes.o libsheepyCSmallBool.o libsheepyCSmallContainer.o libsheepyCSmallDouble.o libsheepyCSmallInt.o libsheepyCSmallString.o laxjson.o ymlParser.o ymlApi.o ymlScanner.o ymlReader.o tpool.o release/libsheepy.a release/libsheepy.so release/libsheepyMemcheck.a release/libsheepyMemcheck.so diff --git a/cleanObjects.sh b/cleanObjects.sh @@ -0,0 +1,2 @@ +# clean objects only, keep libsheepy.a and .so, because libsheepyMemcheck is built after libsheepy with recycling +rm libsheepy.o libsheepySmall.o libsheepyObject.o libsheepyCSmallJson.o libsheepyCUndefined.o libsheepyCSmallDict.o libsheepyCSmallArray.o libsheepyCSmallBytes.o libsheepyCSmallBool.o libsheepyCSmallContainer.o libsheepyCSmallDouble.o libsheepyCSmallInt.o libsheepyCSmallString.o laxjson.o ymlParser.o ymlApi.o ymlScanner.o ymlReader.o tpool.o diff --git a/homeMake.sh b/homeMake.sh @@ -5,6 +5,9 @@ gcc -o genMake genMake.c rm genMake ./clean.sh ./build.sh +echo Building libsheepy without container recycling for memcheck +./cleanObjects.sh +./buildMemcheck.sh #./install.sh # compiling using make: @@ -16,7 +19,7 @@ git checkout Makefile git checkout build.sh echo Add this line in your startup script: -echo export LIBSHEEPY=`cd release && pwd` +echo export LIBSHEEPY=`cd release` echo or -echo setenv LIBSHEEPY `cd release && pwd` -export LIBSHEEPY=`cd release && pwd` +echo setenv LIBSHEEPY `cd release` +export LIBSHEEPY=`cd release` diff --git a/install.sh b/install.sh @@ -5,3 +5,5 @@ cp release/tpool.h /usr/local/include/ cp -R release/json /usr/local/include/ cp release/libsheepy.a /usr/local/lib/ cp release/libsheepy.so /usr/local/lib/ +cp release/libsheepyMemcheck.a /usr/local/lib/ +cp release/libsheepyMemcheck.so /usr/local/lib/ diff --git a/make.sh b/make.sh @@ -3,6 +3,9 @@ gcc -o genMake genMake.c rm genMake ./clean.sh ./build.sh +echo Building libsheepy without container recycling for memcheck +./cleanObjects.sh +./buildMemcheck.sh ./install.sh # compiling using make: diff --git a/release/libsheepy.c b/release/libsheepy.c @@ -1383,7 +1383,7 @@ void initLibsheepyF(const char *progPath, initLibsheepyObjectP initF) { // no buffering if output is sent to file, this makes everything // a bit slower, but it is possible to see where the code fails - if (!isatty(1)) { + if (!isatty(STDOUT_FILENO)) { setbuf(stdout, NULL); } diff --git a/release/libsheepy.h b/release/libsheepy.h @@ -169,6 +169,42 @@ extern const bool FALSE; #define funcend }) /** + * do while(0) alternative macro definition + * + * #define macro(param) MACRO( logVarG(param) ) + */ +#define MACRO( STATEMENTS ) do { STATEMENTS } while(0) + +/** + * Macro returning a value (GNU extension): + * #define macro(value) FUNC(\ + * int returnResult = value + 2;\ + * returnResult;\ + * ) + * + */ +#define FUNC( STATEMENTS) ({ STATEMENTS }) + +/** additions to iso646 + * int a is 0; + * if (a equals 1 or a equals 2) a shl = 2; + * else a inc; + * return ptr_to a; + * + * int *b is &a; + * val_of b is a; + * val_of b dec; + */ +#define is = +#define equals == +#define shr >> +#define shl << +#define inc ++ +#define dec -- +#define ptr_to & +#define val_of * + +/** * stringify Expression - Turn expression into a string literal * * Example: diff --git a/release/libsheepyObject.h b/release/libsheepyObject.h @@ -62,7 +62,7 @@ static const bool checkObjectTypes = true; // the containers are recycled when initiateAllocate is called after a finishO // // When debugging container leaks, disable recycleContainers to make to easier to the -// source of the leak +// source of the leak by defining recycleContainers to 0 // // 180814 the performance gain is about 14% for a program using the iter iterator // (debian stretch kaby lake linux 4.9, gcc 6.3, glibc 2.24) @@ -76,7 +76,9 @@ static const bool checkObjectTypes = true; // New classes have to register their finalizeRecycle functions with // registerFinalizeRecycleContainersInThreadPool before the program exits // to avoid memory leaks +#ifndef recycleContainers #define recycleContainers 1 +#endif #define recycleContainersAmount 8 // debug option: stack check in finish functions (for *NFree functions) diff --git a/src/libsheepy.c b/src/libsheepy.c @@ -1439,7 +1439,7 @@ void initLibsheepyF(const char *progPath, initLibsheepyObjectP initF) { // no buffering if output is sent to file, this makes everything // a bit slower, but it is possible to see where the code fails - if (!isatty(1)) { + if (!isatty(STDOUT_FILENO)) { setbuf(stdout, NULL); } diff --git a/src/libsheepy.h b/src/libsheepy.h @@ -169,6 +169,42 @@ extern const bool FALSE; #define funcend }) /** + * do while(0) alternative macro definition + * + * #define macro(param) MACRO( logVarG(param) ) + */ +#define MACRO( STATEMENTS ) do { STATEMENTS } while(0) + +/** + * Macro returning a value (GNU extension): + * #define macro(value) FUNC(\ + * int returnResult = value + 2;\ + * returnResult;\ + * ) + * + */ +#define FUNC( STATEMENTS) ({ STATEMENTS }) + +/** additions to iso646 + * int a is 0; + * if (a equals 1 or a equals 2) a shl = 2; + * else a inc; + * return ptr_to a; + * + * int *b is &a; + * val_of b is a; + * val_of b dec; + */ +#define is = +#define equals == +#define shr >> +#define shl << +#define inc ++ +#define dec -- +#define ptr_to & +#define val_of * + +/** * stringify Expression - Turn expression into a string literal * * Example: diff --git a/src/libsheepyObject.h b/src/libsheepyObject.h @@ -62,7 +62,7 @@ static const bool checkObjectTypes = true; // the containers are recycled when initiateAllocate is called after a finishO // // When debugging container leaks, disable recycleContainers to make to easier to the -// source of the leak +// source of the leak by defining recycleContainers to 0 // // 180814 the performance gain is about 14% for a program using the iter iterator // (debian stretch kaby lake linux 4.9, gcc 6.3, glibc 2.24) @@ -76,7 +76,9 @@ static const bool checkObjectTypes = true; // New classes have to register their finalizeRecycle functions with // registerFinalizeRecycleContainersInThreadPool before the program exits // to avoid memory leaks +#ifndef recycleContainers #define recycleContainers 1 +#endif #define recycleContainersAmount 8 // debug option: stack check in finish functions (for *NFree functions)