Skip to content

Commit d7877f7

Browse files
authored
Only use __attribute__((constructor)) if supported (#66)
* Only use __attribute__((constructor)) if supported The HAS_CONSTRUCTOR check didn't do anything, since we tried to use __attribute__((constructor)) whether it was defined or not. That caused a build failure on MSVC. Also, we shouldn't add the constructor attribute from a public header, since it's only relevant while building the library, and is conditioned on a config.h macro that isn't visible outside the library. Move constructor handling directly to the one call site that needs it. * meson: simplify constructor support check
1 parent 15047d6 commit d7877f7

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

include/dicom/dicom.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
#define DCM_EXTERN __attribute__((visibility("default"))) extern
2020
#endif
2121

22-
#ifdef HAS_CONSTRUCTOR
23-
#define DCM_CONSTRUCTOR __attribute__ ((constructor))
24-
#else
25-
#define DCM_CONSTRUCTOR __attribute__ ((constructor))
26-
#endif
27-
2822
/**
2923
* Maximum number of characters in values with Value Representation AE.
3024
*/
@@ -132,7 +126,6 @@ typedef struct _DcmSequence DcmSequence;
132126
* This function can be called many times.
133127
*/
134128
DCM_EXTERN
135-
DCM_CONSTRUCTOR
136129
void dcm_init(void);
137130

138131
/* Our copy of getopt, since non-glibc platforms are missing this.

meson.build

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,7 @@ if cc.has_header('unistd.h')
106106
cfg.set('HAVE_UNISTD_H', '1')
107107
endif
108108
# we use a constructor attr for dcm_init()
109-
code = '''#include<stdio.h>
110-
__attribute__ ((constructor)) void func() { printf("constructor\n"); }
111-
'''
112-
cfg.set(
113-
'HAS_CONSTRUCTOR',
114-
cc.compiles(code, name : 'has constructor attribute')
115-
)
109+
cfg.set('HAS_CONSTRUCTOR', cc.has_function_attribute('constructor'))
116110

117111
configure_file(
118112
output : 'config.h',

src/dicom-dict.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5083,6 +5083,9 @@ static struct _DcmAttribute_hash_entry *attribute_from_tag_dict = NULL;
50835083
static struct _DcmAttribute_hash_entry *attribute_from_keyword_dict = NULL;
50845084

50855085

5086+
#ifdef HAS_CONSTRUCTOR
5087+
__attribute__ ((constructor))
5088+
#endif
50865089
void dcm_init(void)
50875090
{
50885091
if (!vrtable_from_str_dict) {

0 commit comments

Comments
 (0)