Add API exported functions visibility control

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
This commit is contained in:
evpobr 2017-03-11 14:07:03 +05:00 committed by Erik de Castro Lopo
parent cfff3b5554
commit 1bff04b3ae
7 changed files with 137 additions and 3 deletions

View File

@ -1,5 +1,5 @@
## Process this file with automake to produce Makefile.in
EXTRA_DIST = add_cflags.m4 clip_mode.m4 endian.m4 \
flexible_array.m4 llrint.m4 lrint.m4 lrintf.m4 octave.m4 extra_pkg.m4
flexible_array.m4 llrint.m4 lrint.m4 lrintf.m4 octave.m4 extra_pkg.m4 visibility.m4

77
M4/visibility.m4 Normal file
View File

@ -0,0 +1,77 @@
# visibility.m4 serial 5 (gettext-0.18.2)
dnl Copyright (C) 2005, 2008, 2010-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Bruno Haible.
dnl Tests whether the compiler supports the command-line option
dnl -fvisibility=hidden and the function and variable attributes
dnl __attribute__((__visibility__("hidden"))) and
dnl __attribute__((__visibility__("default"))).
dnl Does *not* test for __visibility__("protected") - which has tricky
dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
dnl Mac OS X.
dnl Does *not* test for __visibility__("internal") - which has processor
dnl dependent semantics.
dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
dnl "really only recommended for legacy code".
dnl Set the variable CFLAG_VISIBILITY.
dnl Defines and sets the variable HAVE_VISIBILITY.
AC_DEFUN([gl_VISIBILITY],
[
AC_REQUIRE([AC_PROG_CC])
CFLAG_VISIBILITY=
HAVE_VISIBILITY=0
if test -n "$GCC"; then
dnl First, check whether -Werror can be added to the command line, or
dnl whether it leads to an error because of some other option that the
dnl user has put into $CC $CFLAGS $CPPFLAGS.
AC_MSG_CHECKING([whether the -Werror option is usable])
AC_CACHE_VAL([gl_cv_cc_vis_werror], [
gl_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[]], [[]])],
[gl_cv_cc_vis_werror=yes],
[gl_cv_cc_vis_werror=no])
CFLAGS="$gl_save_CFLAGS"])
AC_MSG_RESULT([$gl_cv_cc_vis_werror])
dnl Now check whether visibility declarations are supported.
AC_MSG_CHECKING([for simple visibility declarations])
AC_CACHE_VAL([gl_cv_cc_visibility], [
gl_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fvisibility=hidden"
dnl We use the option -Werror and a function dummyfunc, because on some
dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning
dnl "visibility attribute not supported in this configuration; ignored"
dnl at the first function definition in every compilation unit, and we
dnl don't want to use the option in this case.
if test $gl_cv_cc_vis_werror = yes; then
CFLAGS="$CFLAGS -Werror"
fi
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[extern __attribute__((__visibility__("hidden"))) int hiddenvar;
extern __attribute__((__visibility__("default"))) int exportedvar;
extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
extern __attribute__((__visibility__("default"))) int exportedfunc (void);
void dummyfunc (void) {}
]],
[[]])],
[gl_cv_cc_visibility=yes],
[gl_cv_cc_visibility=no])
CFLAGS="$gl_save_CFLAGS"])
AC_MSG_RESULT([$gl_cv_cc_visibility])
if test $gl_cv_cc_visibility = yes; then
CFLAG_VISIBILITY="-fvisibility=hidden"
HAVE_VISIBILITY=1
fi
fi
AC_SUBST([CFLAG_VISIBILITY])
AC_SUBST([HAVE_VISIBILITY])
AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY],
[Define to 1 or 0, depending whether the compiler supports simple visibility declarations.])
])

View File

@ -83,6 +83,8 @@ else
AM_CONDITIONAL([LINUX_MINGW_CROSS_TEST],
[test "$build_os:$target_os:$host_os:$HAVE_WINE" = "linux-gnu:mingw32msvc:mingw32msvc:yes"])
gl_VISIBILITY
#====================================================================================
# Couple of initializations here. Fill in real values later.

View File

@ -37,6 +37,9 @@ else
WIN_VERSION_FILE =
endif
libsndfile_la_CFLAGS = $(CFLAG_VISIBILITY)
libsndfile_la_CPPFLAGS = -DSNDFILE_EXPORTS
#===============================================================================
# MinGW requires -no-undefined if a DLL is to be built.
libsndfile_la_LDFLAGS = -no-undefined -version-info $(SHARED_VERSION_INFO) $(SHLIB_VERSION_ARG)

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -75,6 +75,17 @@
# define WARN_UNUSED
#endif
/*
** Visibility control
*/
#if defined (SNDFILE_EXPORTS) && !defined (_WIN32)
# define SNDFILE_API __attribute__ ((visibility ("default")))
#else
# define SNDFILE_API
#endif
#define SF_BUFFER_LEN (8192)
#define SF_FILENAME_LEN (1024)
#define SF_SYSERR_LEN (256)

View File

@ -319,6 +319,7 @@ static char sf_syserr [SF_SYSERR_LEN] = { 0 } ;
** Public functions.
*/
SNDFILE_API
SNDFILE*
sf_open (const char *path, int mode, SF_INFO *sfinfo)
{ SF_PRIVATE *psf ;
@ -349,6 +350,7 @@ sf_open (const char *path, int mode, SF_INFO *sfinfo)
return psf_open_file (psf, sfinfo) ;
} /* sf_open */
SNDFILE_API
SNDFILE*
sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc)
{ SF_PRIVATE *psf ;
@ -377,6 +379,7 @@ sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc)
return psf_open_file (psf, sfinfo) ;
} /* sf_open_fd */
SNDFILE_API
SNDFILE*
sf_open_virtual (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data)
{ SF_PRIVATE *psf ;
@ -416,6 +419,7 @@ sf_open_virtual (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user
return psf_open_file (psf, sfinfo) ;
} /* sf_open_virtual */
SNDFILE_API
int
sf_close (SNDFILE *sndfile)
{ SF_PRIVATE *psf ;
@ -425,6 +429,7 @@ sf_close (SNDFILE *sndfile)
return psf_close (psf) ;
} /* sf_close */
SNDFILE_API
void
sf_write_sync (SNDFILE *sndfile)
{ SF_PRIVATE *psf ;
@ -440,6 +445,7 @@ sf_write_sync (SNDFILE *sndfile)
/*==============================================================================
*/
SNDFILE_API
const char*
sf_error_number (int errnum)
{ static const char *bad_errnum =
@ -462,6 +468,7 @@ sf_error_number (int errnum)
return bad_errnum ;
} /* sf_error_number */
SNDFILE_API
const char*
sf_strerror (SNDFILE *sndfile)
{ SF_PRIVATE *psf = NULL ;
@ -490,6 +497,7 @@ sf_strerror (SNDFILE *sndfile)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
int
sf_error (SNDFILE *sndfile)
{ SF_PRIVATE *psf ;
@ -508,6 +516,7 @@ sf_error (SNDFILE *sndfile)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
int
sf_perror (SNDFILE *sndfile)
{ SF_PRIVATE *psf ;
@ -529,6 +538,7 @@ sf_perror (SNDFILE *sndfile)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
int
sf_error_str (SNDFILE *sndfile, char *str, size_t maxlen)
{ SF_PRIVATE *psf ;
@ -552,6 +562,7 @@ sf_error_str (SNDFILE *sndfile, char *str, size_t maxlen)
/*==============================================================================
*/
SNDFILE_API
int
sf_format_check (const SF_INFO *info)
{ int subformat, endian ;
@ -861,6 +872,7 @@ sf_format_check (const SF_INFO *info)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
const char *
sf_version_string (void)
{
@ -875,6 +887,7 @@ sf_version_string (void)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
int
sf_command (SNDFILE *sndfile, int command, void *data, int datasize)
{ SF_PRIVATE *psf = (SF_PRIVATE *) sndfile ;
@ -1375,6 +1388,7 @@ sf_command (SNDFILE *sndfile, int command, void *data, int datasize)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_seek (SNDFILE *sndfile, sf_count_t offset, int whence)
{ SF_PRIVATE *psf ;
@ -1493,6 +1507,7 @@ sf_seek (SNDFILE *sndfile, sf_count_t offset, int whence)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
const char*
sf_get_string (SNDFILE *sndfile, int str_type)
{ SF_PRIVATE *psf ;
@ -1505,6 +1520,7 @@ sf_get_string (SNDFILE *sndfile, int str_type)
return psf_get_string (psf, str_type) ;
} /* sf_get_string */
SNDFILE_API
int
sf_set_string (SNDFILE *sndfile, int str_type, const char* str)
{ SF_PRIVATE *psf ;
@ -1517,6 +1533,7 @@ sf_set_string (SNDFILE *sndfile, int str_type, const char* str)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
int
sf_current_byterate (SNDFILE *sndfile)
{ SF_PRIVATE *psf ;
@ -1561,6 +1578,7 @@ sf_current_byterate (SNDFILE *sndfile)
/*==============================================================================
*/
SNDFILE_API
sf_count_t
sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes)
{ SF_PRIVATE *psf ;
@ -1613,6 +1631,7 @@ sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t len)
{ SF_PRIVATE *psf ;
@ -1668,6 +1687,7 @@ sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t len)
return count ;
} /* sf_read_short */
SNDFILE_API
sf_count_t
sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames)
{ SF_PRIVATE *psf ;
@ -1721,6 +1741,7 @@ sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t len)
{ SF_PRIVATE *psf ;
@ -1776,6 +1797,7 @@ sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t len)
return count ;
} /* sf_read_int */
SNDFILE_API
sf_count_t
sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames)
{ SF_PRIVATE *psf ;
@ -1829,6 +1851,7 @@ sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t len)
{ SF_PRIVATE *psf ;
@ -1884,6 +1907,7 @@ sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t len)
return count ;
} /* sf_read_float */
SNDFILE_API
sf_count_t
sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames)
{ SF_PRIVATE *psf ;
@ -1937,6 +1961,7 @@ sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t len)
{ SF_PRIVATE *psf ;
@ -1992,6 +2017,7 @@ sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t len)
return count ;
} /* sf_read_double */
SNDFILE_API
sf_count_t
sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames)
{ SF_PRIVATE *psf ;
@ -2045,6 +2071,7 @@ sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t len)
{ SF_PRIVATE *psf ;
@ -2104,6 +2131,7 @@ sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t len)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t len)
{ SF_PRIVATE *psf ;
@ -2161,6 +2189,7 @@ sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t len)
return count ;
} /* sf_write_short */
SNDFILE_API
sf_count_t
sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames)
{ SF_PRIVATE *psf ;
@ -2216,6 +2245,7 @@ sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t len)
{ SF_PRIVATE *psf ;
@ -2273,6 +2303,7 @@ sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t len)
return count ;
} /* sf_write_int */
SNDFILE_API
sf_count_t
sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames)
{ SF_PRIVATE *psf ;
@ -2328,6 +2359,7 @@ sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t len)
{ SF_PRIVATE *psf ;
@ -2385,6 +2417,7 @@ sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t len)
return count ;
} /* sf_write_float */
SNDFILE_API
sf_count_t
sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames)
{ SF_PRIVATE *psf ;
@ -2440,6 +2473,7 @@ sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames)
/*------------------------------------------------------------------------------
*/
SNDFILE_API
sf_count_t
sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t len)
{ SF_PRIVATE *psf ;
@ -2497,6 +2531,7 @@ sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t len)
return count ;
} /* sf_write_double */
SNDFILE_API
sf_count_t
sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames)
{ SF_PRIVATE *psf ;
@ -3240,6 +3275,7 @@ error_exit :
** It doesn't work for W64 because W64 uses weird GUID style chunk markers.
*/
SNDFILE_API
int
sf_set_chunk (SNDFILE * sndfile, const SF_CHUNK_INFO * chunk_info)
{ SF_PRIVATE *psf ;
@ -3255,6 +3291,7 @@ sf_set_chunk (SNDFILE * sndfile, const SF_CHUNK_INFO * chunk_info)
return SFE_BAD_CHUNK_FORMAT ;
} /* sf_set_chunk */
SNDFILE_API
SF_CHUNK_ITERATOR *
sf_get_chunk_iterator (SNDFILE * sndfile, const SF_CHUNK_INFO * chunk_info)
{ SF_PRIVATE *psf ;
@ -3267,6 +3304,7 @@ sf_get_chunk_iterator (SNDFILE * sndfile, const SF_CHUNK_INFO * chunk_info)
return psf_get_chunk_iterator (psf, NULL) ;
} /* sf_get_chunk_iterator */
SNDFILE_API
SF_CHUNK_ITERATOR *
sf_next_chunk_iterator (SF_CHUNK_ITERATOR * iterator)
{ SF_PRIVATE *psf ;
@ -3280,6 +3318,7 @@ sf_next_chunk_iterator (SF_CHUNK_ITERATOR * iterator)
return NULL ;
} /* sf_get_chunk_iterator_next */
SNDFILE_API
int
sf_get_chunk_size (const SF_CHUNK_ITERATOR * iterator, SF_CHUNK_INFO * chunk_info)
{ SF_PRIVATE *psf ;
@ -3297,6 +3336,7 @@ sf_get_chunk_size (const SF_CHUNK_ITERATOR * iterator, SF_CHUNK_INFO * chunk_inf
return 0 ;
} /* sf_get_chunk_size */
SNDFILE_API
int
sf_get_chunk_data (const SF_CHUNK_ITERATOR * iterator, SF_CHUNK_INFO * chunk_info)
{ SF_PRIVATE *psf ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2009-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2009-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -35,6 +35,7 @@ extern int sf_errno ;
static void copy_filename (SF_PRIVATE * psf, LPCWSTR wpath) ;
SNDFILE_API
SNDFILE*
sf_wchar_open (LPCWSTR wpath, int mode, SF_INFO *sfinfo)
{ SF_PRIVATE *psf ;