From: José Fonseca Date: Fri, 13 Aug 2010 12:53:04 +0000 (+0100) Subject: talloc: Make it compile with MSVC, MinGW, and Xcode/gcc4.0. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1ca2945f84e9cb298a7d4ad4ec9a0578097c146d;p=mesa.git talloc: Make it compile with MSVC, MinGW, and Xcode/gcc4.0. Based on Aras Pranckevičius' patch. --- diff --git a/src/SConscript b/src/SConscript index 2b46186f986..c3e34be6f76 100644 --- a/src/SConscript +++ b/src/SConscript @@ -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') diff --git a/src/talloc/SConscript b/src/talloc/SConscript new file mode 100644 index 00000000000..a4861a932e5 --- /dev/null +++ b/src/talloc/SConscript @@ -0,0 +1,20 @@ +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') diff --git a/src/talloc/talloc.c b/src/talloc/talloc.c index 7beda4b0f58..cc01346a7f0 100644 --- a/src/talloc/talloc.c +++ b/src/talloc/talloc.c @@ -30,8 +30,38 @@ inspired by http://swapped.cc/halloc/ */ -#include "replace.h" #include "talloc.h" +#include + +#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) { diff --git a/src/talloc/talloc.def b/src/talloc/talloc.def new file mode 100644 index 00000000000..13d7a159cef --- /dev/null +++ b/src/talloc/talloc.def @@ -0,0 +1,63 @@ +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