[asterisk-commits] Change in asterisk[master]: Optional API: Fix handling of sources that are both provider...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 13 07:49:54 CDT 2015
Joshua Colp has submitted this change and it was merged.
Change subject: Optional API: Fix handling of sources that are both provider and user.
......................................................................
Optional API: Fix handling of sources that are both provider and user.
OPTIONAL_API has conditionals to define AST_OPTIONAL_API and
AST_OPTIONAL_API_ATTR differently based on if AST_API_MODULE is defined.
Unfortunately this is inside the include protection block, so only the
first status of AST_API_MODULE is respected. For example res_monitor
is an optional API provider, but uses func_periodic_hook. This makes
func_periodic_hook non-optional to res_monitor.
This changes optional_api.h so that AST_OPTIONAL_API and
AST_OPTIONAL_API_ATTR is redefined every time the header is included.
ASTERISK-17608 #close
Reported by: Warren Selby
Change-Id: I8fcf2a5e7b481893e17484ecde4f172c9ffb5679
---
M include/asterisk/optional_api.h
1 file changed, 54 insertions(+), 28 deletions(-)
Approvals:
Matt Jordan: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Verified
diff --git a/include/asterisk/optional_api.h b/include/asterisk/optional_api.h
index 394aed0..1118dc7 100644
--- a/include/asterisk/optional_api.h
+++ b/include/asterisk/optional_api.h
@@ -178,10 +178,7 @@
#define AST_OPTIONAL_API_NAME(name) __##name
-#if defined(AST_API_MODULE)
-/* Module defining the API */
-
-#define AST_OPTIONAL_API_IMPL_INIT(name) \
+#define AST_OPTIONAL_API_INIT_IMPL(name) \
static void __attribute__((constructor)) __init__##name##_impl(void) { \
ast_optional_api_provide(#name, \
(ast_optional_fn)AST_OPTIONAL_API_NAME(name)); \
@@ -191,22 +188,7 @@
(ast_optional_fn)AST_OPTIONAL_API_NAME(name)); \
}
-#define AST_OPTIONAL_API(result, name, proto, stub) \
- result AST_OPTIONAL_API_NAME(name) proto; \
- static attribute_unused typeof(AST_OPTIONAL_API_NAME(name)) * const \
- name = AST_OPTIONAL_API_NAME(name); \
- AST_OPTIONAL_API_IMPL_INIT(name)
-
-#define AST_OPTIONAL_API_ATTR(result, attr, name, proto, stub) \
- result __attribute__((attr)) AST_OPTIONAL_API_NAME(name) proto; \
- static attribute_unused typeof(AST_OPTIONAL_API_NAME(name)) * const \
- name = AST_OPTIONAL_API_NAME(name); \
- AST_OPTIONAL_API_IMPL_INIT(name)
-
-#else
-/* Module using the API */
-
-#define AST_OPTIONAL_API_INIT(name) \
+#define AST_OPTIONAL_API_INIT_USER(name) \
static void __attribute__((constructor)) __init__##name(void) { \
ast_optional_api_use(#name, (ast_optional_fn *)&name, \
(ast_optional_fn)__stub__##name, \
@@ -217,19 +199,31 @@
AST_MODULE); \
}
-#define AST_OPTIONAL_API(result, name, proto, stub) \
+#define AST_OPTIONAL_API_IMPL(result, name, proto, stub) \
+ result AST_OPTIONAL_API_NAME(name) proto; \
+ static attribute_unused typeof(AST_OPTIONAL_API_NAME(name)) * const \
+ name = AST_OPTIONAL_API_NAME(name); \
+ AST_OPTIONAL_API_INIT_IMPL(name)
+
+#define AST_OPTIONAL_API_USER(result, name, proto, stub) \
static result __stub__##name proto stub; \
static attribute_unused \
typeof(__stub__##name) * name; \
- AST_OPTIONAL_API_INIT(name)
+ AST_OPTIONAL_API_INIT_USER(name)
-#define AST_OPTIONAL_API_ATTR(result, attr, name, proto, stub) \
+
+/* AST_OPTIONAL_API_ATTR */
+#define AST_OPTIONAL_API_ATTR_IMPL(result, attr, name, proto, stub) \
+ result __attribute__((attr)) AST_OPTIONAL_API_NAME(name) proto; \
+ static attribute_unused typeof(AST_OPTIONAL_API_NAME(name)) * const \
+ name = AST_OPTIONAL_API_NAME(name); \
+ AST_OPTIONAL_API_INIT_IMPL(name)
+
+#define AST_OPTIONAL_API_ATTR_USER(result, attr, name, proto, stub) \
static __attribute__((attr)) result __stub__##name proto stub; \
static attribute_unused __attribute__((attr)) \
typeof(__stub__##name) * name; \
- AST_OPTIONAL_API_INIT(name)
-
-#endif /* defined(AST_API_MODULE) */
+ AST_OPTIONAL_API_INIT_USER(name)
#else /* defined(OPTIONAL_API) */
@@ -245,6 +239,38 @@
#endif /* defined(OPTIONAL_API) */
-#undef AST_API_MODULE
-
#endif /* __ASTERISK_OPTIONAL_API_H */
+
+/*
+ * Some Asterisk sources are both consumer and provider of optional API's. The
+ * following definitons are intentionally outside the include protected portion
+ * of this header so AST_OPTIONAL_API and AST_OPTIONAL_API_ATTR can be redefined
+ * each time the header is included. This also ensures that AST_API_MODULE is
+ * undefined after every include of this header.
+ */
+#if defined(OPTIONAL_API)
+
+#undef AST_OPTIONAL_API
+#undef AST_OPTIONAL_API_ATTR
+
+#if defined(AST_API_MODULE)
+
+#define AST_OPTIONAL_API(result, name, proto, stub) \
+ AST_OPTIONAL_API_IMPL(result, name, proto, stub)
+
+#define AST_OPTIONAL_API_ATTR(result, attr, name, proto, stub) \
+ AST_OPTIONAL_API_ATTR_IMPL(result, attr, name, proto, stub)
+
+#else
+
+#define AST_OPTIONAL_API(result, name, proto, stub) \
+ AST_OPTIONAL_API_USER(result, name, proto, stub)
+
+#define AST_OPTIONAL_API_ATTR(result, attr, name, proto, stub) \
+ AST_OPTIONAL_API_ATTR_USER(result, attr, name, proto, stub)
+
+#endif /* defined(AST_API_MODULE) */
+
+#endif /* defined(OPTIONAL_API) */
+
+#undef AST_API_MODULE
--
To view, visit https://gerrit.asterisk.org/73
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8fcf2a5e7b481893e17484ecde4f172c9ffb5679
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>
More information about the asterisk-commits
mailing list