Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform/compiler compatibility fixes for kdq and klist #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions kdq.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include <stdlib.h>
#include <string.h>
#include <limits.h>

#define __KDQ_TYPE(type) \
typedef struct { \
size_t front:58, bits:6, count, mask; \
size_t front:((CHAR_BIT * sizeof(size_t)) - 6), bits:6, count, mask; \
type *a; \
} kdq_##type##_t;

Expand Down Expand Up @@ -93,6 +94,14 @@
__KDQ_TYPE(type) \
__KDQ_IMPL(type, SCOPE)

#ifndef klib_inline
#ifdef _MSC_VER
#define klib_inline __inline
#else
#define klib_inline inline
#endif
#endif /* klib_inline */

#ifndef klib_unused
#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3)
#define klib_unused __attribute__ ((__unused__))
Expand All @@ -101,7 +110,7 @@
#endif
#endif /* klib_unused */

#define KDQ_INIT(type) KDQ_INIT2(type, static inline klib_unused)
#define KDQ_INIT(type) KDQ_INIT2(type, static klib_inline klib_unused)

#define KDQ_DECLARE(type) \
__KDQ_TYPE(type) \
Expand Down
14 changes: 7 additions & 7 deletions khash.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ typedef unsigned long khint64_t;
typedef unsigned long long khint64_t;
#endif

#ifndef kh_inline
#ifndef klib_inline
#ifdef _MSC_VER
#define kh_inline __inline
#define klib_inline __inline
#else
#define kh_inline inline
#define klib_inline inline
#endif
#endif /* kh_inline */
#endif /* klib_inline */

#ifndef klib_unused
#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3)
Expand Down Expand Up @@ -363,7 +363,7 @@ static const double __ac_HASH_UPPER = 0.77;
__KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)

#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
KHASH_INIT2(name, static kh_inline klib_unused, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
KHASH_INIT2(name, static klib_inline klib_unused, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)

/* --- BEGIN OF HASH FUNCTIONS --- */

Expand Down Expand Up @@ -392,7 +392,7 @@ static const double __ac_HASH_UPPER = 0.77;
@param s Pointer to a null terminated string
@return The hash value
*/
static kh_inline khint_t __ac_X31_hash_string(const char *s)
static klib_inline khint_t __ac_X31_hash_string(const char *s)
{
khint_t h = (khint_t)*s;
if (h) for (++s ; *s; ++s) h = (h << 5) - h + (khint_t)*s;
Expand All @@ -409,7 +409,7 @@ static kh_inline khint_t __ac_X31_hash_string(const char *s)
*/
#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0)

static kh_inline khint_t __ac_Wang_hash(khint_t key)
static klib_inline khint_t __ac_Wang_hash(khint_t key)
{
key += ~(key << 15);
key ^= (key >> 10);
Expand Down
12 changes: 10 additions & 2 deletions klist.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@

#include <stdlib.h>

#ifndef klib_inline
#ifdef _MSC_VER
#define klib_inline __inline
#else
#define klib_inline inline
#endif
#endif /* klib_inline */

#ifndef klib_unused
#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3)
#define klib_unused __attribute__ ((__unused__))
Expand Down Expand Up @@ -66,7 +74,7 @@
}

#define KMEMPOOL_INIT(name, kmptype_t, kmpfree_f) \
KMEMPOOL_INIT2(static inline klib_unused, name, kmptype_t, kmpfree_f)
KMEMPOOL_INIT2(static klib_inline klib_unused, name, kmptype_t, kmpfree_f)

#define kmempool_t(name) kmp_##name##_t
#define kmp_init(name) kmp_init_##name()
Expand Down Expand Up @@ -118,7 +126,7 @@
}

#define KLIST_INIT(name, kltype_t, kmpfree_t) \
KLIST_INIT2(static inline klib_unused, name, kltype_t, kmpfree_t)
KLIST_INIT2(static klib_inline klib_unused, name, kltype_t, kmpfree_t)

#define kliter_t(name) kl1_##name
#define klist_t(name) kl_##name##_t
Expand Down