Commit 1ca2945f authored by Jose Fonseca's avatar Jose Fonseca

talloc: Make it compile with MSVC, MinGW, and Xcode/gcc4.0.

Based on Aras Pranckevičius' patch.
parent e6032b1d
......@@ -5,6 +5,9 @@ if 'egl' in env['statetrackers']:
SConscript('egl/main/SConscript')
if 'mesa' in env['statetrackers']:
if platform == 'windows':
SConscript('talloc/SConscript')
SConscript('glsl/SConscript')
SConscript('mapi/glapi/SConscript')
SConscript('mesa/SConscript')
......
Import('*')
if env['platform'] != 'windows':
Return()
env = env.Clone()
talloc = env.SharedLibrary(
target = 'talloc',
source = ['talloc.c', 'talloc.def'],
)
env.InstallSharedLibrary(talloc)
if env['platform'] != 'windows':
talloc = env.FindIxes(talloc, 'LIBPREFIX', 'LIBSUFFIX')
else:
talloc = env.FindIxes(talloc, 'SHLIBPREFIX', 'SHLIBSUFFIX')
Export('talloc')
......@@ -30,8 +30,38 @@
inspired by http://swapped.cc/halloc/
*/
#include "replace.h"
#include "talloc.h"
#include <string.h>
#define TALLOC_MIN(a,b) ((a)<(b)?(a):(b))
/* Visual C++ 2008 compatibility */
#if defined(_MSC_VER) && !defined(_cplusplus)
typedef size_t ssize_t;
#define inline __inline
#endif
/* Xcode/gcc4.0 compatibility */
#if defined(__APPLE__) || defined(__MINGW32__)
static size_t strnlen (const char* s, size_t n)
{
size_t i;
for (i = 0; i < n; ++i)
{
if (s[i] == '\0')
break;
}
return i;
}
#endif
/* Visual C++ 2008 & Xcode/gcc4.0 compatibility */
#if !defined(_cplusplus) && (defined(WIN32) || defined(__APPLE__))
typedef int bool;
#define false 0
#define true 1
#endif
#ifdef TALLOC_BUILD_VERSION_MAJOR
#if (TALLOC_VERSION_MAJOR != TALLOC_BUILD_VERSION_MAJOR)
......@@ -1200,7 +1230,7 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n
}
if (new_ptr) {
memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE);
memcpy(new_ptr, tc, TALLOC_MIN(tc->size,size) + TC_HDR_SIZE);
}
}
else {
......@@ -1686,7 +1716,7 @@ char *talloc_strndup_append_buffer(char *s, const char *a, size_t n)
return __talloc_strlendup_append(s, slen, a, strnlen(a, n));
}
#ifndef HAVE_VA_COPY
#ifndef va_copy
#ifdef HAVE___VA_COPY
#define va_copy(dest, src) __va_copy(dest, src)
#else
......@@ -1703,7 +1733,12 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
/* this call looks strange, but it makes it work on older solaris boxes */
va_copy(ap2, ap);
#ifdef _MSC_VER
/* MSVC runtime needs to use _vcsprintf to return buffer size; vsnprintf would return -1 */
len = _vscprintf(fmt, ap2);
#else
len = vsnprintf(&c, 1, fmt, ap2);
#endif
va_end(ap2);
if (unlikely(len < 0)) {
return NULL;
......@@ -1748,7 +1783,12 @@ static inline char *__talloc_vaslenprintf_append(char *s, size_t slen,
char c;
va_copy(ap2, ap);
#ifdef _MSC_VER
/* MSVC runtime needs to use _vcsprintf to return buffer size; vsnprintf would return -1 */
alen = _vscprintf(fmt, ap2);
#else
alen = vsnprintf(&c, 1, fmt, ap2);
#endif
va_end(ap2);
if (alen <= 0) {
......
EXPORTS
_talloc
_talloc_array
_talloc_free
_talloc_get_type_abort
_talloc_memdup
_talloc_move
_talloc_realloc
_talloc_realloc_array
_talloc_reference_loc
_talloc_set_destructor
_talloc_steal_loc
_talloc_zero
_talloc_zero_array
talloc_asprintf
talloc_asprintf_append
talloc_asprintf_append_buffer
talloc_autofree_context
talloc_check_name
talloc_disable_null_tracking
talloc_enable_leak_report
talloc_enable_leak_report_full
talloc_enable_null_tracking
talloc_enable_null_tracking_no_autofree
talloc_find_parent_byname
talloc_free_children
talloc_get_name
talloc_get_size
talloc_increase_ref_count
talloc_init
talloc_is_parent
talloc_named
talloc_named_const
talloc_parent
talloc_parent_name
talloc_pool
talloc_realloc_fn
talloc_reference_count
talloc_reparent
talloc_report
talloc_report_depth_cb
talloc_report_depth_file
talloc_report_full
talloc_set_abort_fn
talloc_set_log_fn
talloc_set_log_stderr
talloc_set_name
talloc_set_name_const
talloc_show_parents
talloc_strdup
talloc_strdup_append
talloc_strdup_append_buffer
talloc_strndup
talloc_strndup_append
talloc_strndup_append_buffer
talloc_total_blocks
talloc_total_size
talloc_unlink
talloc_vasprintf
talloc_vasprintf_append
talloc_vasprintf_append_buffer
talloc_version_major
talloc_version_minor
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment