]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
astobj2: Add an ao2_replace macro to astobj2.h
authorGeorge Joseph <george.joseph@fairview5.com>
Sun, 22 Jun 2014 18:44:23 +0000 (18:44 +0000)
committerGeorge Joseph <george.joseph@fairview5.com>
Sun, 22 Jun 2014 18:44:23 +0000 (18:44 +0000)
This macro replaces one object reference with another cleaning up the original.

param dst Pointer to the object that will be cleaned up.
param src Pointer to the object replacing it.

src's ref count is bumped if it's non-NULL.
dst's ref count is decremented if it's non-NULL.
src is assigned to dst,

This patch was reviewed on IRC by coreyfarrell and mjordan.

Tested by: George Joseph

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@416995 65c4cc65-6c06-0410-ace0-fbb531ad65f3

Makefile
Makefile.rules
include/asterisk/astobj2.h

index 3d7f49b5d9c243bc42d14ab3dd5c07a5a634f4d2..143d7db879304636422e9560c792091331c6102f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -188,7 +188,6 @@ ifeq ($(AST_DEVMODE),yes)
   _ASTCFLAGS+=-Werror
   _ASTCFLAGS+=-Wunused
   _ASTCFLAGS+=$(AST_DECLARATION_AFTER_STATEMENT)
-  _ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
   _ASTCFLAGS+=$(AST_TRAMPOLINES)
   _ASTCFLAGS+=-Wundef
   _ASTCFLAGS+=-Wmissing-format-attribute
index 35f522ed026b55e11a5807435b9f59abc9a64766..815038117f7c35016cdce5db070b2587f9cddf5d 100644 (file)
@@ -82,6 +82,8 @@ CXX_LIBS=$(PTHREAD_LIBS) $(LIBS)
 # and if that doesn't fail then compile again with optimizer disabled
 ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_DEVMODE),DONT_OPTIMIZEyes)
 COMPILE_DOUBLE=yes
+else
+_ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
 endif
 
 ifeq ($(findstring BUILD_NATIVE,$(MENUSELECT_CFLAGS)),BUILD_NATIVE)
index d113cb38cdb349eabfee2a528b345f70aca42363..d1c75ff5f07782529f1bae2f6ccd846802da73fb 100644 (file)
@@ -550,6 +550,26 @@ unsigned int ao2_options_get(void *obj);
 int __ao2_ref_debug(void *o, int delta, const char *tag, const char *file, int line, const char *func);
 int __ao2_ref(void *o, int delta);
 
+/*!
+ * \since 12.4.0
+ * \brief Replace one object reference with another cleaning up the original.
+ *
+ * \param dst Pointer to the object that will be cleaned up.
+ * \param src Pointer to the object replacing it.
+ */
+#define ao2_replace(dst, src) \
+       {\
+               typeof(dst) *__dst_ ## __LINE__ = &dst; \
+               typeof(src) __src_ ## __LINE__ = src; \
+               if (__src_ ## __LINE__) {\
+                       ao2_ref(__src_ ## __LINE__, +1); \
+               } \
+               if (*__dst_ ## __LINE__) {\
+                       ao2_ref(*__dst_ ## __LINE__, -1); \
+               } \
+               *__dst_ ## __LINE__ = __src_ ## __LINE__; \
+       }
+
 /*! @} */
 
 /*! \brief Which lock to request. */