Skip to content

Commit

Permalink
Merge pull request h2o#12 from dacci/msvc
Browse files Browse the repository at this point in the history
Makes it compatible with VC++ compiler.
  • Loading branch information
kazuho committed Dec 27, 2014
2 parents ab73dd8 + e0cec2c commit eb83328
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
16 changes: 13 additions & 3 deletions picohttpparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
#include <stddef.h>
#include <string.h>
#ifdef __SSE4_2__
# include <x86intrin.h>
# ifdef _MSC_VER
# include <nmmintrin.h>
# else
# include <x86intrin.h>
# endif
#endif
#include "picohttpparser.h"

Expand All @@ -42,6 +46,12 @@
# define unlikely(x) (x)
#endif

#ifdef _MSC_VER
# define ALIGNED(n) _declspec(align(n))
#else
# define ALIGNED(n) __attribute__((aligned(n)))
#endif

#define IS_PRINTABLE_ASCII(c) ((unsigned char)(c) - 040u < 0137u)

#define CHECK_EOF() \
Expand All @@ -59,7 +69,7 @@

#define ADVANCE_TOKEN(tok, toklen) do { \
const char* tok_start = buf; \
static const char ranges2[] __attribute__((aligned(16))) = "\000\040\177\177"; \
static const char ALIGNED(16) ranges2[] = "\000\040\177\177"; \
int found2; \
buf = findchar_fast(buf, buf_end, ranges2, sizeof(ranges2) - 1, &found2); \
if (! found2) { \
Expand Down Expand Up @@ -263,7 +273,7 @@ static const char* parse_headers(const char* buf, const char* buf_end,
/* parsing name, but do not discard SP before colon, see
* http://www.mozilla.org/security/announce/2006/mfsa2006-33.html */
headers[*num_headers].name = buf;
static const char ranges1[] __attribute__((aligned(16))) = "::\x00\037";
static const char ALIGNED(16) ranges1[] = "::\x00\037";
int found;
buf = findchar_fast(buf, buf_end, ranges1, sizeof(ranges1) - 1, &found);
if (! found) {
Expand Down
4 changes: 4 additions & 0 deletions picohttpparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#include <sys/types.h>

#ifdef _MSC_VER
# define ssize_t intptr_t
#endif

/* $Id$ */

#ifdef __cplusplus
Expand Down
6 changes: 3 additions & 3 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ static void test_chunked_at_once(int line, int consume_trailer,
const char *encoded, const char *decoded,
ssize_t expected)
{
struct phr_chunked_decoder dec = {};
struct phr_chunked_decoder dec = {0};
char *buf;
size_t bufsz;
ssize_t ret;
Expand Down Expand Up @@ -318,7 +318,7 @@ static void test_chunked_per_byte(int line, int consume_trailer,
const char *encoded, const char *decoded,
ssize_t expected)
{
struct phr_chunked_decoder dec = {};
struct phr_chunked_decoder dec = {0};
char *buf = malloc(strlen(encoded) + 1);
size_t bytes_to_consume = strlen(encoded) - (expected >= 0 ? expected : 0),
bytes_ready = 0, bufsz, i;
Expand Down Expand Up @@ -357,7 +357,7 @@ static void test_chunked_per_byte(int line, int consume_trailer,

static void test_chunked_failure(int line, const char *encoded, ssize_t expected)
{
struct phr_chunked_decoder dec = {};
struct phr_chunked_decoder dec = {0};
char *buf = strdup(encoded);
size_t bufsz, i;
ssize_t ret;
Expand Down

0 comments on commit eb83328

Please sign in to comment.