diff --git a/.clang-format b/.clang-format index ded585e8..ab349356 100644 --- a/.clang-format +++ b/.clang-format @@ -3,3 +3,4 @@ IndentWidth: 4 BreakBeforeBraces: Attach ColumnLimit: 0 AlwaysBreakAfterReturnType: AllDefinitions +PointerBindsToType: false diff --git a/ext/oj/fast.c b/ext/oj/fast.c index 8ca233c2..528c6179 100644 --- a/ext/oj/fast.c +++ b/ext/oj/fast.c @@ -27,16 +27,16 @@ #endif typedef struct _batch { - struct _batch* next; + struct _batch *next; int next_avail; struct _leaf leaves[BATCH_SIZE]; } * Batch; typedef struct _doc { Leaf data; - Leaf* where; // points to current location + Leaf *where; // points to current location Leaf where_path[MAX_STACK]; // points to head of path - char* json; + char *json; unsigned long size; // number of leaves/branches in the doc VALUE self; Batch batches; @@ -44,10 +44,10 @@ typedef struct _doc { } * Doc; typedef struct _parseInfo { - char* str; /* buffer being read from */ - char* s; /* current position in buffer */ + char *str; /* buffer being read from */ + char *s; /* current position in buffer */ Doc doc; - void* stack_min; + void *stack_min; } * ParseInfo; static void leaf_init(Leaf leaf, int type); @@ -67,15 +67,15 @@ static Leaf read_true(ParseInfo pi); static Leaf read_false(ParseInfo pi); static Leaf read_nil(ParseInfo pi); static void next_non_white(ParseInfo pi); -static char* read_quoted_value(ParseInfo pi); +static char *read_quoted_value(ParseInfo pi); static void skip_comment(ParseInfo pi); static VALUE protect_open_proc(VALUE x); -static VALUE parse_json(VALUE clas, char* json, bool given, bool allocated); +static VALUE parse_json(VALUE clas, char *json, bool given, bool allocated); static void each_leaf(Doc doc, VALUE self); -static int move_step(Doc doc, const char* path, int loc); -static Leaf get_doc_leaf(Doc doc, const char* path); -static Leaf get_leaf(Leaf* stack, Leaf* lp, const char* path); +static int move_step(Doc doc, const char *path, int loc); +static Leaf get_doc_leaf(Doc doc, const char *path); +static Leaf get_leaf(Leaf *stack, Leaf *lp, const char *path); static void each_value(Doc doc, Leaf leaf); static void doc_init(Doc doc); @@ -85,21 +85,21 @@ static VALUE doc_open_file(VALUE clas, VALUE filename); static VALUE doc_where(VALUE self); static VALUE doc_local_key(VALUE self); static VALUE doc_home(VALUE self); -static VALUE doc_type(int argc, VALUE* argv, VALUE self); -static VALUE doc_fetch(int argc, VALUE* argv, VALUE self); -static VALUE doc_each_leaf(int argc, VALUE* argv, VALUE self); +static VALUE doc_type(int argc, VALUE *argv, VALUE self); +static VALUE doc_fetch(int argc, VALUE *argv, VALUE self); +static VALUE doc_each_leaf(int argc, VALUE *argv, VALUE self); static VALUE doc_move(VALUE self, VALUE str); -static VALUE doc_each_child(int argc, VALUE* argv, VALUE self); -static VALUE doc_each_value(int argc, VALUE* argv, VALUE self); -static VALUE doc_dump(int argc, VALUE* argv, VALUE self); +static VALUE doc_each_child(int argc, VALUE *argv, VALUE self); +static VALUE doc_each_value(int argc, VALUE *argv, VALUE self); +static VALUE doc_dump(int argc, VALUE *argv, VALUE self); static VALUE doc_size(VALUE self); VALUE oj_doc_class = Qundef; // This is only for CentOS 5.4 with Ruby 1.9.3-p0. #ifndef HAVE_STPCPY -char* -stpcpy(char* dest, const char* src) { +char * +stpcpy(char *dest, const char *src) { size_t cnt = strlen(src); strcpy(dest, src); @@ -127,10 +127,10 @@ next_non_white(ParseInfo pi) { } } -inline static char* -ulong_fill(char* s, size_t num) { +inline static char * +ulong_fill(char *s, size_t num) { char buf[32]; - char* b = buf + sizeof(buf) - 1; + char *b = buf + sizeof(buf) - 1; *b-- = '\0'; for (; 0 < num; num /= 10, b--) { @@ -297,7 +297,7 @@ skip_comment(ParseInfo pi) { static void leaf_fixnum_value(Leaf leaf) { - char* s = leaf->str; + char *s = leaf->str; int64_t n = 0; int neg = 0; int big = 0; @@ -374,7 +374,7 @@ static Leaf read_next(ParseInfo pi) { Leaf leaf = 0; - if ((void*)&leaf < pi->stack_min) { + if ((void *)&leaf < pi->stack_min) { rb_raise(rb_eSysStackError, "JSON is too deeply nested"); } next_non_white(pi); // skip white space @@ -423,8 +423,8 @@ read_next(ParseInfo pi) { static Leaf read_obj(ParseInfo pi) { Leaf h = leaf_new(pi->doc, T_HASH); - char* end; - const char* key = 0; + char *end; + const char *key = 0; Leaf val = 0; pi->s++; @@ -474,7 +474,7 @@ static Leaf read_array(ParseInfo pi) { Leaf a = leaf_new(pi->doc, T_ARRAY); Leaf e; - char* end; + char *end; int cnt = 0; pi->s++; @@ -519,7 +519,7 @@ read_str(ParseInfo pi) { static Leaf read_num(ParseInfo pi) { - char* start = pi->s; + char *start = pi->s; int type = T_FIXNUM; Leaf leaf; @@ -589,7 +589,7 @@ read_nil(ParseInfo pi) { } static uint32_t -read_4hex(ParseInfo pi, const char* h) { +read_4hex(ParseInfo pi, const char *h) { uint32_t b = 0; int i; @@ -608,8 +608,8 @@ read_4hex(ParseInfo pi, const char* h) { return b; } -static char* -unicode_to_chars(ParseInfo pi, char* t, uint32_t code) { +static char * +unicode_to_chars(ParseInfo pi, char *t, uint32_t code) { if (0x0000007F >= code) { *t++ = (char)code; } else if (0x000007FF >= code) { @@ -646,11 +646,11 @@ unicode_to_chars(ParseInfo pi, char* t, uint32_t code) { /* Assume the value starts immediately and goes until the quote character is * reached again. Do not read the character after the terminating quote. */ -static char* +static char * read_quoted_value(ParseInfo pi) { - char* value = 0; - char* h = pi->s; // head - char* t = h; // tail + char *value = 0; + char *h = pi->s; // head + char *t = h; // tail h++; // skip quote character t++; @@ -764,7 +764,7 @@ protect_open_proc(VALUE x) { } static void -free_doc_cb(void* x) { +free_doc_cb(void *x) { Doc doc = (Doc)x; if (0 != doc) { @@ -797,7 +797,7 @@ mark_leaf(Leaf leaf) { } static void -mark_doc(void* ptr) { +mark_doc(void *ptr) { if (NULL != ptr) { Doc doc = (Doc)ptr; @@ -830,7 +830,7 @@ compact_leaf(Leaf leaf) { } static void -compact_doc(void* ptr) { +compact_doc(void *ptr) { Doc doc = (Doc)ptr; if (doc) { @@ -855,7 +855,7 @@ static const rb_data_type_t oj_doc_type = { }; static VALUE -parse_json(VALUE clas, char* json, bool given, bool allocated) { +parse_json(VALUE clas, char *json, bool given, bool allocated) { struct _parseInfo pi; volatile VALUE result = Qnil; Doc doc; @@ -879,13 +879,13 @@ parse_json(VALUE clas, char* json, bool given, bool allocated) { doc_init(doc); pi.doc = doc; #if IS_WINDOWS - pi.stack_min = (void*)((char*)&pi - (512 * 1024)); // assume a 1M stack and give half to ruby + pi.stack_min = (void *)((char *)&pi - (512 * 1024)); // assume a 1M stack and give half to ruby #else { struct rlimit lim; if (0 == getrlimit(RLIMIT_STACK, &lim) && RLIM_INFINITY != lim.rlim_cur) { - pi.stack_min = (void*)((char*)&lim - (lim.rlim_cur / 4 * 3)); // let 3/4ths of the stack be used only + pi.stack_min = (void *)((char *)&lim - (lim.rlim_cur / 4 * 3)); // let 3/4ths of the stack be used only } else { pi.stack_min = 0; // indicates not to check stack limit } @@ -913,12 +913,12 @@ parse_json(VALUE clas, char* json, bool given, bool allocated) { } static Leaf -get_doc_leaf(Doc doc, const char* path) { +get_doc_leaf(Doc doc, const char *path) { Leaf leaf = *doc->where; if (0 != doc->data && 0 != path) { Leaf stack[MAX_STACK]; - Leaf* lp; + Leaf *lp; if ('/' == *path) { path++; @@ -941,8 +941,8 @@ get_doc_leaf(Doc doc, const char* path) { return leaf; } -static const char* -next_slash(const char* s) { +static const char * +next_slash(const char *s) { for (; '\0' != *s; s++) { if ('\\' == *s) { s++; @@ -957,7 +957,7 @@ next_slash(const char* s) { } static bool -key_match(const char* pat, const char* key, int plen) { +key_match(const char *pat, const char *key, int plen) { for (; 0 < plen; plen--, pat++, key++) { if ('\\' == *pat) { plen--; @@ -971,7 +971,7 @@ key_match(const char* pat, const char* key, int plen) { } static Leaf -get_leaf(Leaf* stack, Leaf* lp, const char* path) { +get_leaf(Leaf *stack, Leaf *lp, const char *path) { Leaf leaf = *lp; if (MAX_STACK <= lp - stack) { @@ -1014,8 +1014,8 @@ get_leaf(Leaf* stack, Leaf* lp, const char* path) { e = e->next; } while (e != first); } else if (T_HASH == type) { - const char* key = path; - const char* slash = next_slash(path); + const char *key = path; + const char *slash = next_slash(path); int klen; if (0 == slash) { @@ -1064,7 +1064,7 @@ each_leaf(Doc doc, VALUE self) { } static int -move_step(Doc doc, const char* path, int loc) { +move_step(Doc doc, const char *path, int loc) { if (MAX_STACK <= doc->where - doc->where_path) { rb_raise(rb_const_get_at(Oj, rb_intern("DepthError")), "Path too deep. Limit is %d levels.", MAX_STACK); } @@ -1124,8 +1124,8 @@ move_step(Doc doc, const char* path, int loc) { e = e->next; } while (e != first); } else if (T_HASH == leaf->rtype) { - const char* key = path; - const char* slash = next_slash(path); + const char *key = path; + const char *slash = next_slash(path); int klen; if (0 == slash) { @@ -1192,7 +1192,7 @@ each_value(Doc doc, Leaf leaf) { */ static VALUE doc_open(VALUE clas, VALUE str) { - char* json; + char *json; size_t len; volatile VALUE obj; int given = rb_block_given_p(); @@ -1240,9 +1240,9 @@ doc_open(VALUE clas, VALUE str) { */ static VALUE doc_open_file(VALUE clas, VALUE filename) { - char* path; - char* json; - FILE* f; + char *path; + char *json; + FILE *f; size_t len; volatile VALUE obj; int given = rb_block_given_p(); @@ -1281,7 +1281,7 @@ doc_open_file(VALUE clas, VALUE filename) { } static int -esc_strlen(const char* s) { +esc_strlen(const char *s) { int cnt = 0; for (; '\0' != *s; s++, cnt++) { @@ -1292,8 +1292,8 @@ esc_strlen(const char* s) { return cnt; } -static char* -append_key(char* p, const char* key) { +static char * +append_key(char *p, const char *key) { for (; '\0' != *key; p++, key++) { if ('/' == *key) { *p++ = '\\'; @@ -1319,11 +1319,11 @@ doc_where(VALUE self) { if (0 == *doc->where_path || doc->where == doc->where_path) { return oj_slash_string; } else { - Leaf* lp; + Leaf *lp; Leaf leaf; size_t size = 3; // leading / and terminating \0 - char* path; - char* p; + char *path; + char *p; for (lp = doc->where_path; lp <= doc->where; lp++) { leaf = *lp; @@ -1402,10 +1402,10 @@ doc_home(VALUE self) { * Oj::Doc.open('[1,2]') { |doc| doc.type('/1') } #=> Fixnum */ static VALUE -doc_type(int argc, VALUE* argv, VALUE self) { +doc_type(int argc, VALUE *argv, VALUE self) { Doc doc = self_doc(self); Leaf leaf; - const char* path = 0; + const char *path = 0; VALUE type = Qnil; if (1 <= argc) { @@ -1464,11 +1464,11 @@ doc_type(int argc, VALUE* argv, VALUE self) { * Oj::Doc.open('[1,2]') { |doc| doc.fetch('/1') } #=> 1 */ static VALUE -doc_fetch(int argc, VALUE* argv, VALUE self) { +doc_fetch(int argc, VALUE *argv, VALUE self) { Doc doc; Leaf leaf; volatile VALUE val = Qnil; - const char* path = 0; + const char *path = 0; doc = self_doc(self); if (1 <= argc) { @@ -1500,11 +1500,11 @@ doc_fetch(int argc, VALUE* argv, VALUE self) { * #=> ["/1" => 3, "/2/1" => 2, "/2/2" => 1] */ static VALUE -doc_each_leaf(int argc, VALUE* argv, VALUE self) { +doc_each_leaf(int argc, VALUE *argv, VALUE self) { if (rb_block_given_p()) { Leaf save_path[MAX_STACK]; Doc doc = self_doc(self); - const char* path = 0; + const char *path = 0; size_t wlen; wlen = doc->where - doc->where_path; @@ -1544,7 +1544,7 @@ doc_each_leaf(int argc, VALUE* argv, VALUE self) { static VALUE doc_move(VALUE self, VALUE str) { Doc doc = self_doc(self); - const char* path; + const char *path; int loc; Check_Type(str, T_STRING); @@ -1576,11 +1576,11 @@ doc_move(VALUE self, VALUE str) { * #=> ["/2/1", "/2/2"] */ static VALUE -doc_each_child(int argc, VALUE* argv, VALUE self) { +doc_each_child(int argc, VALUE *argv, VALUE self) { if (rb_block_given_p()) { Leaf save_path[MAX_STACK]; Doc doc = self_doc(self); - const char* path = 0; + const char *path = 0; size_t wlen; wlen = doc->where - doc->where_path; @@ -1643,10 +1643,10 @@ doc_each_child(int argc, VALUE* argv, VALUE self) { * #=> [2, 1] */ static VALUE -doc_each_value(int argc, VALUE* argv, VALUE self) { +doc_each_value(int argc, VALUE *argv, VALUE self) { if (rb_block_given_p()) { Doc doc = self_doc(self); - const char* path = 0; + const char *path = 0; Leaf leaf; if (1 <= argc) { @@ -1673,11 +1673,11 @@ doc_each_value(int argc, VALUE* argv, VALUE self) { * #=> "[2,1]" */ static VALUE -doc_dump(int argc, VALUE* argv, VALUE self) { +doc_dump(int argc, VALUE *argv, VALUE self) { Doc doc = self_doc(self); Leaf leaf; - const char* path = 0; - const char* filename = 0; + const char *path = 0; + const char *filename = 0; if (1 <= argc) { if (Qnil != *argv) {