Low: further avoid magic in qblog.h by using named constants

Also advise to use these constants and obey this in the internal code.
This commit is contained in:
Jan Pokorný 2016-03-04 14:55:52 +01:00
parent 9b6783568a
commit 9d696f5f5a
No known key found for this signature in database
GPG Key ID: 61BBB23A9E8F8DE2
2 changed files with 18 additions and 9 deletions

View File

@ -257,13 +257,22 @@ typedef void (*qb_log_filter_fn)(struct qb_log_callsite * cs);
* https://sourceware.org/binutils/docs/ld/Orphan-Sections.html
*/
#ifdef QB_HAVE_ATTRIBUTE_SECTION
extern struct qb_log_callsite __start___verbose[];
extern struct qb_log_callsite __stop___verbose[];
#define QB_ATTR_SECTION __verbose /* conforms to C ident. */
#define QB_ATTR_SECTION_STR QB_PP_STRINGIFY(QB_ATTR_SECTION)
#define QB_ATTR_SECTION_START QB_PP_JOIN(__start_, QB_ATTR_SECTION)
#define QB_ATTR_SECTION_STOP QB_PP_JOIN(__stop_, QB_ATTR_SECTION)
#define QB_ATTR_SECTION_START_STR QB_PP_STRINGIFY(QB_ATTR_SECTION_START)
#define QB_ATTR_SECTION_STOP_STR QB_PP_STRINGIFY(QB_ATTR_SECTION_STOP)
extern struct qb_log_callsite QB_ATTR_SECTION_START[];
extern struct qb_log_callsite QB_ATTR_SECTION_STOP[];
/* mere linker sanity check, possible future extension for internal purposes */
#define QB_LOG_INIT_DATA(name) \
void name(void); \
void name(void) { if (__start___verbose == __stop___verbose) assert(0); } \
void name(void) \
{ if (QB_ATTR_SECTION_START == QB_ATTR_SECTION_STOP) assert(0); } \
void __attribute__ ((constructor)) name(void);
#else
#define QB_LOG_INIT_DATA(name)
@ -348,7 +357,7 @@ void qb_log_from_external_source_va(const char *function,
#ifdef QB_HAVE_ATTRIBUTE_SECTION
#define qb_logt(priority, tags, fmt, args...) do { \
static struct qb_log_callsite descriptor \
__attribute__((section("__verbose"), aligned(8))) = \
__attribute__((section(QB_ATTR_SECTION_STR), aligned(8))) = \
{ __func__, __FILE__, fmt, priority, __LINE__, 0, tags }; \
qb_log_real_(&descriptor, ##args); \
} while(0)
@ -509,8 +518,8 @@ void qb_log_fini(void);
* you will need to do the following to get the filters to work
* in that module:
* @code
* _start = dlsym (dl_handle, "__start___verbose");
* _stop = dlsym (dl_handle, "__stop___verbose");
* _start = dlsym (dl_handle, QB_ATTR_SECTION_START_STR);
* _stop = dlsym (dl_handle, QB_ATTR_SECTION_STOP_STR);
* qb_log_callsites_register(_start, _stop);
* @endcode
*/

View File

@ -800,13 +800,13 @@ _log_so_walk_dlnames(void)
goto done;
}
start = dlsym(handle, "__start___verbose");
start = dlsym(handle, QB_ATTR_SECTION_START_STR);
error = dlerror();
if (error) {
goto done;
}
stop = dlsym(handle, "__stop___verbose");
stop = dlsym(handle, QB_ATTR_SECTION_STOP_STR);
error = dlerror();
if (error) {
goto done;
@ -868,7 +868,7 @@ qb_log_init(const char *name, int32_t facility, uint8_t priority)
qb_log_dcs_init();
#ifdef QB_HAVE_ATTRIBUTE_SECTION
qb_log_callsites_register(__start___verbose, __stop___verbose);
qb_log_callsites_register(QB_ATTR_SECTION_START, QB_ATTR_SECTION_STOP);
dl_iterate_phdr(_log_so_walk_callback, NULL);
_log_so_walk_dlnames();
#endif /* QB_HAVE_ATTRIBUTE_SECTION */