Skip to content

Commit

Permalink
[v2.0.3][Issue #8] Added --without-sentinel configure option to disab…
Browse files Browse the repository at this point in the history
…le variadic argument sentinels
  • Loading branch information
Snaipe committed Jun 10, 2015
1 parent 287664d commit 76b65f4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
!configure.ac
!autogen.sh

src/config.h
include/csptr/config.h
*~
*.swp
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ([2.60])

AC_INIT([csptr], [2.0.1], [], [csptr], [[email protected]])
AC_INIT([csptr], [2.0.3], [], [csptr], [[email protected]])
AC_CONFIG_SRCDIR([src/mman.c])

LT_PREREQ([2.2.4])
Expand Down Expand Up @@ -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])],
Expand All @@ -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
22 changes: 19 additions & 3 deletions include/csptr/smalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@

# include <stdlib.h>

# 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,
Expand All @@ -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;
Expand All @@ -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_ */
8 changes: 4 additions & 4 deletions include/csptr/smart_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ 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 { \
const void *ptr; \
size_t size; \
} meta; \
} args = { \
.sentinel_ = 0, \
CSPTR_SENTINEL \
Args \
}; \
const __typeof__(Type[1]) dummy; \
Expand All @@ -65,15 +65,15 @@ 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 { \
const void *ptr; \
size_t size; \
} meta; \
} args = { \
.sentinel_ = 0, \
CSPTR_SENTINEL \
Args \
}; \
void *var = smalloc(sizeof (Type), Length, Kind, ARGS_); \
Expand Down
1 change: 0 additions & 1 deletion src/mman.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <string.h>
#include <assert.h>

#include "config.h"
#include "mman.h"
#include "array.h"
#undef smalloc
Expand Down

0 comments on commit 76b65f4

Please sign in to comment.