From 6fc804e12ad7db569e82229cc11a361066cec682 Mon Sep 17 00:00:00 2001 From: flaviojs Date: Thu, 8 Sep 2011 19:47:26 +0000 Subject: * Fix C++ compilation issues. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14955 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/cbasetypes.h | 29 +++++++++++++++++++++++++++++ src/common/db.h | 6 +++--- src/common/grfio.c | 8 ++++---- src/common/grfio.h | 4 ++-- src/common/plugin.h | 2 +- src/common/strlib.c | 4 ++-- 6 files changed, 41 insertions(+), 12 deletions(-) (limited to 'src/common') diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index 27420edbf..58acad2c7 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -77,6 +77,12 @@ // portable printf/scanf format macros and integer definitions // NOTE: Visual C++ uses and provided in /3rdparty ////////////////////////////////////////////////////////////////////////// +#ifdef __cplusplus +#define __STDC_CONSTANT_MACROS +#define __STDC_FORMAT_MACROS +#define __STDC_LIMIT_MACROS +#endif + #include #include #include @@ -326,4 +332,27 @@ typedef char bool; #endif #endif + +////////////////////////////////////////////////////////////////////////// +// Set a pointer variable to a pointer value. +#ifdef __cplusplus +template +void SET_POINTER(T1*&var, T2* p) +{ + var = static_cast(p); +} +template +void SET_FUNCPOINTER(T1& var, T2 p) +{ + char ASSERT_POINTERSIZE[sizeof(T1) == sizeof(void*) && sizeof(T2) == sizeof(void*)?1:-1];// 1 if true, -1 if false + union{ T1 out; T2 in; } tmp;// /!\ WARNING casting a pointer to a function pointer is against the C++ standard + tmp.in = p; + var = tmp.out; +} +#else +#define SET_POINTER(var,p) (var) = (p) +#define SET_FUNCPOINTER(var,p) (var) = (p) +#endif + + #endif /* _CBASETYPES_H_ */ diff --git a/src/common/db.h b/src/common/db.h index d33b8ec2e..e5515803c 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -994,8 +994,8 @@ void linkdb_foreach( struct linkdb_node** head, LinkDBFunc func, ... ); do{ \ if( (__n) > VECTOR_CAPACITY(__vec) ) \ { /* increase size */ \ - if( VECTOR_CAPACITY(__vec) == 0 ) VECTOR_DATA(__vec) = aMalloc((__n)*sizeof(VECTOR_FIRST(__vec))); /* allocate new */ \ - else VECTOR_DATA(__vec) = aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))); /* reallocate */ \ + if( VECTOR_CAPACITY(__vec) == 0 ) SET_POINTER(VECTOR_DATA(__vec), aMalloc((__n)*sizeof(VECTOR_FIRST(__vec)))); /* allocate new */ \ + else SET_POINTER(VECTOR_DATA(__vec), aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec)))); /* reallocate */ \ memset(VECTOR_DATA(__vec)+VECTOR_LENGTH(__vec), 0, (VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec))*sizeof(VECTOR_FIRST(__vec))); /* clear new data */ \ VECTOR_CAPACITY(__vec) = (__n); /* update capacity */ \ } \ @@ -1007,7 +1007,7 @@ void linkdb_foreach( struct linkdb_node** head, LinkDBFunc func, ... ); } \ else if( (__n) < VECTOR_CAPACITY(__vec) ) \ { /* reduce size */ \ - VECTOR_DATA(__vec) = aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))); /* reallocate */ \ + SET_POINTER(VECTOR_DATA(__vec), aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec)))); /* reallocate */ \ VECTOR_CAPACITY(__vec) = (__n); /* update capacity */ \ if( VECTOR_LENGTH(__vec) > (__n) ) VECTOR_LENGTH(__vec) = (__n); /* update length */ \ } \ diff --git a/src/common/grfio.c b/src/common/grfio.c index cb242fe5d..1d1ce756f 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -223,17 +223,17 @@ unsigned long grfio_crc32 (const unsigned char* buf, unsigned int len) /////////////////////////////////////////////////////////////////////////////// /// Grf data sub : zip decode -int decode_zip(unsigned char* dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen) +int decode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen) { - return uncompress(dest, destLen, source, sourceLen); + return uncompress((Bytef*)dest, destLen, (const Bytef*)source, sourceLen); } /////////////////////////////////////////////////////////////////////////////// /// Grf data sub : zip encode -int encode_zip(unsigned char* dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen) +int encode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen) { - return compress(dest, destLen, source, sourceLen); + return compress((Bytef*)dest, destLen, (const Bytef*)source, sourceLen); } diff --git a/src/common/grfio.h b/src/common/grfio.h index d0baa6609..0fc9f958d 100644 --- a/src/common/grfio.h +++ b/src/common/grfio.h @@ -14,7 +14,7 @@ char *grfio_find_file(char *fname); int grfio_size(char*); // GRFIO data file size get unsigned long grfio_crc32(const unsigned char *buf, unsigned int len); -int decode_zip(unsigned char* dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen); -int encode_zip(unsigned char* dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen); +int decode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen); +int encode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen); #endif /* _GRFIO_H_ */ diff --git a/src/common/plugin.h b/src/common/plugin.h index a367d2537..ec6399c57 100644 --- a/src/common/plugin.h +++ b/src/common/plugin.h @@ -50,7 +50,7 @@ typedef void Plugin_Event_Func(void); #define PLUGIN_MAP 8 #define PLUGIN_CORE 16 -#define IMPORT_SYMBOL(s,n) (s) = plugin_call_table[n] +#define IMPORT_SYMBOL(s,n) SET_FUNCPOINTER((s), plugin_call_table[n]) #define SYMBOL_SERVER_TYPE 0 #define SYMBOL_SERVER_NAME 1 diff --git a/src/common/strlib.c b/src/common/strlib.c index 097f499e6..7f79a5ef0 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -245,7 +245,7 @@ char* _strtok_r(char *s1, const char *s2, char **lasts) If no '\0' terminator is found in that many characters, return MAXLEN. */ size_t strnlen (const char* string, size_t maxlen) { - const char* end = memchr (string, '\0', maxlen); + const char* end = (const char*)memchr(string, '\0', maxlen); return end ? (size_t) (end - string) : maxlen; } #endif @@ -980,7 +980,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc // allocate enough memory for the maximum requested amount of columns plus the reserved one fields_length = maxcols+1; - fields = aMalloc(fields_length*sizeof(char*)); + fields = (char**)aMalloc(fields_length*sizeof(char*)); // process rows one by one while( fgets(line, sizeof(line), fp) ) -- cgit v1.2.3-60-g2f50