summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLloyd Hilaiel <lloyd@hilaiel.com>2011-04-25 11:16:15 -0700
committerLloyd Hilaiel <lloyd@hilaiel.com>2011-04-25 11:16:15 -0700
commit18e45d1e52e7cd7a4e948b74ae30057ab5d960fe (patch)
tree010ff8a59f073fdeee2a53a6ded3b728a901cc05
parent8b203acbff93612f2e504a9e725ad8a995eaeffc (diff)
downloadyajl-18e45d1e52e7cd7a4e948b74ae30057ab5d960fe.tar.gz
compiling cleanly on winblows
-rw-r--r--CMakeLists.txt4
-rw-r--r--perf/perftest.c59
-rw-r--r--reformatter/json_reformat.c2
-rw-r--r--src/api/yajl_tree.h2
-rw-r--r--src/yajl_tree.c24
-rw-r--r--verify/json_verify.c2
6 files changed, 55 insertions, 38 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3724f58..9315502 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,9 +28,10 @@ IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
IF (WIN32)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
ADD_DEFINITIONS(-DWIN32)
SET(linkFlags "/PDB:NONE /INCREMENTAL:NO /OPT:NOREF /OPT:NOICF")
SET(CMAKE_EXE_LINKER_FLAGS "${linkFlags}"
@@ -48,6 +49,7 @@ IF (WIN32)
SET(CMAKE_C_FLAGS_DEBUG "/D DEBUG /Od /Z7")
SET(CMAKE_C_FLAGS_RELEASE "/D NDEBUG /O2")
ELSE (WIN32)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
IF(CMAKE_COMPILER_IS_GNUCC)
INCLUDE(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_GCC_VISIBILITY)
diff --git a/perf/perftest.c b/perf/perftest.c
index 9618435..e3e7415 100644
--- a/perf/perftest.c
+++ b/perf/perftest.c
@@ -14,36 +14,55 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include "documents.h"
-
#include <yajl/yajl_parse.h>
-#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "documents.h"
+
+/* a platform specific defn' of a function to get a high res time in a
+ * portable format */
+#ifndef WIN32
+#include <sys/time.h>
+double mygettime(void) {
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return now.tv_sec + (now.tv_usec / 1000000.0);
+}
+#else
+#define _WIN32 1
+#include <windows.h>
+double mygettime(void) {
+ long long tval;
+ FILETIME ft;
+ GetSystemTimeAsFileTime(&ft);
+ tval = ft.dwHighDateTime;
+ tval <<=32;
+ tval |= ft.dwLowDateTime;
+ return tval / 10000000.00;
+}
+#endif
+
#define PARSE_TIME_SECS 3
static int
run(int validate_utf8)
{
long long times = 0;
- struct timeval starttime;
- gettimeofday(&starttime, NULL);
+ double starttime;
+
+ starttime = mygettime();
/* allocate a parser */
for (;;) {
+ int i;
{
- struct timeval now;
- gettimeofday(&now, NULL);
- now.tv_sec -= starttime.tv_sec;
- if (now.tv_usec < starttime.tv_usec) {
- now.tv_sec--;
- }
- if (now.tv_sec >= PARSE_TIME_SECS) break;
+ double now = mygettime();
+ if (now - starttime >= PARSE_TIME_SECS) break;
}
- for (int i = 0; i < 100; i++) {
+ for (i = 0; i < 100; i++) {
yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
yajl_status stat;
const char ** d;
@@ -73,22 +92,18 @@ run(int validate_utf8)
/* parsed doc 'times' times */
{
- double then, n;
double throughput;
- struct timeval now;
+ double now;
const char * all_units[] = { "B/s", "KB/s", "MB/s", (char *) 0 };
const char ** units = all_units;
- int avg_doc_size = 0;
-
- gettimeofday(&now, NULL);
+ int i, avg_doc_size = 0;
- then = starttime.tv_sec + (starttime.tv_usec / 1000000.0);
- n = now.tv_sec + (now.tv_usec / 1000000.0);
+ now = mygettime();
- for (int i = 0; i < num_docs(); i++) avg_doc_size += doc_size(i);
+ for (i = 0; i < num_docs(); i++) avg_doc_size += doc_size(i);
avg_doc_size /= num_docs();
- throughput = (times * avg_doc_size) / (n - then);
+ throughput = (times * avg_doc_size) / (now - starttime);
while (*(units + 1) && throughput > 1024) {
throughput /= 1024;
diff --git a/reformatter/json_reformat.c b/reformatter/json_reformat.c
index ba55748..c5b88f0 100644
--- a/reformatter/json_reformat.c
+++ b/reformatter/json_reformat.c
@@ -114,6 +114,7 @@ main(int argc, char ** argv)
yajl_status stat;
size_t rd;
int retval = 0;
+ int a = 1;
g = yajl_gen_alloc(NULL);
yajl_gen_config(g, yajl_gen_beautify, 1);
@@ -125,7 +126,6 @@ main(int argc, char ** argv)
yajl_config(hand, yajl_allow_comments, 1);
/* check arguments.*/
- int a = 1;
while ((a < argc) && (argv[a][0] == '-') && (strlen(argv[a]) > 1)) {
unsigned int i;
for ( i=1; i < strlen(argv[a]); i++) {
diff --git a/src/api/yajl_tree.h b/src/api/yajl_tree.h
index a02c531..8b377f6 100644
--- a/src/api/yajl_tree.h
+++ b/src/api/yajl_tree.h
@@ -72,12 +72,12 @@ struct yajl_val_s
{
char * string;
struct {
- char *r; /*< unparsed number in string form. */
long long i; /*< integer value, if representable. */
double d; /*< double value, if representable. */
/** Signals whether the \em i and \em d members are
* valid. See \c YAJL_NUMBER_INT_VALID and
* \c YAJL_NUMBER_DOUBLE_VALID. */
+ char *r; /*< unparsed number in string form. */
unsigned int flags;
} number;
struct {
diff --git a/src/yajl_tree.c b/src/yajl_tree.c
index e05e41b..17bb7af 100644
--- a/src/yajl_tree.c
+++ b/src/yajl_tree.c
@@ -25,6 +25,10 @@
#include "yajl_parser.h"
+#if WIN32
+#define snprintf sprintf_s
+#endif
+
#define STATUS_CONTINUE 1
#define STATUS_ABORT 0
@@ -46,11 +50,11 @@ struct context_s
};
typedef struct context_s context_t;
-#define RETURN_ERROR(ctx,retval,...) do { \
+#define RETURN_ERROR(ctx,retval,...) { \
if ((ctx)->errbuf != NULL) \
snprintf ((ctx)->errbuf, (ctx)->errbuf_size, __VA_ARGS__); \
return (retval); \
- } while (0) \
+ }
static yajl_val value_alloc (yajl_type type)
{
@@ -78,7 +82,7 @@ static void yajl_object_free (yajl_val v)
v->u.object.values[i] = NULL;
}
- free(v->u.object.keys);
+ free((void*) v->u.object.keys);
free(v->u.object.values);
free(v);
}
@@ -160,7 +164,7 @@ static int object_add_keyval(context_t *ctx,
/* We're assuring that "obj" is an object in "context_add_value". */
assert(YAJL_IS_OBJECT(obj));
- tmpk = realloc(obj->u.object.keys, sizeof(*(obj->u.object.keys)) * (obj->u.object.len + 1));
+ tmpk = realloc((void *) obj->u.object.keys, sizeof(*(obj->u.object.keys)) * (obj->u.object.len + 1));
if (tmpk == NULL)
RETURN_ERROR(ctx, ENOMEM, "Out of memory");
obj->u.object.keys = tmpk;
@@ -415,16 +419,12 @@ yajl_val yajl_tree_parse (const char *input,
/* end array = */ handle_end_array
};
- context_t ctx =
- {
- /* key = */ NULL,
- /* stack = */ NULL,
- /* errbuf = */ error_buffer,
- /* errbuf_size = */ error_buffer_size
- };
-
yajl_handle handle;
yajl_status status;
+ context_t ctx = { NULL, NULL, NULL, 0 };
+
+ ctx.errbuf = error_buffer;
+ ctx.errbuf_size = error_buffer_size;
if (error_buffer != NULL)
memset (error_buffer, 0, error_buffer_size);
diff --git a/verify/json_verify.c b/verify/json_verify.c
index 10e8733..e01f4fd 100644
--- a/verify/json_verify.c
+++ b/verify/json_verify.c
@@ -41,12 +41,12 @@ main(int argc, char ** argv)
static unsigned char fileData[65536];
int quiet = 0;
int retval = 0;
+ int a = 1;
/* allocate a parser */
hand = yajl_alloc(NULL, NULL, NULL);
/* check arguments.*/
- int a = 1;
while ((a < argc) && (argv[a][0] == '-') && (strlen(argv[a]) > 1)) {
unsigned int i;
for ( i=1; i < strlen(argv[a]); i++) {