Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow uint64_t for numeric storage, and macros to define it

Also fixed up some makefile deps and documentation typos
  • Loading branch information...
commit 2475b792eb56a39b05c476fc6fc821a85bd0f9b4 1 parent 2f7bdb2
@mnunberg authored
Showing with 53 additions and 28 deletions.
  1. +2 −2 Makefile
  2. +3 −1 jsonsl.c
  3. +48 −25 jsonsl.h
View
4 Makefile
@@ -3,7 +3,7 @@ LDFLAGS=-L$(LIBJSONSL_DIR) -Wl,-rpath $(LIBJSONSL_DIR) -ljsonsl $(PROFILE)
CFLAGS=\
-Wall -std=gnu89 -pedantic \
-O3 -ggdb3 \
- -I$(LIBJSONSL_DIR) -DJSONSL_STATE_GENERIC
+ -I$(LIBJSONSL_DIR) -DJSONSL_STATE_GENERIC \
export CFLAGS
export LDFLAGS
@@ -21,7 +21,7 @@ json_examples_tarball:
rm -f json_samples.tgz
tar -czf json_samples.tgz share
-check: libjsonsl.so share
+check: libjsonsl.so share jsonsl.c
JSONSL_QUIET_TESTS=1 $(MAKE) -C tests
bench:
View
4 jsonsl.c
@@ -86,6 +86,7 @@ case '9': \
case '0':
+
/**
* This table (predeclared) contains characters which are recognized
* non-string values.
@@ -278,7 +279,7 @@ jsonsl_feed(jsonsl_t jsn, const jsonsl_char_t *bytes, size_t nbytes)
INCR_METRIC(STRINGY_SLOWPATH);
} else if (state_type == JSONSL_T_SPECIAL) {
- if (state->special_flags & (JSONSL_SPECIALf_SIGNED|JSONSL_SPECIALf_UNSIGNED)) {
+ if (state->special_flags & JSONSL_SPECIALf_NUMERIC) {
switch (CUR_CHAR) {
CASE_DIGITS
state->nelem = (state->nelem*10) + (CUR_CHAR-0x30);
@@ -301,6 +302,7 @@ jsonsl_feed(jsonsl_t jsn, const jsonsl_char_t *bytes, size_t nbytes)
break;
}
}
+ /* else if (!NUMERIC) */
if (!is_special_end(CUR_CHAR)) {
/* Verify TRUE, FALSE, NULL */
if (state->special_flags == JSONSL_SPECIALf_TRUE) {
View
73 jsonsl.h
@@ -27,6 +27,24 @@ typedef char jsonsl_char_t;
typedef unsigned char jsonsl_uchar_t;
#endif /* JSONSL_USE_WCHAR */
+/* Stolen from http-parser.h, and possibly others */
+#if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600)
+typedef __int8 int8_t;
+typedef unsigned __int8 uint8_t;
+typedef __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+
+typedef unsigned int size_t;
+typedef int ssize_t;
+#else
+#include <stdint.h>
+#endif
+
+
#if (!defined(JSONSL_STATE_GENERIC)) && (!defined(JSONSL_STATE_USER_FIELDS))
#warning "JSONSL_STATE_USER_FIELDS not defined. Define this for extra structure fields"
#warning "or define JSONSL_STATE_GENERIC"
@@ -107,7 +125,9 @@ typedef enum {
/* Handy flags for checking */
JSONSL_SPECIALf_UNKNOWN = 1 << 8,
JSONSL_SPECIALf_NUMERIC = (JSONSL_SPECIALf_SIGNED|JSONSL_SPECIALf_UNSIGNED),
- JSONSL_SPECIALf_BOOLEAN = (JSONSL_SPECIALf_TRUE|JSONSL_SPECIALf_FALSE)
+ JSONSL_SPECIALf_BOOLEAN = (JSONSL_SPECIALf_TRUE|JSONSL_SPECIALf_FALSE),
+ /* For non-simple numeric types */
+ JSONSL_SPECIALf_NUMNOINT = (JSONSL_SPECIALf_FLOAT|JSONSL_SPECIALf_EXPONENT)
} jsonsl_special_t;
@@ -202,29 +222,6 @@ struct jsonsl_state_st {
jsonsl_special_t special_flags;
/**
- * how many elements in the object/list.
- * For objects (hashes), an element is either
- * a key or a value. Thus for one complete pair,
- * nelem will be 2.
- *
- * For special types, this will hold the sum of the digits.
- * This only holds true for values which are simple signed/unsigned
- * numbers. Otherwise a special flag is set, and extra handling is not
- * performed.
- */
- unsigned long nelem;
-
-
- /**
- * Level of recursion into nesting. This is mainly a convenience
- * variable, as this can technically be deduced from the lexer's
- * level parameter (though the logic is not that simple)
- */
- unsigned int level;
-
- /*TODO: merge this and special_flags into a union */
-
- /**
* Position offset variables. These are relative to jsn->pos.
* pos_begin is the position at which this state was first pushed
* to the stack. pos_cur is the position at which return last controlled
@@ -243,6 +240,32 @@ struct jsonsl_state_st {
/**
+ * Level of recursion into nesting. This is mainly a convenience
+ * variable, as this can technically be deduced from the lexer's
+ * level parameter (though the logic is not that simple)
+ */
+ unsigned int level;
+
+
+ /**
+ * how many elements in the object/list.
+ * For objects (hashes), an element is either
+ * a key or a value. Thus for one complete pair,
+ * nelem will be 2.
+ *
+ * For special types, this will hold the sum of the digits.
+ * This only holds true for values which are simple signed/unsigned
+ * numbers. Otherwise a special flag is set, and extra handling is not
+ * performed.
+ */
+ uint64_t nelem;
+
+
+
+ /*TODO: merge this and special_flags into a union */
+
+
+ /**
* Useful for an opening nest, this will prevent a callback from being
* invoked on this item or any of its children
*/
@@ -262,7 +285,7 @@ struct jsonsl_state_st {
#else
/**
- * Otherwise, this is a simple void * pointer for anything yoiu want
+ * Otherwise, this is a simple void * pointer for anything you want
*/
void *data;
#endif /* JSONSL_STATE_USER_FIELDS */

0 comments on commit 2475b79

Please sign in to comment.
Something went wrong with that request. Please try again.