mirror of
https://github.com/yasm/yasm
synced 2026-08-26 22:26:05 -04:00
Clean up and simplify libyasm.h options and symbol visibility:
- Move config.h and util.h from libyasm (and installed libyasm) to top level. - Move yasm_* functions from util.h to coretype.h. - Remove a number of autoconf-related YASM_*_INTERNAL options from libyasm.h. - Rename YASM_INTERNAL to YASM_LIB_INTERNAL; it now actually means what the comment describes: enables definitions that violate the yasm_* namespace. While we're at it, no longer define YASM_LIB_INTERNAL from yasm frontend, so it's closer to what a real typical libyasm-using application would look like. svn path=/trunk/yasm/; revision=944
This commit is contained in:
parent
959c7e1427
commit
cfc6bf0ded
51 changed files with 295 additions and 574 deletions
225
util.h
225
util.h
|
|
@ -1,21 +1,17 @@
|
|||
/**
|
||||
* \file util.h
|
||||
* \brief YASM utility functions.
|
||||
*
|
||||
* $IdPath: yasm/libyasm/util.h,v 1.50 2003/05/03 08:02:15 peter Exp $
|
||||
/* $IdPath: yasm/util.h,v 1.51 2003/05/04 20:28:28 peter Exp $
|
||||
* YASM utility functions.
|
||||
*
|
||||
* Includes standard headers and defines prototypes for replacement functions
|
||||
* if needed. This is the *only* header file which should include other
|
||||
* header files!
|
||||
* if needed.
|
||||
*
|
||||
* Copyright (C) 2001 Peter Johnson
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
|
|
@ -34,123 +30,61 @@
|
|||
#ifndef YASM_UTIL_H
|
||||
#define YASM_UTIL_H
|
||||
|
||||
#ifdef YASM_LIB_INTERNAL
|
||||
# define YASM_INTERNAL
|
||||
# define YASM_AUTOCONF_INTERNAL
|
||||
# define YASM_LIB_AC_INTERNAL
|
||||
# define YASM_GETTEXT_INTERNAL
|
||||
#endif
|
||||
|
||||
#ifdef YASM_INTERNAL
|
||||
|
||||
#if defined(YASM_LIB_AC_INTERNAL) && defined(HAVE_CONFIG_H)
|
||||
# include <libyasm/config.h>
|
||||
#include <config.h>
|
||||
|
||||
/* Work around glibc's non-defining of certain things when using gcc -ansi */
|
||||
# if defined(HAVE_GNU_C_LIBRARY) && defined(__STRICT_ANSI__)
|
||||
# undef __STRICT_ANSI__
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef YASM_INTERNAL
|
||||
|
||||
#if defined(YASM_LIB_AC_INTERNAL) && defined(HAVE_CONFIG_H)
|
||||
# include <stdarg.h>
|
||||
#if defined(HAVE_GNU_C_LIBRARY) && defined(__STRICT_ANSI__)
|
||||
# undef __STRICT_ANSI__
|
||||
#endif
|
||||
|
||||
#if !defined(lint) && !defined(NDEBUG)
|
||||
# define NDEBUG
|
||||
#endif
|
||||
|
||||
#ifdef YASM_AUTOCONF_INTERNAL
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
# ifdef STDC_HEADERS
|
||||
# include <stddef.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <assert.h>
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stddef.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <assert.h>
|
||||
#endif
|
||||
|
||||
#ifdef lint
|
||||
# define _(String) String
|
||||
#else
|
||||
# ifdef HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
# endif
|
||||
|
||||
# ifdef YASM_GETTEXT_INTERNAL
|
||||
# if defined(lint)
|
||||
# define _(String) String
|
||||
# else
|
||||
# ifdef HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
# endif
|
||||
# ifdef ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(String) gettext(String)
|
||||
# else
|
||||
# define gettext(Msgid) (Msgid)
|
||||
# define dgettext(Domainname, Msgid) (Msgid)
|
||||
# define dcgettext(Domainname, Msgid, Category) (Msgid)
|
||||
# define textdomain(Domainname) while (0) /* nothing */
|
||||
# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */
|
||||
# define _(String) (String)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
# ifdef ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(String) gettext(String)
|
||||
# else
|
||||
# define gettext(Msgid) (Msgid)
|
||||
# define dgettext(Domainname, Msgid) (Msgid)
|
||||
# define dcgettext(Domainname, Msgid, Category) (Msgid)
|
||||
# define textdomain(Domainname) while (0) /* nothing */
|
||||
# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */
|
||||
# define _(String) (String)
|
||||
# endif
|
||||
# endif
|
||||
#ifdef gettext_noop
|
||||
# define N_(String) gettext_noop(String)
|
||||
#else
|
||||
# define N_(String) (String)
|
||||
#endif
|
||||
|
||||
# ifdef gettext_noop
|
||||
# define N_(String) gettext_noop(String)
|
||||
# else
|
||||
# define N_(String) (String)
|
||||
# endif
|
||||
|
||||
# endif /*YASM_GETTEXT_INTERNAL*/
|
||||
|
||||
#endif /*YASM_AUTOCONF_INTERNAL*/
|
||||
|
||||
/** Sort an array using merge sort algorithm.
|
||||
* \internal
|
||||
* \param base base of array
|
||||
* \param nmemb number of elements in array
|
||||
* \param size size of each array element
|
||||
* \param compar element comparison function
|
||||
*/
|
||||
int yasm__mergesort(void *base, size_t nmemb, size_t size,
|
||||
int (*compar)(const void *, const void *));
|
||||
|
||||
#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_MERGESORT)
|
||||
#ifdef HAVE_MERGESORT
|
||||
#define yasm__mergesort(a, b, c, d) mergesort(a, b, c, d)
|
||||
#endif
|
||||
|
||||
/** Separate string by delimiters.
|
||||
* \internal
|
||||
* \param stringp string
|
||||
* \param delim set of 1 or more delimiters
|
||||
* \return First/next substring.
|
||||
*/
|
||||
/*@null@*/ char *yasm__strsep(char **stringp, const char *delim);
|
||||
|
||||
#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_STRSEP)
|
||||
#ifdef HAVE_STRSEP
|
||||
#define yasm__strsep(a, b) strsep(a, b)
|
||||
#endif
|
||||
|
||||
/** Compare two strings, ignoring case differences.
|
||||
* \internal
|
||||
* \param s1 string 1
|
||||
* \param s2 string 2
|
||||
* \return 0 if strings are equal, -1 if s1<s2, 1 if s1>s2.
|
||||
*/
|
||||
int yasm__strcasecmp(const char *s1, const char *s2);
|
||||
|
||||
/** Compare portion of two strings, ignoring case differences.
|
||||
* \internal
|
||||
* \param s1 string 1
|
||||
* \param s2 string 2
|
||||
* \param n maximum number of characters to compare
|
||||
* \return 0 if strings are equal, -1 if s1<s2, 1 if s1>s2.
|
||||
*/
|
||||
int yasm__strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
|
||||
#ifdef YASM_AUTOCONF_INTERNAL
|
||||
|
||||
#ifdef HAVE_STRCASECMP
|
||||
# define yasm__strcasecmp(x, y) strcasecmp(x, y)
|
||||
# define yasm__strncasecmp(x, y, n) strncasecmp(x, y, n)
|
||||
|
|
@ -168,11 +102,9 @@ int yasm__strncasecmp(const char *s1, const char *s2, size_t n);
|
|||
# define toascii(c) ((c) & 0x7F)
|
||||
#endif
|
||||
|
||||
#endif /*YASM_AUTOCONF_INTERNAL*/
|
||||
|
||||
#include <libyasm/compat-queue.h>
|
||||
|
||||
#if defined(YASM_AUTOCONF_INTERNAL) && defined(HAVE_SYS_CDEFS_H)
|
||||
#ifdef HAVE_SYS_CDEFS_H
|
||||
# include <sys/cdefs.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -190,68 +122,13 @@ int yasm__strncasecmp(const char *s1, const char *s2, size_t n);
|
|||
# endif
|
||||
#endif
|
||||
|
||||
/** strdup() implementation using yasm_xmalloc().
|
||||
* \internal
|
||||
* \param str string
|
||||
* \return Newly allocated duplicate string.
|
||||
*/
|
||||
/*@only@*/ char *yasm__xstrdup(const char *str);
|
||||
|
||||
/** strndup() implementation using yasm_xmalloc().
|
||||
* \internal
|
||||
* \param str string
|
||||
* \param len maximum number of characters to copy
|
||||
* \return Newly allocated duplicate string.
|
||||
*/
|
||||
/*@only@*/ char *yasm__xstrndup(const char *str, size_t len);
|
||||
|
||||
#endif /*YASM_INTERNAL*/
|
||||
|
||||
/** Error-checking memory allocation. A default implementation is provided
|
||||
* that calls yasm_fatal() on allocation errors.
|
||||
* A replacement should \em never return NULL.
|
||||
* \param size number of bytes to allocate
|
||||
* \return Allocated memory block.
|
||||
*/
|
||||
extern /*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size);
|
||||
|
||||
/** Error-checking memory allocation (with clear-to-0). A default
|
||||
* implementation is provided that calls yasm_fatal() on allocation errors.
|
||||
* A replacement should \em never return NULL.
|
||||
* \param size number of elements to allocate
|
||||
* \param elsize size (in bytes) of each element
|
||||
* \return Allocated and cleared memory block.
|
||||
*/
|
||||
extern /*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize);
|
||||
|
||||
/** Error-checking memory reallocation. A default implementation is provided
|
||||
* that calls yasm_fatal() on allocation errors. A replacement should
|
||||
* \em never return NULL.
|
||||
* \param oldmem memory block to resize
|
||||
* \param elsize new size, in bytes
|
||||
* \return Re-allocated memory block.
|
||||
*/
|
||||
extern /*@only@*/ void * (*yasm_xrealloc)
|
||||
(/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size)
|
||||
/*@modifies oldmem@*/;
|
||||
|
||||
/** Error-checking memory deallocation. A default implementation is provided
|
||||
* that calls yasm_fatal() on allocation errors.
|
||||
* \param p memory block to free
|
||||
*/
|
||||
extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p)
|
||||
/*@modifies p@*/;
|
||||
|
||||
#ifdef YASM_INTERNAL
|
||||
|
||||
#if defined(YASM_AUTOCONF_INTERNAL) && defined(WITH_DMALLOC)
|
||||
#ifdef WITH_DMALLOC
|
||||
# include <dmalloc.h>
|
||||
|
||||
#define yasm__xstrdup(str) xstrdup(str)
|
||||
#define yasm_xmalloc(size) xmalloc(size)
|
||||
#define yasm_xcalloc(count, size) xcalloc(count, size)
|
||||
#define yasm_xrealloc(ptr, size) xrealloc(ptr, size)
|
||||
#define yasm_xfree(ptr) xfree(ptr)
|
||||
# define yasm__xstrdup(str) xstrdup(str)
|
||||
# define yasm_xmalloc(size) xmalloc(size)
|
||||
# define yasm_xcalloc(count, size) xcalloc(count, size)
|
||||
# define yasm_xrealloc(ptr, size) xrealloc(ptr, size)
|
||||
# define yasm_xfree(ptr) xfree(ptr)
|
||||
#endif
|
||||
|
||||
/* Bit-counting: used primarily by HAMT but also in a few other places. */
|
||||
|
|
@ -276,10 +153,4 @@ extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p)
|
|||
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
|
||||
#endif
|
||||
|
||||
#endif /*YASM_INTERNAL*/
|
||||
|
||||
#include <libyasm/coretype.h>
|
||||
|
||||
#include <libyasm/valparam.h>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue