mesa: remove MSVC warning pragmas
[mesa.git] / src / mesa / main / imports.c
index af8efbacb5a1e94f1b8054702e674bc54a5f0d09..ac8deeb97c983674c7cd5f14133efd41e53a1a1a 100644 (file)
@@ -20,7 +20,6 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-
-
+#include <stdio.h>
+#include <stdarg.h>
+#include "c99_math.h"
 #include "imports.h"
 #include "context.h"
 #include "mtypes.h"
@@ -92,7 +93,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
 #else
    uintptr_t ptr, buf;
 
-   ASSERT( alignment > 0 );
+   assert( alignment > 0 );
 
    ptr = (uintptr_t)malloc(bytes + alignment + sizeof(void *));
    if (!ptr)
@@ -141,7 +142,7 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
 #else
    uintptr_t ptr, buf;
 
-   ASSERT( alignment > 0 );
+   assert( alignment > 0 );
 
    ptr = (uintptr_t)calloc(1, bytes + alignment + sizeof(void *));
    if (!ptr)
@@ -168,6 +169,8 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
  * \param ptr pointer to the memory to be freed.
  * The actual address to free is stored in the word immediately before the
  * address the client sees.
+ * Note that it is legal to pass NULL pointer to this function and will be
+ * handled accordingly.
  */
 void
 _mesa_align_free(void *ptr)
@@ -177,9 +180,11 @@ _mesa_align_free(void *ptr)
 #elif defined(_WIN32) && defined(_MSC_VER)
    _aligned_free(ptr);
 #else
-   void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
-   void *realAddr = *cubbyHole;
-   free(realAddr);
+   if (ptr) {
+      void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
+      void *realAddr = *cubbyHole;
+      free(realAddr);
+   }
 #endif /* defined(HAVE_POSIX_MEMALIGN) */
 }
 
@@ -199,26 +204,12 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
    if (newBuf && oldBuffer && copySize > 0) {
       memcpy(newBuf, oldBuffer, copySize);
    }
-   if (oldBuffer)
-      _mesa_align_free(oldBuffer);
+
+   _mesa_align_free(oldBuffer);
    return newBuf;
 #endif
 }
 
-
-
-/** Reallocate memory */
-void *
-_mesa_realloc(void *oldBuffer, size_t oldSize, size_t newSize)
-{
-   const size_t copySize = (oldSize < newSize) ? oldSize : newSize;
-   void *newBuffer = malloc(newSize);
-   if (newBuffer && oldBuffer && copySize > 0)
-      memcpy(newBuffer, oldBuffer, copySize);
-   free(oldBuffer);
-   return newBuffer;
-}
-
 /*@}*/
 
 
@@ -227,7 +218,7 @@ _mesa_realloc(void *oldBuffer, size_t oldSize, size_t newSize)
 /*@{*/
 
 
-#ifndef __GNUC__
+#ifndef HAVE___BUILTIN_FFS
 /**
  * Find the first bit set in a word.
  */
@@ -256,8 +247,9 @@ ffs(int i)
    }
    return bit;
 }
+#endif
 
-
+#ifndef HAVE___BUILTIN_FFSLL
 /**
  * Find position of first bit set in given value.
  * XXX Warning: this function can only be used on 64-bit systems!
@@ -281,11 +273,10 @@ ffsll(long long int val)
 
    return 0;
 }
-#endif /* __GNUC__ */
+#endif
 
 
-#if !defined(__GNUC__) ||\
-   ((__GNUC__ * 100 + __GNUC_MINOR__) < 304) /* Not gcc 3.4 or later */
+#ifndef HAVE___BUILTIN_POPCOUNT
 /**
  * Return number of bits set in given GLuint.
  */
@@ -298,7 +289,9 @@ _mesa_bitcount(unsigned int n)
    }
    return bits;
 }
+#endif
 
+#ifndef HAVE___BUILTIN_POPCOUNTLL
 /**
  * Return number of bits set in given 64-bit uint.
  */
@@ -484,100 +477,10 @@ _mesa_half_to_float(GLhalfARB val)
 /*@}*/
 
 
-/**********************************************************************/
-/** \name Sort & Search */
-/*@{*/
-
-/**
- * Wrapper for bsearch().
- */
-void *
-_mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size, 
-               int (*compar)(const void *, const void *) )
-{
-#if defined(_WIN32_WCE)
-   void *mid;
-   int cmp;
-   while (nmemb) {
-      nmemb >>= 1;
-      mid = (char *)base + nmemb * size;
-      cmp = (*compar)(key, mid);
-      if (cmp == 0)
-        return mid;
-      if (cmp > 0) {
-        base = (char *)mid + size;
-        --nmemb;
-      }
-   }
-   return NULL;
-#else
-   return bsearch(key, base, nmemb, size, compar);
-#endif
-}
-
-/*@}*/
-
-
-/**********************************************************************/
-/** \name Environment vars */
-/*@{*/
-
-/**
- * Wrapper for getenv().
- */
-char *
-_mesa_getenv( const char *var )
-{
-#if defined(_XBOX) || defined(_WIN32_WCE)
-   return NULL;
-#else
-   return getenv(var);
-#endif
-}
-
-/*@}*/
-
-
 /**********************************************************************/
 /** \name String */
 /*@{*/
 
-/**
- * Implemented using malloc() and strcpy.
- * Note that NULL is handled accordingly.
- */
-char *
-_mesa_strdup( const char *s )
-{
-   if (s) {
-      size_t l = strlen(s);
-      char *s2 = malloc(l + 1);
-      if (s2)
-         strcpy(s2, s);
-      return s2;
-   }
-   else {
-      return NULL;
-   }
-}
-
-/** Wrapper around strtof() */
-float
-_mesa_strtof( const char *s, char **end )
-{
-#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \
-   !defined(ANDROID) && !defined(__HAIKU__) && !defined(__UCLIBC__)
-   static locale_t loc = NULL;
-   if (!loc) {
-      loc = newlocale(LC_CTYPE_MASK, "C", NULL);
-   }
-   return strtof_l(s, end, loc);
-#elif defined(_ISOC99_SOURCE) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
-   return strtof(s, end);
-#else
-   return (float)strtod(s, end);
-#endif
-}
 
 /** Compute simple checksum/hash for a string */
 unsigned int