Skip to content

Commit 76b65f4

Browse files
committed
[v2.0.3][Issue #8] Added --without-sentinel configure option to disable variadic argument sentinels
1 parent 287664d commit 76b65f4

6 files changed

Lines changed: 34 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
!configure.ac
1717
!autogen.sh
1818

19-
src/config.h
19+
include/csptr/config.h
2020
*~
2121
*.swp

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ EXTRA_DIST = LICENSE README.md
2222

2323
subdirincludedir = $(includedir)/csptr/
2424
subdirinclude_HEADERS = \
25+
include/csptr/config.h \
2526
include/csptr/smalloc.h \
2627
include/csptr/array.h \
2728
include/csptr/smart_ptr.h

configure.ac

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AC_PREREQ([2.60])
22

3-
AC_INIT([csptr], [2.0.1], [], [csptr], [franklinmathieu@gmail.com])
3+
AC_INIT([csptr], [2.0.3], [], [csptr], [franklinmathieu@gmail.com])
44
AC_CONFIG_SRCDIR([src/mman.c])
55

66
LT_PREREQ([2.2.4])
@@ -35,6 +35,13 @@ AC_ARG_WITH([fixed-allocator],
3535
[AC_DEFINE([SMALLOC_FIXED_ALLOCATOR], [1], [Define if malloc should always be used.])],
3636
[])
3737

38+
AC_ARG_WITH([sentinel],
39+
AS_HELP_STRING([--without-sentinel], [Disable the sentinel used for variadic function arguments]))
40+
41+
AS_IF([test "x$with_sentinel" = "xno"], [
42+
AC_DEFINE([CSPTR_NO_SENTINEL], [1], [Define if a sentinel should not be used for variadic function arguments.])
43+
])
44+
3845
AC_ARG_ENABLE([gcov],
3946
[AS_HELP_STRING([--enable-gcov],
4047
[Compile the project with converage enabled])],
@@ -56,7 +63,7 @@ case "`uname`" in
5663
;;
5764
esac
5865

59-
AC_CONFIG_HEADERS([src/config.h])
66+
AC_CONFIG_HEADERS([include/csptr/config.h])
6067
AC_CONFIG_FILES([Makefile check/Makefile])
6168

6269
AC_OUTPUT

include/csptr/smalloc.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@
2727

2828
# include <stdlib.h>
2929

30+
# ifndef CSPTR_CONFIG_H_
31+
# define CSPTR_CONFIG_H_
32+
# include "config.h"
33+
# endif
34+
35+
# ifdef CSPTR_NO_SENTINEL
36+
# ifndef __GNUC__
37+
# error Variadic structure sentinels can only be disabled on a compiler supporting GNU extensions
38+
# endif
39+
# define CSPTR_SENTINEL
40+
# define CSPTR_SENTINEL_DEC
41+
# else
42+
# define CSPTR_SENTINEL .sentinel_ = 0,
43+
# define CSPTR_SENTINEL_DEC int sentinel_;
44+
# endif
45+
3046
enum pointer_kind {
3147
UNIQUE,
3248
SHARED,
@@ -44,7 +60,7 @@ typedef struct {
4460
extern s_allocator smalloc_allocator;
4561

4662
typedef struct {
47-
int sentinel_;
63+
CSPTR_SENTINEL_DEC
4864
size_t size;
4965
size_t nmemb;
5066
enum pointer_kind kind;
@@ -62,7 +78,7 @@ __attribute__((malloc))
6278
void *smalloc(s_smalloc_args *args);
6379
void sfree(void *ptr);
6480

65-
# define smalloc(...) \
66-
smalloc(&(s_smalloc_args) { .sentinel_ = 0, __VA_ARGS__ })
81+
# define smalloc(...) \
82+
smalloc(&(s_smalloc_args) { CSPTR_SENTINEL __VA_ARGS__ })
6783

6884
#endif /* !CSPTR_SMALLOC_H_ */

include/csptr/smart_ptr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ inline void sfree_stack(void *ptr) {
4141
# define smart_ptr(Kind, Type, Args...) \
4242
({ \
4343
struct s_tmp { \
44-
int sentinel_; \
44+
CSPTR_SENTINEL_DEC \
4545
__typeof__(Type) value; \
4646
f_destructor dtor; \
4747
struct { \
4848
const void *ptr; \
4949
size_t size; \
5050
} meta; \
5151
} args = { \
52-
.sentinel_ = 0, \
52+
CSPTR_SENTINEL \
5353
Args \
5454
}; \
5555
const __typeof__(Type[1]) dummy; \
@@ -65,15 +65,15 @@ inline void sfree_stack(void *ptr) {
6565
# define smart_arr(Kind, Type, Length, Args...) \
6666
({ \
6767
struct s_tmp { \
68-
int sentinel_; \
68+
CSPTR_SENTINEL_DEC \
6969
__typeof__(__typeof__(Type)[Length]) value; \
7070
f_destructor dtor; \
7171
struct { \
7272
const void *ptr; \
7373
size_t size; \
7474
} meta; \
7575
} args = { \
76-
.sentinel_ = 0, \
76+
CSPTR_SENTINEL \
7777
Args \
7878
}; \
7979
void *var = smalloc(sizeof (Type), Length, Kind, ARGS_); \

src/mman.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <string.h>
2929
#include <assert.h>
3030

31-
#include "config.h"
3231
#include "mman.h"
3332
#include "array.h"
3433
#undef smalloc

0 commit comments

Comments
 (0)