1
0
forked from GitHub/gf-core

a patch from Bjørnar Luteberget for compatibility with MSVC

This commit is contained in:
krasimir
2017-04-12 10:24:56 +00:00
parent 915747efa7
commit a8eaa2f2e5
17 changed files with 72 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
#include <gu/defs.h>
void* const gu_null = NULL;
GuStruct* const gu_null_struct = NULL;
GU_API_DATA GuStruct* const gu_null_struct = NULL;

View File

@@ -25,6 +25,24 @@
#ifndef GU_DEFS_H_
#define GU_DEFS_H_
// MSVC requires explicit export/import of
// symbols in DLLs. CMake takes care of this
// for functions, but not for data/variables.
#if defined(_MSC_VER)
#if defined(COMPILING_GU)
#define GU_API_DATA_DECL __declspec(dllexport)
#define GU_API_DATA __declspec(dllexport)
#else
#define GU_API_DATA_DECL __declspec(dllimport)
#define GU_API_DATA ERROR_NOT_COMPILING_LIBGU
#endif
#else
#define GU_API_DATA_DECL extern
#define GU_API_DATA
#endif
// end MSVC workaround
#include <stddef.h>
#include <inttypes.h>
#include <stdbool.h>
@@ -154,7 +172,7 @@ extern void* const gu_null;
// Dummy struct used for generic struct pointers
typedef struct GuStruct GuStruct;
extern GuStruct* const gu_null_struct;
GU_API_DATA_DECL GuStruct* const gu_null_struct;
typedef uintptr_t GuWord;

View File

@@ -25,7 +25,7 @@ gu_int_hash_fn(GuHasher* self, const void* p)
return (GuHash) *(const int*) p;
}
GuHasher gu_int_hasher[1] = {
GU_API_DATA GuHasher gu_int_hasher[1] = {
{
{ gu_int_eq_fn },
gu_int_hash_fn
@@ -46,7 +46,7 @@ gu_addr_hash_fn(GuHasher* self, const void* p)
return (GuHash) (uintptr_t) p;
}
GuHasher gu_addr_hasher[1] = {
GU_API_DATA GuHasher gu_addr_hasher[1] = {
{
{ gu_addr_eq_fn },
gu_addr_hash_fn
@@ -69,7 +69,7 @@ gu_word_hash_fn(GuHasher* self, const void* p)
return (GuHash) (uintptr_t) p;
}
GuHasher gu_word_hasher[1] = {
GU_API_DATA GuHasher gu_word_hasher[1] = {
{
{ gu_word_eq_fn },
gu_word_hash_fn

View File

@@ -31,10 +31,10 @@ struct GuHasher {
};
extern GuHasher gu_int_hasher[1];
GU_API_DATA GuHasher gu_int_hasher[1];
extern GuHasher gu_addr_hasher[1];
GU_API_DATA GuHasher gu_addr_hasher[1];
extern GuHasher gu_word_hasher[1];
GU_API_DATA GuHasher gu_word_hasher[1];
#endif // GU_HASH_H_

View File

@@ -8,7 +8,9 @@
#include <sys/mman.h>
#include <sys/stat.h>
#endif
#if !defined(_MSC_VER)
#include <unistd.h>
#endif
#include <fcntl.h>
#ifdef USE_VALGRIND

View File

@@ -3,7 +3,7 @@
#include <gu/fun.h>
#include <gu/assert.h>
#include <stdlib.h>
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <malloc.h>
#endif

View File

@@ -5,7 +5,7 @@
#include <gu/utf8.h>
#include <gu/assert.h>
#include <stdlib.h>
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <malloc.h>
#endif
@@ -273,7 +273,7 @@ gu_string_eq_fn(GuEquality* self, const void* p1, const void* p2)
return strcmp((GuString) p1, (GuString) p2) == 0;
}
GuEquality gu_string_equality[1] = { { gu_string_eq_fn } };
GU_API_DATA GuEquality gu_string_equality[1] = { { gu_string_eq_fn } };
static int
gu_string_cmp_fn(GuOrder* self, const void* p1, const void* p2)
@@ -282,7 +282,7 @@ gu_string_cmp_fn(GuOrder* self, const void* p1, const void* p2)
return strcmp((GuString) p1, (GuString) p2);
}
GuOrder gu_string_order[1] = { { gu_string_cmp_fn } };
GU_API_DATA GuOrder gu_string_order[1] = { { gu_string_cmp_fn } };
static GuHash
gu_string_hasher_hash(GuHasher* self, const void* p)
@@ -291,7 +291,7 @@ gu_string_hasher_hash(GuHasher* self, const void* p)
return gu_string_hash(0, (GuString) p);
}
GuHasher gu_string_hasher[1] = {
GU_API_DATA GuHasher gu_string_hasher[1] = {
{
.eq = { gu_string_eq_fn },
.hash = gu_string_hasher_hash

View File

@@ -58,9 +58,9 @@ gu_string_is_prefix(GuString s1, GuString s2);
#if defined(GU_FUN_H_) && !defined(GU_STRING_H_FUN_)
#define GU_STRING_H_FUN_
extern GuEquality gu_string_equality[1];
GU_API_DATA GuEquality gu_string_equality[1];
extern GuOrder gu_string_order[1];
GU_API_DATA GuOrder gu_string_order[1];
#endif
#if defined(GU_HASH_H_) && !defined(GU_STRING_H_HASH_)
@@ -69,7 +69,7 @@ extern GuOrder gu_string_order[1];
GuHash
gu_string_hash(GuHash h, GuString s);
extern GuHasher gu_string_hasher[1];
GU_API_DATA GuHasher gu_string_hasher[1];
#endif
#if defined(GU_SEQ_H_) && !defined(GU_STRING_H_SEQ_)

View File

@@ -108,4 +108,4 @@ gu_variant_intval(GuVariant variant)
return (variant / GU_VARIANT_ALIGNMENT);
}
const GuVariant gu_null_variant = { (GuWord) NULL };
GU_API_DATA const GuVariant gu_null_variant = { (GuWord) NULL };

View File

@@ -97,7 +97,7 @@ gu_variant_from_ptr(const void* p)
return (uintptr_t) p;
}
extern const GuVariant gu_null_variant;
GU_API_DATA const GuVariant gu_null_variant;
static inline bool
gu_variant_is_null(GuVariant v) {

View File

@@ -56,7 +56,7 @@ typedef struct {
PgfPatt patt;
} PgfPattAs;
typedef void PgfPattWild;
typedef char PgfPattWild;
typedef struct {
PgfPatt patt;
@@ -241,12 +241,15 @@ typedef struct PgfSymbolKP
} PgfSymbolKP;
typedef struct {
char nothing[0]; // Empty struct
} PgfSymbolNE;
typedef struct {
char nothing[0]; // Empty struct
} PgfSymbolBIND;
typedef struct {
char nothing[0]; // Empty struct
} PgfSymbolCAPIT;
typedef GuBuf PgfProductionIdx;

View File

@@ -437,7 +437,7 @@ pgf_evaluate_accum_init_flt(PgfReasoner* rs,
rs->pool);
lit_flt->val = val;
accum->enter_stack_ptr = rs->enter_stack_ptr;
rs->enter_stack_ptr = ((void*)accum)-sizeof(void*)*2;
rs->enter_stack_ptr = ((char*)accum)-sizeof(char*)*2;
accum->consts = NULL;
}

View File

@@ -5,7 +5,7 @@
#include <pgf/reasoner.h>
#include <pgf/reader.h>
#include "lightning.h"
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <malloc.h>
#endif
@@ -43,7 +43,7 @@ typedef struct {
#define JIT_VSTATE JIT_V1
#define JIT_VCLOS JIT_V2
#if defined(__MINGW32__)
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <windows.h>
static int
@@ -71,7 +71,7 @@ pgf_jit_alloc_page(PgfReader* rdr)
#if defined(ANDROID)
if ((page = memalign(page_size, page_size)) == NULL) {
#elif defined(__MINGW32__)
#elif defined(__MINGW32__) || defined(_MSC_VER)
if ((page = malloc(page_size)) == NULL) {
#else
if (posix_memalign(&page, page_size, page_size) != 0) {

View File

@@ -29,6 +29,7 @@ PgfCncTreeEnum*
pgf_lzr_concretize(PgfConcr* concr, PgfExpr expr, GuExn* err, GuPool* pool);
typedef struct {
char nothing[0]; // Empty struct
} PgfLinNonExist;
PgfCncTree

View File

@@ -334,7 +334,7 @@ pgf_match_name_lit(PgfLiteralCallback* self, PgfConcr* concr,
return ep;
}
PgfLiteralCallback pgf_nerc_literal_callback =
PGF_API_DATA PgfLiteralCallback pgf_nerc_literal_callback =
{ pgf_match_name_lit, pgf_predict_empty } ;
static void
@@ -419,7 +419,7 @@ pgf_match_unknown_lit(PgfLiteralCallback* self, PgfConcr* concr,
return ep;
}
PgfLiteralCallback pgf_unknown_literal_callback =
PGF_API_DATA PgfLiteralCallback pgf_unknown_literal_callback =
{ pgf_match_unknown_lit, pgf_predict_empty } ;
PgfCallbacksMap*

View File

@@ -1,13 +1,33 @@
#ifndef PGF_LITERALS_H_
#define PGF_LITERALS_H_
// MSVC requires explicit export/import of
// symbols in DLLs. CMake takes care of this
// for functions, but not for data/variables.
#if defined(_MSC_VER)
#if defined(COMPILING_PGF)
#define PGF_API_DATA_DECL __declspec(dllexport)
#define PGF_API_DATA __declspec(dllexport)
#else
#define PGF_API_DATA_DECL __declspec(dllimport)
#define PGF_API_DATA ERROR_NOT_COMPILING_LIBPGF
#endif
#else
#define PGF_API_DATA_DECL extern
#define PGF_API_DATA
#endif
// end MSVC workaround
#include <pgf/data.h>
// literal for named entities recognition
extern PgfLiteralCallback pgf_nerc_literal_callback;
PGF_API_DATA_DECL PgfLiteralCallback pgf_nerc_literal_callback;
// literal for finding unknown words
extern PgfLiteralCallback pgf_unknown_literal_callback;
PGF_API_DATA_DECL PgfLiteralCallback pgf_unknown_literal_callback;
PgfCCat*
pgf_literal_cat(PgfConcr* concr, PgfLiteral lit);

View File

@@ -14,7 +14,7 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <malloc.h>
#endif