/*
- * Copyright (c) 2009, 2010, 2011 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "json.h"
-#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
const char *
json_string(const struct json *json)
{
- assert(json->type == JSON_STRING);
+ ovs_assert(json->type == JSON_STRING);
return json->u.string;
}
struct json_array *
json_array(const struct json *json)
{
- assert(json->type == JSON_ARRAY);
- return (struct json_array *) &json->u.array;
+ ovs_assert(json->type == JSON_ARRAY);
+ return CONST_CAST(struct json_array *, &json->u.array);
}
struct shash *
json_object(const struct json *json)
{
- assert(json->type == JSON_OBJECT);
- return (struct shash *) json->u.object;
+ ovs_assert(json->type == JSON_OBJECT);
+ return CONST_CAST(struct shash *, json->u.object);
}
bool
json_boolean(const struct json *json)
{
- assert(json->type == JSON_TRUE || json->type == JSON_FALSE);
+ ovs_assert(json->type == JSON_TRUE || json->type == JSON_FALSE);
return json->type == JSON_TRUE;
}
double
json_real(const struct json *json)
{
- assert(json->type == JSON_REAL || json->type == JSON_INTEGER);
+ ovs_assert(json->type == JSON_REAL || json->type == JSON_INTEGER);
return json->type == JSON_REAL ? json->u.real : json->u.integer;
}
int64_t
json_integer(const struct json *json)
{
- assert(json->type == JSON_INTEGER);
+ ovs_assert(json->type == JSON_INTEGER);
return json->u.integer;
}
\f
break;
case JSON_N_TYPES:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
free(json);
}
case JSON_N_TYPES:
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
case JSON_N_TYPES:
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
case JSON_N_TYPES:
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
\f
significand = 0;
if (*cp == '0') {
cp++;
- if (isdigit(*cp)) {
+ if (isdigit((unsigned char) *cp)) {
json_error(p, "leading zeros not allowed");
return;
}
- } else if (isdigit(*cp)) {
+ } else if (isdigit((unsigned char) *cp)) {
do {
if (significand <= ULLONG_MAX / 10) {
significand = significand * 10 + (*cp - '0');
}
}
cp++;
- } while (isdigit(*cp));
+ } while (isdigit((unsigned char) *cp));
} else {
json_error(p, "'-' must be followed by digit");
return;
/* Optional fraction. */
if (*cp == '.') {
cp++;
- if (!isdigit(*cp)) {
+ if (!isdigit((unsigned char) *cp)) {
json_error(p, "decimal point must be followed by digit");
return;
}
imprecise = true;
}
cp++;
- } while (isdigit(*cp));
+ } while (isdigit((unsigned char) *cp));
}
/* Optional exponent. */
cp++;
}
- if (!isdigit(*cp)) {
+ if (!isdigit((unsigned char) *cp)) {
json_error(p, "exponent must contain at least one digit");
return;
}
}
exponent = exponent * 10 + (*cp - '0');
cp++;
- } while (isdigit(*cp));
+ } while (isdigit((unsigned char) *cp));
if (negative_exponent) {
pow10 -= exponent;
stream = fopen(file_name, "r");
if (!stream) {
return json_string_create_nocopy(
- xasprintf("error opening \"%s\": %s", file_name, strerror(errno)));
+ xasprintf("error opening \"%s\": %s", file_name,
+ ovs_strerror(errno)));
}
json = json_from_stream(stream);
fclose(stream);
if (ferror(stream)) {
json_destroy(json);
json = json_string_create_nocopy(
- xasprintf("error reading JSON stream: %s", strerror(errno)));
+ xasprintf("error reading JSON stream: %s", ovs_strerror(errno)));
}
return json;
}
if (!p->error) {
- assert(p->height == 1);
- assert(p->stack[0].json != NULL);
+ ovs_assert(p->height == 1);
+ ovs_assert(p->stack[0].json != NULL);
json = p->stack[--p->height].json;
} else {
json = json_string_create_nocopy(p->error);
} else if (node->json->type == JSON_ARRAY) {
json_array_add(node->json, value);
} else {
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
} else if (node->json->type == JSON_OBJECT) {
p->parse_state = JSON_PARSE_OBJECT_NEXT;
} else {
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
}
case JSON_N_TYPES:
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}