From 8d4c259a1f9eb9fbbab3de3fdcdaf58572648b36 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 30 Nov 2023 10:28:07 +0100 Subject: [PATCH] Remove useless DATA_PTR call and appease clang-format --- ext/oj/cache.c | 4 ++-- ext/oj/dump.c | 7 +++++-- ext/oj/fast.c | 13 +++++++------ ext/oj/oj.h | 1 + ext/oj/parser.c | 15 +++++++++++---- ext/oj/rails.c | 4 +++- ext/oj/string_writer.c | 2 +- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/ext/oj/cache.c b/ext/oj/cache.c index 0f151d82..5669b676 100644 --- a/ext/oj/cache.c +++ b/ext/oj/cache.c @@ -261,7 +261,7 @@ void cache_set_expunge_rate(Cache c, int rate) { } void cache_free(void *data) { - Cache c = (Cache)data; + Cache c = (Cache)data; uint64_t i; for (i = 0; i < c->size; i++) { @@ -278,7 +278,7 @@ void cache_free(void *data) { } void cache_mark(void *data) { - Cache c = (Cache)data; + Cache c = (Cache)data; uint64_t i; #if !HAVE_PTHREAD_MUTEX_INIT diff --git a/ext/oj/dump.c b/ext/oj/dump.c index 122e3a3d..1f5bfbe9 100644 --- a/ext/oj/dump.c +++ b/ext/oj/dump.c @@ -727,8 +727,11 @@ static void debug_raise(const char *orig, size_t cnt, int line) { void oj_dump_raw_json(VALUE obj, int depth, Out out) { if (oj_string_writer_class == rb_obj_class(obj)) { - StrWriter sw = oj_str_writer_unwrap(obj); - size_t len = sw->out.cur - sw->out.buf; + StrWriter sw; + size_t len; + + sw = oj_str_writer_unwrap(obj); + len = sw->out.cur - sw->out.buf; if (0 < len) { len--; diff --git a/ext/oj/fast.c b/ext/oj/fast.c index ee53716d..841e0d50 100644 --- a/ext/oj/fast.c +++ b/ext/oj/fast.c @@ -780,11 +780,10 @@ static VALUE parse_json(VALUE clas, char *json, bool given) { } } #endif - doc->json = json; - self = TypedData_Wrap_Struct(clas, &oj_doc_type, doc); - doc->self = self; - DATA_PTR(doc->self) = doc; - result = rb_protect(protect_open_proc, (VALUE)&pi, &ex); + doc->json = json; + self = TypedData_Wrap_Struct(clas, &oj_doc_type, doc); + doc->self = self; + result = rb_protect(protect_open_proc, (VALUE)&pi, &ex); if (given || 0 != ex) { DATA_PTR(doc->self) = NULL; // TBD is this needed? @@ -1609,7 +1608,9 @@ static VALUE doc_dump(int argc, VALUE *argv, VALUE self) { * Oj::Doc.open('[1,2,3]') { |doc| doc.size() } #=> 4 */ static VALUE doc_size(VALUE self) { - return ULONG2NUM(((Doc)DATA_PTR(self))->size); + Doc d; + TypedData_Get_Struct(self, struct _doc, &oj_doc_type, d); + return ULONG2NUM(d->size); } /* @overload close() => nil diff --git a/ext/oj/oj.h b/ext/oj/oj.h index ce4a139e..2d9b96e2 100644 --- a/ext/oj/oj.h +++ b/ext/oj/oj.h @@ -263,6 +263,7 @@ extern void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts); extern char *oj_longlong_to_string(long long num, bool negative, char *buf); extern StrWriter oj_str_writer_unwrap(VALUE writer); + extern void oj_str_writer_push_key(StrWriter sw, const char *key); extern void oj_str_writer_push_object(StrWriter sw, const char *key); extern void oj_str_writer_push_array(StrWriter sw, const char *key); diff --git a/ext/oj/parser.c b/ext/oj/parser.c index f2a22fcd..2ad234a4 100644 --- a/ext/oj/parser.c +++ b/ext/oj/parser.c @@ -1334,11 +1334,12 @@ void oj_parser_set_option(ojParser p, VALUE ropts) { */ static VALUE parser_missing(int argc, VALUE *argv, VALUE self) { ojParser p; - TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); const char *key = NULL; volatile VALUE rkey = *argv; volatile VALUE rv = Qnil; + TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); + #if HAVE_RB_EXT_RACTOR_SAFE // This doesn't seem to do anything. rb_ext_ractor_safe(true); @@ -1365,9 +1366,10 @@ static VALUE parser_missing(int argc, VALUE *argv, VALUE self) { */ static VALUE parser_parse(VALUE self, VALUE json) { ojParser p; - TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); const byte *ptr = (const byte *)StringValuePtr(json); + TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); + parser_reset(p); p->start(p); parse(p, ptr); @@ -1382,9 +1384,10 @@ static VALUE load_rescue(VALUE self, VALUE x) { static VALUE load(VALUE self) { ojParser p; - TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); volatile VALUE rbuf = rb_str_new2(""); + TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); + p->start(p); while (true) { rb_funcall(p->reader, oj_readpartial_id, 2, INT2NUM(16385), rbuf); @@ -1404,6 +1407,7 @@ static VALUE load(VALUE self) { */ static VALUE parser_load(VALUE self, VALUE reader) { ojParser p; + TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); parser_reset(p); @@ -1422,10 +1426,11 @@ static VALUE parser_load(VALUE self, VALUE reader) { */ static VALUE parser_file(VALUE self, VALUE filename) { ojParser p; - TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); const char *path; int fd; + TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); + path = StringValuePtr(filename); parser_reset(p); @@ -1470,6 +1475,7 @@ static VALUE parser_file(VALUE self, VALUE filename) { */ static VALUE parser_just_one(VALUE self) { ojParser p; + TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); return p->just_one ? Qtrue : Qfalse; @@ -1485,6 +1491,7 @@ static VALUE parser_just_one(VALUE self) { */ static VALUE parser_just_one_set(VALUE self, VALUE v) { ojParser p; + TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p); p->just_one = (Qtrue == v); diff --git a/ext/oj/rails.c b/ext/oj/rails.c index 700b0892..91fed0db 100644 --- a/ext/oj/rails.c +++ b/ext/oj/rails.c @@ -847,8 +847,10 @@ static VALUE rails_deoptimize(int argc, VALUE *argv, VALUE self) { */ static VALUE encoder_optimized(VALUE self, VALUE clas) { Encoder e; + ROpt ro; + TypedData_Get_Struct(self, struct _encoder, &oj_encoder_type, e); - ROpt ro = oj_rails_get_opt(&e->ropts, clas); + ro = oj_rails_get_opt(&e->ropts, clas); if (NULL == ro) { return Qfalse; diff --git a/ext/oj/string_writer.c b/ext/oj/string_writer.c index 225a24ed..cb5ff102 100644 --- a/ext/oj/string_writer.c +++ b/ext/oj/string_writer.c @@ -469,7 +469,7 @@ static VALUE str_writer_reset(VALUE self) { static VALUE str_writer_to_s(VALUE self) { StrWriter sw; TypedData_Get_Struct(self, struct _strWriter, &oj_string_writer_type, sw); - VALUE rstr = rb_str_new(sw->out.buf, sw->out.cur - sw->out.buf); + VALUE rstr = rb_str_new(sw->out.buf, sw->out.cur - sw->out.buf); return oj_encode(rstr); }