shithub: sox

Download patch

ref: 88eec9c75d0a23c6c4d5d61af76c6ebd56b82b51
parent: e29e9ceb7c25a2d83c09bc8a601de117fc65563c
author: Doug Cook <idigdoug@users.sourceforge.net>
date: Sat Mar 26 13:13:58 EDT 2011

Portability fixes for sox.h

The point of this change is to make sox.h more convenient and portable
for users of libsox. The libsox API should depend only on the system's
ABI and should be independent of soxconfig.h or CRT-specific
definitions. It should also minimize its impact on the program in which
it is included.

sox.h changes:
- Don't include soxstdint.h from sox.h. soxstdint.h includes
  soxconfig.h. The sox.h header should be self-contained for easy
  management, and should especially not depend on a non-constant header
  like soxconfig.h (which is different depending on how sox was built).
- Minimize the impact on client program by including as few headers as
  possible. stdio.h and stdlib.h aren't really needed to describe the
  libsox api, so remove them. stdarg.h is needed for va_list. stddef.h
  is needed to define size_t. limits.h is needed to get integer sizes.
  These headers were part of the 1989 C freestanding implementation, so
  there should be no problem in using them in 2011.
- Use limits.h to automatically determine appropriate 8, 16, 32, and 64
  bit types without referencing soxconfig.h. stdint.h would be even
  better, but there are still a few environments that don't have
  stdint.h. Any C implementation that has a long long type with
  corresponding macros in limits.h should work with this compile-time
  auto-detection. My GCC raises a warning about the use of long long, so
  GCC warnings had to be suppressed for this header. I'm hoping this will
  be enough to support most systems on which SoX is supported, but if I
  missed something, it shouldn't be too hard to add support for it.
- Use sox_intN_t instead of intN_t for the width-specified integer types
  referenced by sox.h. All types of the form intN_t, including int24_t,
  are potentially defined by stdint.h. Sox.h should not be defining any
  type that might be defined by a standard header. (With this change,
  sox.h is now "clean" in that every definition made in sox.h starts
  with either SOX_ or LSX_.)
- Change format_t's fp from FILE* to void*. The FILE structure can be
  defined differently for different C runtimes, causing problems if a
  libsox shared library uses a different C runtime than the one used by
  the client. Sox should not expose CRT-specific details such as FILE* to
  its client API, and should definitely not be encouraging clients to
  directly access the fp. The clients should be using API calls, and if an
  API call is missing, it should be added to SoX.
- Similarly, it is not safe for the client to pass a FILE* to SoX for use
  in sox_output_message. The primary magic performed by sox_output_message
  was its determination of the file's basename, so replace
  sox_output_message with a new sox_basename function. The client can then
  call sox_basename to format the filename, then use its own mechanism to
  print the output message.

Summary of other changes in patch:
- deleted soxstdint.h.cmake, removed from cmakelists.txt, removed from
  Makefile.am.
- lpc10.h no longer includes soxstdint.h. INT16 and INT32 are auto-detected
  and defined based on limits.h.
- format->fp is now void*, so plugins have to cast it to FILE* for now. In
  the future, I would like to make fp completely opaque (probably even
  plugins should not access fp directly), but this is a good start for now.
- stdio.h and stdlib.h inclusion moved to sox_i.h.
- util.h defines the non-prefixed uint64_t and similar, based on inttypes.h,
  stdint.h, or limits.h, depending on what soxconfig.h says is available.
  I'm staying away from int24_t because it isn't present in any stdint.h
  I know about, but it is specifically mentioned in the C standard as an
  example of something that stdint.h might define. I don't have a way to
  determine whether or not stdint.h has defined it, so users of int24_t
  need to now use sox_int24_t instead.
- util.h now defines PRId64 and PRIu64 for use in printf formatting of
  64-bit integers.
- Change int24_t to sox_int24_t everywhere.
- Cast format->fp to FILE*.
- Fix samples to work with updated sox.h.