Skip to content

Commit

Permalink
Only use __attribute__((constructor)) if supported (#66)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bgilbert authored Oct 3, 2023
1 parent 15047d6 commit d7877f7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
7 changes: 0 additions & 7 deletions include/dicom/dicom.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
#define DCM_EXTERN __attribute__((visibility("default"))) extern
#endif

#ifdef HAS_CONSTRUCTOR
#define DCM_CONSTRUCTOR __attribute__ ((constructor))
#else
#define DCM_CONSTRUCTOR __attribute__ ((constructor))
#endif

/**
* Maximum number of characters in values with Value Representation AE.
*/
Expand Down Expand Up @@ -132,7 +126,6 @@ typedef struct _DcmSequence DcmSequence;
* This function can be called many times.
*/
DCM_EXTERN
DCM_CONSTRUCTOR
void dcm_init(void);

/* Our copy of getopt, since non-glibc platforms are missing this.
Expand Down
8 changes: 1 addition & 7 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ if cc.has_header('unistd.h')
cfg.set('HAVE_UNISTD_H', '1')
endif
# we use a constructor attr for dcm_init()
code = '''#include<stdio.h>
__attribute__ ((constructor)) void func() { printf("constructor\n"); }
'''
cfg.set(
'HAS_CONSTRUCTOR',
cc.compiles(code, name : 'has constructor attribute')
)
cfg.set('HAS_CONSTRUCTOR', cc.has_function_attribute('constructor'))

configure_file(
output : 'config.h',
Expand Down
3 changes: 3 additions & 0 deletions src/dicom-dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -5083,6 +5083,9 @@ static struct _DcmAttribute_hash_entry *attribute_from_tag_dict = NULL;
static struct _DcmAttribute_hash_entry *attribute_from_keyword_dict = NULL;


#ifdef HAS_CONSTRUCTOR
__attribute__ ((constructor))
#endif
void dcm_init(void)
{
if (!vrtable_from_str_dict) {
Expand Down

0 comments on commit d7877f7

Please sign in to comment.