mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-07 05:39:39 +00:00
Add support for the clang compiler; update RAII_VAR to use BlocksRuntime
RAII_VAR, which is used extensively in Asterisk to manage reference counted resources, uses a GCC extension to automatically invoke a cleanup function when a variable loses scope. While this functionality is incredibly useful and has prevented a large number of memory leaks, it also prevents Asterisk from being compiled with clang. This patch updates the RAII_VAR macro such that it can be compiled with clang. It makes use of the BlocksRuntime, which allows for a closure to be created that performs the actual cleanup. Note that this does not attempt to address the numerous warnings that the clang compiler catches in Asterisk. Much thanks for this patch goes to: * The folks on StackOverflow who asked this question and Leushenko for providing the answer that formed the basis of this code: http://stackoverflow.com/questions/24959440/rewrite-gcc-cleanup-macro-with-nested-function-for-clang * Diederik de Groot, who has been extremely patient in working on getting this patch into Asterisk. Review: https://reviewboard.asterisk.org/r/4370/ ASTERISK-24133 ASTERISK-23666 ASTERISK-20399 ASTERISK-20850 #close Reported by: Diederik de Groot patches: RAII_CLANG.patch uploaded by Diederik de Groot (License 6600) ........ Merged revisions 432807 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@432808 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -25,12 +25,14 @@
|
||||
Small API functions that are candidates for inlining need to be specially
|
||||
declared and defined, to ensure that the 'right thing' always happens.
|
||||
For example:
|
||||
- there must _always_ be a non-inlined version of the function
|
||||
- there must _always_ be a non-inlined version of the function
|
||||
available for modules compiled out of the tree to link to
|
||||
- references to a function that cannot be inlined (for any
|
||||
reason that the compiler deems proper) must devolve into an
|
||||
'extern' reference, instead of 'static', so that multiple
|
||||
copies of the function body are not built in different modules
|
||||
copies of the function body are not built in different modules.
|
||||
However, since this doesn't work for clang, we go with 'static'
|
||||
anyway and hope for the best!
|
||||
- when LOW_MEMORY is defined, inlining should be disabled
|
||||
completely, even if the compiler is configured to support it
|
||||
|
||||
@@ -46,8 +48,12 @@
|
||||
#if !defined(LOW_MEMORY) && !defined(DISABLE_INLINE)
|
||||
|
||||
#if !defined(AST_API_MODULE)
|
||||
#if defined(__clang__)
|
||||
#define AST_INLINE_API(hdr, body) static hdr; static inline hdr body
|
||||
#else /* if defined(__clang__) */
|
||||
#define AST_INLINE_API(hdr, body) hdr; extern inline hdr body
|
||||
#else
|
||||
#endif
|
||||
#else /* if !defined(AST_API_MODULE) */
|
||||
#define AST_INLINE_API(hdr, body) hdr; hdr body
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user