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

[WIP]: Add windows support #917

Open
wants to merge 2 commits into
base: main
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
9 changes: 8 additions & 1 deletion bridge/third_party/gumbo-parser/src/attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#include "util.h"

#ifdef _MSC_VER
//not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <strings.h>
#endif

struct GumboInternalParser;

GumboAttribute* gumbo_get_attribute(
Expand Down
10 changes: 9 additions & 1 deletion bridge/third_party/gumbo-parser/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#include "attribute.h"
#include "error.h"
Expand All @@ -32,6 +31,15 @@
#include "util.h"
#include "vector.h"


#ifdef _MSC_VER
//not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <strings.h>
#endif

#define AVOID_UNUSED_VARIABLE_WARNING(i) (void)(i)

#define GUMBO_STRING(literal) \
Expand Down
8 changes: 8 additions & 0 deletions bridge/third_party/gumbo-parser/src/string_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>


#ifdef _MSC_VER
//not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <strings.h>
#endif

#include "string_piece.h"
#include "util.h"
Expand Down
7 changes: 7 additions & 0 deletions bridge/third_party/gumbo-parser/src/string_piece.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>

#ifdef _MSC_VER
//not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <strings.h>
#endif

#include "util.h"

Expand Down
8 changes: 7 additions & 1 deletion bridge/third_party/gumbo-parser/src/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include <strings.h> // For strncasecmp.

#ifdef _MSC_VER
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <strings.h>
#endif

#include "error.h"
#include "gumbo.h"
Expand Down
9 changes: 8 additions & 1 deletion bridge/third_party/gumbo-parser/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <stdio.h>

#include "gumbo.h"
#include "parser.h"

#ifdef _MSC_VER
//not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <strings.h>
#endif

// TODO(jdtang): This should be elsewhere, but there's no .c file for
// SourcePositions and yet the constant needs some linkage, so this is as good
// as any.
Expand Down
8 changes: 8 additions & 0 deletions bridge/third_party/gumbo-parser/src/vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>


#ifdef _MSC_VER
//not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <strings.h>
#endif

#include "util.h"

Expand Down
53 changes: 53 additions & 0 deletions bridge/third_party/quickjs/cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,27 @@
#include <stdlib.h>
#include <inttypes.h>

#ifdef _MSC_VER
#include <intrin.h>
#endif

/* set if CPU is big endian */
#undef WORDS_BIGENDIAN

#ifdef _MSC_VER
#define likely(x) (x)
#define unlikely(x) (x)
#define force_inline __forceinline
#define no_inline __declspec(noinline)
#define __maybe_unused
#define __attribute__(...)
#else
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define force_inline inline __attribute__((always_inline))
#define no_inline __attribute__((noinline))
#define __maybe_unused __attribute__((unused))
#endif

#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)
Expand Down Expand Up @@ -114,27 +127,66 @@ static inline int64_t min_int64(int64_t a, int64_t b)
/* WARNING: undefined if a = 0 */
static inline int clz32(unsigned int a)
{
#ifdef _MSC_VER
unsigned long idx;
_BitScanReverse(&idx, a);
return 31 ^ idx;
#else
return __builtin_clz(a);
#endif
}

/* WARNING: undefined if a = 0 */
static inline int clz64(uint64_t a)
{
#ifdef _MSC_VER
unsigned long idx;
_BitScanReverse64(&idx, a);
return 63 ^ idx;
#else
return __builtin_clzll(a);
#endif
}

/* WARNING: undefined if a = 0 */
static inline int ctz32(unsigned int a)
{
#ifdef _MSC_VER
unsigned long idx;
_BitScanForward(&idx, a);
return 31 ^ idx;
#else
return __builtin_ctz(a);
#endif
}

/* WARNING: undefined if a = 0 */
static inline int ctz64(uint64_t a)
{
#ifdef _MSC_VER
unsigned long idx;
_BitScanForward64(&idx, a);
return 63 ^ idx;
#else
return __builtin_ctzll(a);
#endif
}

#ifdef _MSC_VER
#pragma pack(push, 1)
struct packed_u64 {
uint64_t v;
};

struct packed_u32 {
uint32_t v;
};

struct packed_u16 {
uint16_t v;
};
#pragma pack(pop)
#else
struct __attribute__((packed)) packed_u64 {
uint64_t v;
};
Expand All @@ -146,6 +198,7 @@ struct __attribute__((packed)) packed_u32 {
struct __attribute__((packed)) packed_u16 {
uint16_t v;
};
#endif

static inline uint64_t get_u64(const uint8_t *tab)
{
Expand Down
6 changes: 2 additions & 4 deletions bridge/third_party/quickjs/list.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Linux klist like system
*
*
* Copyright (c) 2016-2017 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -28,8 +28,6 @@
#include <stddef.h>
#endif

#include <stdio.h>

struct list_head {
struct list_head *prev;
struct list_head *next;
Expand All @@ -48,7 +46,7 @@ static inline void init_list_head(struct list_head *head)
}

/* insert 'el' between 'prev' and 'next' */
static inline void __list_add(struct list_head *el,
static inline void __list_add(struct list_head *el,
struct list_head *prev, struct list_head *next)
{
prev->next = el;
Expand Down
Loading