From 76b65f4e5884e3df480aba580b3ae83cd0e32675 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Wed, 10 Jun 2015 11:46:13 +0200 Subject: [PATCH] [v2.0.3][Issue #8] Added --without-sentinel configure option to disable variadic argument sentinels --- .gitignore | 2 +- Makefile.am | 1 + configure.ac | 11 +++++++++-- include/csptr/smalloc.h | 22 +++++++++++++++++++--- include/csptr/smart_ptr.h | 8 ++++---- src/mman.c | 1 - 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 76f5241..1f6196c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,6 @@ !configure.ac !autogen.sh -src/config.h +include/csptr/config.h *~ *.swp diff --git a/Makefile.am b/Makefile.am index 2d4d3da..af53ba2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,7 @@ EXTRA_DIST = LICENSE README.md subdirincludedir = $(includedir)/csptr/ subdirinclude_HEADERS = \ + include/csptr/config.h \ include/csptr/smalloc.h \ include/csptr/array.h \ include/csptr/smart_ptr.h diff --git a/configure.ac b/configure.ac index 952c8be..59a7234 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.60]) -AC_INIT([csptr], [2.0.1], [], [csptr], [franklinmathieu@gmail.com]) +AC_INIT([csptr], [2.0.3], [], [csptr], [franklinmathieu@gmail.com]) AC_CONFIG_SRCDIR([src/mman.c]) LT_PREREQ([2.2.4]) @@ -35,6 +35,13 @@ AC_ARG_WITH([fixed-allocator], [AC_DEFINE([SMALLOC_FIXED_ALLOCATOR], [1], [Define if malloc should always be used.])], []) +AC_ARG_WITH([sentinel], + AS_HELP_STRING([--without-sentinel], [Disable the sentinel used for variadic function arguments])) + +AS_IF([test "x$with_sentinel" = "xno"], [ + AC_DEFINE([CSPTR_NO_SENTINEL], [1], [Define if a sentinel should not be used for variadic function arguments.]) +]) + AC_ARG_ENABLE([gcov], [AS_HELP_STRING([--enable-gcov], [Compile the project with converage enabled])], @@ -56,7 +63,7 @@ case "`uname`" in ;; esac -AC_CONFIG_HEADERS([src/config.h]) +AC_CONFIG_HEADERS([include/csptr/config.h]) AC_CONFIG_FILES([Makefile check/Makefile]) AC_OUTPUT diff --git a/include/csptr/smalloc.h b/include/csptr/smalloc.h index 4eddb7e..a71e233 100644 --- a/include/csptr/smalloc.h +++ b/include/csptr/smalloc.h @@ -27,6 +27,22 @@ # include +# ifndef CSPTR_CONFIG_H_ +# define CSPTR_CONFIG_H_ +# include "config.h" +# endif + +# ifdef CSPTR_NO_SENTINEL +# ifndef __GNUC__ +# error Variadic structure sentinels can only be disabled on a compiler supporting GNU extensions +# endif +# define CSPTR_SENTINEL +# define CSPTR_SENTINEL_DEC +# else +# define CSPTR_SENTINEL .sentinel_ = 0, +# define CSPTR_SENTINEL_DEC int sentinel_; +# endif + enum pointer_kind { UNIQUE, SHARED, @@ -44,7 +60,7 @@ typedef struct { extern s_allocator smalloc_allocator; typedef struct { - int sentinel_; + CSPTR_SENTINEL_DEC size_t size; size_t nmemb; enum pointer_kind kind; @@ -62,7 +78,7 @@ __attribute__((malloc)) void *smalloc(s_smalloc_args *args); void sfree(void *ptr); -# define smalloc(...) \ - smalloc(&(s_smalloc_args) { .sentinel_ = 0, __VA_ARGS__ }) +# define smalloc(...) \ + smalloc(&(s_smalloc_args) { CSPTR_SENTINEL __VA_ARGS__ }) #endif /* !CSPTR_SMALLOC_H_ */ diff --git a/include/csptr/smart_ptr.h b/include/csptr/smart_ptr.h index 6e3bfd0..d9dd665 100644 --- a/include/csptr/smart_ptr.h +++ b/include/csptr/smart_ptr.h @@ -41,7 +41,7 @@ inline void sfree_stack(void *ptr) { # define smart_ptr(Kind, Type, Args...) \ ({ \ struct s_tmp { \ - int sentinel_; \ + CSPTR_SENTINEL_DEC \ __typeof__(Type) value; \ f_destructor dtor; \ struct { \ @@ -49,7 +49,7 @@ inline void sfree_stack(void *ptr) { size_t size; \ } meta; \ } args = { \ - .sentinel_ = 0, \ + CSPTR_SENTINEL \ Args \ }; \ const __typeof__(Type[1]) dummy; \ @@ -65,7 +65,7 @@ inline void sfree_stack(void *ptr) { # define smart_arr(Kind, Type, Length, Args...) \ ({ \ struct s_tmp { \ - int sentinel_; \ + CSPTR_SENTINEL_DEC \ __typeof__(__typeof__(Type)[Length]) value; \ f_destructor dtor; \ struct { \ @@ -73,7 +73,7 @@ inline void sfree_stack(void *ptr) { size_t size; \ } meta; \ } args = { \ - .sentinel_ = 0, \ + CSPTR_SENTINEL \ Args \ }; \ void *var = smalloc(sizeof (Type), Length, Kind, ARGS_); \ diff --git a/src/mman.c b/src/mman.c index 58d9b96..6c64403 100644 --- a/src/mman.c +++ b/src/mman.c @@ -28,7 +28,6 @@ #include #include -#include "config.h" #include "mman.h" #include "array.h" #undef smalloc