Skip to content

Commit

Permalink
Remove useless DATA_PTR call and appease clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Dec 4, 2023
1 parent 86e5e79 commit 8d4c259
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ext/oj/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions ext/oj/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand Down
13 changes: 7 additions & 6 deletions ext/oj/fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ext/oj/oj.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 11 additions & 4 deletions ext/oj/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion ext/oj/rails.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/string_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 8d4c259

Please sign in to comment.