usermode/library/common/cuckoo_hash/Common.h

00001 
00002 //metadoc Common copyright Steve Dekorte 2002
00003 //metadoc Common license BSD revised
00004 /*metadoc Common description
00005 This is a header that all other source files should include.
00006 These defines are helpful for doing OS specific checks in the code.
00007  */
00008  
00009 
00010 #ifndef IOCOMMON_DEFINED
00011 #define IOCOMMON_DEFINED 1
00012 
00013 /*#define LOW_MEMORY_SYSTEM 1*/
00014 #include <stdlib.h>
00015 #include <string.h>
00016 #include <stddef.h>
00017 
00018 
00019 #if defined (__SVR4) && defined (__sun)
00020 #include <inttypes.h>
00021 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
00022 #include <inttypes.h>
00023 #elif !defined(__SYMBIAN32__) && !defined(_MSC_VER) && !defined(__NeXT__)
00024 #include <stdint.h>
00025 #else
00026 typedef unsigned char   uint8_t;
00027 typedef   signed char    int8_t;
00028 typedef unsigned short uint16_t;
00029 typedef   signed short  int16_t;
00030 typedef unsigned long  uint32_t;
00031 typedef   signed long   int32_t;
00032 /*
00033  typedef unsigned long uint64_t;
00034  typedef signed long int64_t;
00035  */
00036 typedef unsigned long long uint64_t;
00037 typedef long long int64_t;
00038 #endif
00039 
00040 /* Windows stuff */
00041 
00042 #if defined(WIN32) || defined(__WINS__) || defined(__MINGW32__) || defined(_MSC_VER)
00043 #define inline __inline
00044 #define snprintf _snprintf
00045 #define usleep(x) Sleep(((x)+999)/1000)
00046 
00047 #define HAS_FIBERS 1
00048 
00049 #define ON_WINDOWS 1
00050 
00051 // this also includes windows.h
00052 #include <winsock2.h>
00053 
00054 // Enable fibers
00055 #ifndef _WIN32_WINNT
00056 #define _WIN32_WINNT 0x0400
00057 #endif
00058 
00059 #if !defined(__MINGW32__)
00060 #if defined(BUILDING_BASEKIT_DLL) || defined(BUILDING_IOVMALL_DLL)
00061 #define BASEKIT_API __declspec(dllexport)
00062 #else
00063 #define BASEKIT_API __declspec(dllimport)
00064 #endif
00065 #else
00066 #define BASEKIT_API
00067 #endif
00068 /*
00069 #ifndef _SYS_STDINT_H_
00070 #include "PortableStdint.h"
00071 #endif
00072  */
00073 
00074 #if !defined(__MINGW32__)
00075 /* disable compile warnings which are always treated
00076 as errors in my dev settings */
00077 
00078 #pragma warning( disable : 4244 )
00079 /* warning C4244: 'function' : conversion from 'double ' to 'int ', possible loss of data */
00080 
00081 #pragma warning( disable : 4996 )
00082 /* warning C4996: 'function' : This function or variable may be unsafe. Consider using 'function_s' instead */
00083 
00084 #pragma warning( disable : 4018 )
00085 /* warning C4018: 'operator' : signed/unsigned mismatch */
00086 
00087 /*#pragma warning( disable : 4090 ) */
00088 /* warning C4090: 'function' : different 'const' qualifiers  */
00089 
00090 /*#pragma warning( disable : 4024 )*/
00091 /* warning C4024: different types for formal and actual parameter  */
00092 
00093 /*#pragma warning( disable : 4761 ) */
00094 /* warning C4761: integral size mismatch in argument; conversion supplied  */
00095 
00096 /*#pragma warning( disable : 4047 ) */
00097 /* warning C4047: '=' : 'char *' differs in levels of indirection from 'int '  */
00098 #define ARCHITECTURE_x86 1
00099 #endif
00100 
00101 /* io_malloc, io_realloc, io_free undefined */
00102 #if !defined(__SYMBIAN32__)
00103 #include <memory.h>
00104 
00105 /* strlen undefined */
00106 #include <string.h>
00107 #include <malloc.h> /* for calloc */
00108 #endif
00109 #else
00110 
00111 // Not on windows so define this away
00112 #define BASEKIT_API
00113 
00114 #endif
00115 
00116 /*
00117  [DBCS Enabling]
00118 
00119  DBCS (Short for Double-Byte Character Set), a character set that uses two-byte (16-bit) characters. Some languages, such as Chinese, Japanese and Korean (CJK), have writing schemes with many different characters that cannot be represented with single-byte codes such as ASCII and EBCDIC.
00120 
00121  In CJK world, CES (Character Encoding Scheme) and CCS (Coded Character Set) are actually different concept(one CES may contain multiple CCS).
00122  For example, EUC-JP is a CES which includes CCS of ASCII and JIS X 0208 (optionally JIS X 0201 Kana and JIS X 0212).
00123 
00124  In Japanese (because I am Japanese),
00125  While EUC-JP and UTF-8 Map ASCII unchanged, ShiftJIS not (However ShiftJIS is de facto standard in Japan). For example, {0x95, 0x5c} represents one character. in ASCII, second byte(0x5c) is back slash character.
00126  */
00127 
00128 /*
00129  check whether double-byte character. supported only ShiftJIS.
00130  if you want to use ShiftJIS characters in string literal, set compiler option -DDBCS_ENABLED=1.
00131  */
00132 
00133 #if DBCS_ENABLED
00134 #define ismbchar(c)  ISSJIS((unsigned char)c)
00135 #define mbcharlen(c) 2
00136 #define ISSJIS(c)    ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc))
00137 #else
00138 #define ismbchar(c)   0
00139 #define mbcharlen(c)  1
00140 #endif  /* DBCS_ENABLED */
00141 
00142 #ifdef __cplusplus
00143 extern "C" {
00144 #endif
00145 
00146 //#define IO_CHECK_ALLOC
00147 
00148 #ifdef IO_CHECK_ALLOC
00149         BASEKIT_API size_t io_memsize(void *ptr);
00150 
00151         #define io_malloc(size) io_real_malloc(size, __FILE__, __LINE__)
00152         BASEKIT_API void *io_real_malloc(size_t size, char *file, int line);
00153 
00154         #define io_calloc(count, size) io_real_calloc(count, size, __FILE__, __LINE__)
00155         BASEKIT_API void *io_real_calloc(size_t count, size_t size, char *file, int line);
00156 
00157         #define io_realloc(ptr, size) io_real_realloc(ptr, size, __FILE__, __LINE__)
00158         BASEKIT_API void *io_real_realloc(void *ptr, size_t newSize, char *file, int line);
00159 
00160         BASEKIT_API void io_free(void *ptr);
00161         BASEKIT_API void io_show_mem(char *s);
00162         BASEKIT_API size_t io_maxAllocatedBytes(void);
00163         BASEKIT_API void io_resetMaxAllocatedBytes(void);
00164         BASEKIT_API size_t io_frees(void);
00165         BASEKIT_API size_t io_allocs(void);
00166         BASEKIT_API size_t io_allocatedBytes(void);
00167 
00168         BASEKIT_API void io_showUnfreed(void);
00169 #else
00170         #define io_memsize
00171         #define io_malloc malloc
00172         #define io_calloc calloc
00173         #define io_realloc io_freerealloc
00174         #define io_free free
00175         #define io_show_mem
00176 
00177         #define io_maxAllocatedBytes() 0
00178         #define io_frees() 0
00179         #define io_allocs() 0
00180         #define io_allocatedBytes() 0
00181         #define io_resetMaxAllocatedBytes()
00182 #endif
00183 
00184 BASEKIT_API void *cpalloc(const void *p, size_t size);
00185 BASEKIT_API void *io_freerealloc(void *p, size_t size);
00186 
00187 int io_isBigEndian(void);
00188 BASEKIT_API uint32_t io_uint32InBigEndian(uint32_t i);
00189 
00190 #ifdef __cplusplus
00191 }
00192 #endif
00193 
00194 #endif
00195 
00196 
00197 

Generated on Sat Apr 23 11:43:34 2011 for Mnemosyne by  doxygen 1.4.7