summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2014-06-22 18:53:26 +0000
committerGeorge Joseph <george.joseph@fairview5.com>2014-06-22 18:53:26 +0000
commit682357dced7caccaa7e11164bf2e3509acbd8c06 (patch)
tree65b44d2e057e555e4dce3bcdc5a3054b35284c57
parent1a6db55404907b937fc2258b46ab3a7d08b732e6 (diff)
astobj2: Add an ao2_replace macro to astobj2.h
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 ........ Merged revisions 416995 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416996 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--Makefile1
-rw-r--r--Makefile.rules2
-rw-r--r--include/asterisk/astobj2.h20
3 files changed, 22 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index b9057ee17..09bcb5b03 100644
--- 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
diff --git a/Makefile.rules b/Makefile.rules
index 35f522ed0..815038117 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -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)
diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h
index d113cb38c..d1c75ff5f 100644
--- a/include/asterisk/astobj2.h
+++ b/include/asterisk/astobj2.h
@@ -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. */