Index: main/Makefile =================================================================== --- main/Makefile (revision 413043) +++ main/Makefile (working copy) @@ -40,6 +40,7 @@ AST_LIBS+=$(URIPARSER_LIB) AST_LIBS+=$(UUID_LIB) AST_LIBS+=$(CRYPT_LIB) +AST_LIBS+=$(AST_CLANG_BLOCKS_LIBS) ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc kfreebsd-gnu),) ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),) Index: include/asterisk/utils.h =================================================================== --- include/asterisk/utils.h (revision 413043) +++ include/asterisk/utils.h (working copy) @@ -985,11 +985,32 @@ * } * \endcode */ -#define RAII_VAR(vartype, varname, initval, dtor) \ - /* Prototype needed due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36774 */ \ - auto void _dtor_ ## varname (vartype * v); \ - void _dtor_ ## varname (vartype * v) { dtor(*v); } \ + +//#define RAII_VAR(vartype, varname, initval, dtor) \ +// /* Prototype needed due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36774 */ \ +// auto void _dtor_ ## varname (vartype * v); \ +// void _dtor_ ## varname (vartype * v) { dtor(*v); } \ +// vartype varname __attribute__((cleanup(_dtor_ ## varname))) = (initval) +#ifndef __has_feature +#define __has_feature(f) 0 +#endif + +#if __has_feature(blocks) +typedef void (^_raii_cleanup_block_t)(void); +static inline void _raii_cleanup_block(_raii_cleanup_block_t *b) { (*b)(); } + +#define RAII_VAR(vartype, varname, initval, dtor) \ + _raii_cleanup_block_t _raii_cleanup_ ## varname __attribute__((cleanup(_raii_cleanup_block),unused)) = NULL; \ + vartype varname = initval; \ + _raii_cleanup_ ## varname = ^{ dtor(varname); } +#elif __GNUC__ +#define RAII_VAR(vartype, varname, initval, dtor) \ + auto void _dtor_ ## varname (vartype * v); \ + void _dtor_ ## varname (vartype * v) { dtor(*v); } \ vartype varname __attribute__((cleanup(_dtor_ ## varname))) = (initval) +#else + #warning "Your compiler is not supported" +#endif /*! * \brief Asterisk wrapper around crypt(3). Index: makeopts.in =================================================================== --- makeopts.in (revision 413043) +++ makeopts.in (working copy) @@ -108,6 +108,9 @@ AST_NO_STRICT_OVERFLOW=@AST_NO_STRICT_OVERFLOW@ AST_SHADOW_WARNINGS=@AST_SHADOW_WARNINGS@ AST_NESTED_FUNCTIONS=@AST_NESTED_FUNCTIONS@ +AST_CLANG_BLOCKS=@AST_CLANG_BLOCKS@ +AST_CLANG_BLOCKS_LIBS=@AST_CLANG_BLOCKS_LIBS@ +AST_CLANG_SILENCE_COMPILE_WARNINGS_UNTIL_FIXED=@AST_CLANG_SILENCE_COMPILE_WARNINGS_UNTIL_FIXED@ AST_RPATH=@AST_RPATH@ AST_FORTIFY_SOURCE=@AST_FORTIFY_SOURCE@ AST_MARCH_NATIVE=@AST_MARCH_NATIVE@ Index: configure.ac =================================================================== --- configure.ac (revision 413043) +++ configure.ac (working copy) @@ -1088,16 +1088,47 @@ AC_SUBST(AST_NATIVE_ARCH) dnl Nested functions required for RAII implementation -AC_MSG_CHECKING(for -fnested-functions) -AC_COMPILE_IFELSE( - dnl Prototype needed due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36774 - [AC_LANG_PROGRAM([], [auto void foo(void); void foo(void) {}])], - AC_MSG_RESULT(no) - [AST_NESTED_FUNCTIONS=], - AC_MSG_RESULT(required) - [AST_NESTED_FUNCTIONS=-fnested-functions] +AC_LINK_IFELSE( + [AC_LANG_PROGRAM([], + [ + #if defined(__clang__) + choke + #endif + int main(void) {return 0};]) + ],[ + dnl Nested functions required for RAII implementation + AC_MSG_CHECKING(for gcc -fnested-functions) + AC_COMPILE_IFELSE( + dnl Prototype needed due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36774 + [AC_LANG_PROGRAM([], [auto void foo(void); void foo(void) {}])], + dnl Warn about problems ahead + AC_MSG_RESULT(no) + [AST_NESTED_FUNCTIONS=], + AC_MSG_RESULT(required) + [AST_NESTED_FUNCTIONS=-fnested-functions] + ) + AC_SUBST(AST_NESTED_FUNCTIONS) + ],[ + AC_MSG_CHECKING(for clang -fblocks) + if test "`echo "int main(){return ^{return 42;}();}" | clang -o /dev/null -fblocks -x c - 2>&1`" = ""; then + [AST_CLANG_BLOCKS_LIBS=""] + [AST_CLANG_BLOCKS="-Wno-unknown-warning-option -fblocks"] + AC_MSG_RESULT(yes) + elif test "`echo "int main(){return ^{return 42;}();}" | clang -o /dev/null -fblocks -x c -lBlocksRuntime - 2>&1`" = ""; then + [AST_CLANG_BLOCKS_LIBS="-lBlocksRuntime"] + [AST_CLANG_BLOCKS="-fblocks"] + AC_MSG_RESULT(yes) + else + dnl Warn about problems ahead + [AST_CLANG_BLOCKS_LIBS=] + [AST_CLANG_BLOCKS=] + AC_MSG_RESULT(no) + fi + AC_SUBST(AST_CLANG_BLOCKS_LIBS) + AC_SUBST(AST_CLANG_BLOCKS) + AC_SUBST(AST_CLANG_SILENCE_COMPILE_WARNINGS_UNTIL_FIXED) + ] ) -AC_SUBST(AST_NESTED_FUNCTIONS) dnl Check to see if rpath should be set in LDFLAGS AC_ARG_ENABLE(rpath, Index: Makefile =================================================================== --- Makefile (revision 413043) +++ Makefile (working copy) @@ -181,7 +181,7 @@ _ASTCFLAGS+=-Wall endif -_ASTCFLAGS+=-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_NESTED_FUNCTIONS) $(DEBUG) +_ASTCFLAGS+=-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_NESTED_FUNCTIONS) $(AST_CLANG_BLOCKS) $(DEBUG) ADDL_TARGETS= ifeq ($(AST_DEVMODE),yes)