Skip to content

Commit

Permalink
compiling cleanly on winblows
Browse files Browse the repository at this point in the history
  • Loading branch information
lloyd committed Apr 25, 2011
1 parent 8b203ac commit 18e45d1
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 38 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Expand Up @@ -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}"
Expand All @@ -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)
Expand Down
59 changes: 37 additions & 22 deletions perf/perftest.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion reformatter/json_reformat.c
Expand Up @@ -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);
Expand All @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/yajl_tree.h
Expand Up @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions src/yajl_tree.c
Expand Up @@ -25,6 +25,10 @@

#include "yajl_parser.h"

#if WIN32
#define snprintf sprintf_s
#endif

#define STATUS_CONTINUE 1
#define STATUS_ABORT 0

Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion verify/json_verify.c
Expand Up @@ -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++) {
Expand Down

0 comments on commit 18e45d1

Please sign in to comment.