X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fimports.c;h=8f097195922e590a2fafc209c5cdc138bf8f9f1c;hb=7a80c1bbc56b61525634f2b699f995e863dfade2;hp=d8375bf57273791ccd15395180c0b0a03966837e;hpb=26f8fad1456fdc2b352cea9d3b4c32cb5f6ae947;p=mesa.git diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index d8375bf5727..8f097195922 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -46,6 +46,7 @@ #include "imports.h" #include "context.h" +#include "mtypes.h" #include "version.h" #ifdef _GNU_SOURCE @@ -71,27 +72,6 @@ extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg); /** \name Memory */ /*@{*/ -/** Wrapper around malloc() */ -void * -_mesa_malloc(size_t bytes) -{ - return malloc(bytes); -} - -/** Wrapper around calloc() */ -void * -_mesa_calloc(size_t bytes) -{ - return calloc(1, bytes); -} - -/** Wrapper around free() */ -void -_mesa_free(void *ptr) -{ - free(ptr); -} - /** * Allocate aligned memory. * @@ -109,7 +89,8 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment) #if defined(HAVE_POSIX_MEMALIGN) void *mem; int err = posix_memalign(& mem, alignment, bytes); - (void) err; + if (err) + return NULL; return mem; #elif defined(_WIN32) && defined(_MSC_VER) return _aligned_malloc(bytes, alignment); @@ -118,7 +99,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment) ASSERT( alignment > 0 ); - ptr = (uintptr_t) _mesa_malloc(bytes + alignment + sizeof(void *)); + ptr = (uintptr_t) malloc(bytes + alignment + sizeof(void *)); if (!ptr) return NULL; @@ -138,8 +119,8 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment) } /** - * Same as _mesa_align_malloc(), but using _mesa_calloc() instead of - * _mesa_malloc() + * Same as _mesa_align_malloc(), but using calloc(1, ) instead of + * malloc() */ void * _mesa_align_calloc(size_t bytes, unsigned long alignment) @@ -167,7 +148,7 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment) ASSERT( alignment > 0 ); - ptr = (uintptr_t) _mesa_calloc(bytes + alignment + sizeof(void *)); + ptr = (uintptr_t) calloc(1, bytes + alignment + sizeof(void *)); if (!ptr) return NULL; @@ -203,7 +184,7 @@ _mesa_align_free(void *ptr) #else void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); void *realAddr = *cubbyHole; - _mesa_free(realAddr); + free(realAddr); #endif /* defined(HAVE_POSIX_MEMALIGN) */ } @@ -236,11 +217,11 @@ void * _mesa_realloc(void *oldBuffer, size_t oldSize, size_t newSize) { const size_t copySize = (oldSize < newSize) ? oldSize : newSize; - void *newBuffer = _mesa_malloc(newSize); + void *newBuffer = malloc(newSize); if (newBuffer && oldBuffer && copySize > 0) memcpy(newBuffer, oldBuffer, copySize); if (oldBuffer) - _mesa_free(oldBuffer); + free(oldBuffer); return newBuffer; } @@ -257,28 +238,6 @@ _mesa_memset16( unsigned short *dst, unsigned short val, size_t n ) *dst++ = val; } -/** Wrapper around either memset() or bzero() */ -void -_mesa_bzero( void *dst, size_t n ) -{ -#if defined(__FreeBSD__) - bzero( dst, n ); -#else - memset( dst, 0, n ); -#endif -} - -/** Wrapper around memcmp() */ -int -_mesa_memcmp( const void *s1, const void *s2, size_t n ) -{ -#if defined(SUNOS4) - return memcmp( (char *) s1, (char *) s2, (int) n ); -#else - return memcmp(s1, s2, n); -#endif -} - /*@}*/ @@ -286,41 +245,6 @@ _mesa_memcmp( const void *s1, const void *s2, size_t n ) /** \name Math */ /*@{*/ -/** Wrapper around sin() */ -double -_mesa_sin(double a) -{ - return sin(a); -} - -/** Single precision wrapper around sin() */ -float -_mesa_sinf(float a) -{ - return (float) sin((double) a); -} - -/** Wrapper around cos() */ -double -_mesa_cos(double a) -{ - return cos(a); -} - -/** Single precision wrapper around asin() */ -float -_mesa_asinf(float x) -{ - return (float) asin((double) x); -} - -/** Single precision wrapper around atan() */ -float -_mesa_atanf(float x) -{ - return (float) atan((double) x); -} - /** Wrapper around sqrt() */ double _mesa_sqrtd(double x) @@ -529,15 +453,7 @@ _mesa_inv_sqrtf(float n) #endif } - -/** Wrapper around pow() */ -double -_mesa_pow(double x, double y) -{ - return pow(x, y); -} - - +#ifndef __GNUC__ /** * Find the first bit set in a word. */ @@ -581,9 +497,6 @@ _mesa_ffs(int32_t i) int _mesa_ffsll(int64_t val) { -#ifdef ffsll - return ffsll(val); -#else int bit; assert(sizeof(val) == 8); @@ -597,26 +510,24 @@ _mesa_ffsll(int64_t val) return 32 + bit; return 0; -#endif } +#endif - +#if !defined(__GNUC__) ||\ + ((_GNUC__ == 3 && __GNUC_MINOR__ < 4) && __GNUC__ < 4) /** * Return number of bits set in given GLuint. */ unsigned int _mesa_bitcount(unsigned int n) { -#if defined(__GNUC__) - return __builtin_popcount(n); -#else unsigned int bits; for (bits = 0; n > 0; n = n >> 1) { bits += (n & 1); } return bits; -#endif } +#endif /** @@ -820,7 +731,7 @@ _mesa_getenv( const char *var ) /*@{*/ /** - * Implemented using _mesa_malloc() and strcpy. + * Implemented using malloc() and strcpy. * Note that NULL is handled accordingly. */ char * @@ -828,7 +739,7 @@ _mesa_strdup( const char *s ) { if (s) { size_t l = strlen(s); - char *s2 = (char *) _mesa_malloc(l + 1); + char *s2 = (char *) malloc(l + 1); if (s2) strcpy(s2, s); return s2; @@ -838,18 +749,21 @@ _mesa_strdup( const char *s ) } } -/** Wrapper around strtod() */ -double -_mesa_strtod( const char *s, char **end ) +/** Wrapper around strtof() */ +float +_mesa_strtof( const char *s, char **end ) { -#ifdef _GNU_SOURCE +#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \ + !defined(ANDROID) static locale_t loc = NULL; if (!loc) { loc = newlocale(LC_CTYPE_MASK, "C", NULL); } - return strtod_l(s, end, loc); + return strtof_l(s, end, loc); +#elif defined(_ISOC99_SOURCE) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) + return strtof(s, end); #else - return strtod(s, end); + return (float)strtod(s, end); #endif } @@ -870,22 +784,6 @@ _mesa_str_checksum(const char *str) /*@}*/ -/**********************************************************************/ -/** \name I/O */ -/*@{*/ - -/** Wrapper around vsprintf() */ -int -_mesa_sprintf( char *str, const char *fmt, ... ) -{ - int r; - va_list args; - va_start( args, fmt ); - r = vsprintf( str, fmt, args ); - va_end( args ); - return r; -} - /** Wrapper around vsnprintf() */ int _mesa_snprintf( char *str, size_t size, const char *fmt, ... ) @@ -898,38 +796,6 @@ _mesa_snprintf( char *str, size_t size, const char *fmt, ... ) return r; } -/** Wrapper around printf(), using vsprintf() for the formatting. */ -void -_mesa_printf( const char *fmtString, ... ) -{ - va_list args; - va_start( args, fmtString ); - vfprintf(stderr, fmtString, args); - va_end( args ); -} - -/** Wrapper around fprintf(), using vsprintf() for the formatting. */ -void -_mesa_fprintf( FILE *f, const char *fmtString, ... ) -{ - char s[MAXSTRING]; - va_list args; - va_start( args, fmtString ); - vsnprintf(s, MAXSTRING, fmtString, args); - va_end( args ); - fprintf(f, "%s", s); -} - - -/** Wrapper around vsprintf() */ -int -_mesa_vsprintf( char *str, const char *fmt, va_list args ) -{ - return vsprintf( str, fmt, args ); -} - -/*@}*/ - /**********************************************************************/ /** \name Diagnostics */ @@ -1014,7 +880,7 @@ error_string( GLenum error ) * previous errors which were accumulated. */ static void -flush_delayed_errors( GLcontext *ctx ) +flush_delayed_errors( struct gl_context *ctx ) { char s[MAXSTRING]; @@ -1038,7 +904,7 @@ flush_delayed_errors( GLcontext *ctx ) * \param fmtString printf()-like format string. */ void -_mesa_warning( GLcontext *ctx, const char *fmtString, ... ) +_mesa_warning( struct gl_context *ctx, const char *fmtString, ... ) { char str[MAXSTRING]; va_list args; @@ -1061,18 +927,24 @@ _mesa_warning( GLcontext *ctx, const char *fmtString, ... ) * \param fmtString problem description string. */ void -_mesa_problem( const GLcontext *ctx, const char *fmtString, ... ) +_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... ) { va_list args; char str[MAXSTRING]; + static int numCalls = 0; + (void) ctx; - va_start( args, fmtString ); - vsnprintf( str, MAXSTRING, fmtString, args ); - va_end( args ); + if (numCalls < 50) { + numCalls++; - fprintf(stderr, "Mesa %s implementation error: %s\n", MESA_VERSION_STRING, str); - fprintf(stderr, "Please report at bugzilla.freedesktop.org\n"); + va_start( args, fmtString ); + vsnprintf( str, MAXSTRING, fmtString, args ); + va_end( args ); + fprintf(stderr, "Mesa %s implementation error: %s\n", + MESA_VERSION_STRING, str); + fprintf(stderr, "Please report at bugs.freedesktop.org\n"); + } } @@ -1089,7 +961,7 @@ _mesa_problem( const GLcontext *ctx, const char *fmtString, ... ) * \param fmtString printf() style format string, followed by optional args */ void -_mesa_error( GLcontext *ctx, GLenum error, const char *fmtString, ... ) +_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... ) { static GLint debug = -1; @@ -1146,7 +1018,7 @@ _mesa_error( GLcontext *ctx, GLenum error, const char *fmtString, ... ) * \param fmtString printf()-style format string, followed by optional args. */ void -_mesa_debug( const GLcontext *ctx, const char *fmtString, ... ) +_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... ) { #ifdef DEBUG char s[MAXSTRING];