From 0d8a45191aa449db73d52be4ef5b202e59f8c958 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 19 Feb 2016 23:30:47 +0900 Subject: [PATCH] struct pic_data * -> pic_value --- contrib/10.callcc/callcc.c | 2 +- contrib/30.regexp/src/regexp.c | 2 +- contrib/40.srfi/src/106.c | 4 ++-- docs/capi.rst | 5 +---- extlib/benz/bool.c | 2 +- extlib/benz/cont.c | 4 ++-- extlib/benz/data.c | 12 +++++------- extlib/benz/gc.c | 2 +- extlib/benz/include/picrin.h | 5 ++--- extlib/benz/include/picrin/object.h | 4 ++-- 10 files changed, 18 insertions(+), 24 deletions(-) diff --git a/contrib/10.callcc/callcc.c b/contrib/10.callcc/callcc.c index 80905d8e..b3d9a96c 100644 --- a/contrib/10.callcc/callcc.c +++ b/contrib/10.callcc/callcc.c @@ -252,7 +252,7 @@ pic_callcc(pic_state *pic, struct pic_proc *proc) pic_value args[1]; /* save the continuation object in proc */ - c = pic_lambda(pic, cont_call, 1, pic_obj_value(pic_data_value(pic, cont, &cont_type))); + c = pic_lambda(pic, cont_call, 1, pic_data_value(pic, cont, &cont_type)); args[0] = pic_obj_value(c); return pic_applyk(pic, proc, 1, args); diff --git a/contrib/30.regexp/src/regexp.c b/contrib/30.regexp/src/regexp.c index dd611975..130f6ff2 100644 --- a/contrib/30.regexp/src/regexp.c +++ b/contrib/30.regexp/src/regexp.c @@ -62,7 +62,7 @@ pic_regexp_regexp(pic_state *pic) pic_errorf(pic, "regexp compilation error: %s", errbuf); } - return pic_obj_value(pic_data_value(pic, reg, ®exp_type)); + return pic_data_value(pic, reg, ®exp_type); } static pic_value diff --git a/contrib/40.srfi/src/106.c b/contrib/40.srfi/src/106.c index a52d161d..b82c0f6f 100644 --- a/contrib/40.srfi/src/106.c +++ b/contrib/40.srfi/src/106.c @@ -141,7 +141,7 @@ pic_socket_make_socket(pic_state *pic) pic_errorf(pic, "%s", strerror(errno)); } - return pic_obj_value(pic_data_value(pic, sock, &socket_type)); + return pic_data_value(pic, sock, &socket_type); } static pic_value @@ -179,7 +179,7 @@ pic_socket_socket_accept(pic_state *pic) new_sock = pic_malloc(pic, sizeof(struct pic_socket_t)); new_sock->fd = fd; - return pic_obj_value(pic_data_value(pic, new_sock, &socket_type)); + return pic_data_value(pic, new_sock, &socket_type); } static pic_value diff --git a/docs/capi.rst b/docs/capi.rst index 6e701fb9..03b5cc50 100644 --- a/docs/capi.rst +++ b/docs/capi.rst @@ -83,15 +83,12 @@ When you use dynamic memory allocation inside C APIs, you must be caseful about pic_create_foo(pic_state *pic) { struct foo *f; - struct pic_data *dat; pic_get_args(pic, ""); // no args here f = create_foo(); - data = pic_data_value(pic, md, &foo_type); - - return pic_obj_value(data); + return pic_data_value(pic, md, &foo_type); } void diff --git a/extlib/benz/bool.c b/extlib/benz/bool.c index 3e474e55..826c4626 100644 --- a/extlib/benz/bool.c +++ b/extlib/benz/bool.c @@ -172,7 +172,7 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, int depth, khash_t(m) return true; } case PIC_TYPE_DATA: { - return pic_data_ptr(x)->data == pic_data_ptr(y)->data; + return pic_data(pic, x) == pic_data(pic, y); } default: return false; diff --git a/extlib/benz/cont.c b/extlib/benz/cont.c index f47347b6..4007b558 100644 --- a/extlib/benz/cont.c +++ b/extlib/benz/cont.c @@ -109,7 +109,7 @@ cont_call(pic_state *pic) pic_errorf(pic, "calling dead escape continuation"); } - cont = pic_data_ptr(pic_closure_ref(pic, CV_ESCAPE))->data; + cont = pic_data(pic, pic_closure_ref(pic, CV_ESCAPE)); cont->retc = argc; cont->retv = argv; @@ -127,7 +127,7 @@ pic_make_cont(pic_state *pic, struct pic_cont *cont) struct pic_proc *c; /* save the escape continuation in proc */ - c = pic_lambda(pic, cont_call, 2, pic_int_value(pic, cont->id), pic_obj_value(pic_data_value(pic, cont, &cont_type))); + c = pic_lambda(pic, cont_call, 2, pic_int_value(pic, cont->id), pic_data_value(pic, cont, &cont_type)); return c; } diff --git a/extlib/benz/data.c b/extlib/benz/data.c index da8b7d6d..ce7c6530 100644 --- a/extlib/benz/data.c +++ b/extlib/benz/data.c @@ -4,18 +4,16 @@ bool pic_data_type_p(pic_state *pic, pic_value obj, const pic_data_type *type) { - return pic_data_p(pic, obj) && pic_data_ptr(obj)->type == type; + return pic_data_p(pic, obj) && pic_data_ptr(pic, obj)->type == type; } void * -pic_data(pic_state *pic, pic_value data) +pic_data(pic_state PIC_UNUSED(*pic), pic_value data) { - pic_assert_type(pic, data, data); - - return pic_data_ptr(data)->data; + return pic_data_ptr(pic, data)->data; } -struct pic_data * +pic_value pic_data_value(pic_state *pic, void *userdata, const pic_data_type *type) { struct pic_data *data; @@ -24,5 +22,5 @@ pic_data_value(pic_state *pic, void *userdata, const pic_data_type *type) data->type = type; data->data = userdata; - return data; + return pic_obj_value(data); } diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index 2a7a29a2..8baa2239 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -704,7 +704,7 @@ pic_alloca(pic_state *pic, size_t n) static const pic_data_type t = { "pic_alloca", pic_free, 0 }; /* TODO: optimize */ - return pic_data_value(pic, pic_malloc(pic, n), &t)->data; + return pic_data(pic, pic_data_value(pic, pic_malloc(pic, n), &t)); } struct pic_object * diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 9e796dc3..45130110 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -58,7 +58,6 @@ struct pic_proc; struct pic_port; struct pic_error; struct pic_env; -struct pic_data; typedef struct pic_symbol pic_sym; typedef struct pic_id pic_id; @@ -125,7 +124,7 @@ PIC_INLINE char pic_char(pic_state *, pic_value c); #define pic_bool(pic,b) (! pic_false_p(pic, b)) const char *pic_str(pic_state *, struct pic_string *); unsigned char *pic_blob(pic_state *, pic_value blob, int *len); -void *pic_data(pic_state *, pic_value str); +void *pic_data(pic_state *, pic_value data); typedef struct { const char *type_name; @@ -147,7 +146,7 @@ struct pic_string *pic_str_value(pic_state *, const char *str, int len); struct pic_string *pic_strf_value(pic_state *, const char *fmt, ...); struct pic_string *pic_vstrf_value(pic_state *, const char *fmt, va_list ap); pic_value pic_blob_value(pic_state *, const unsigned char *buf, int len); -struct pic_data *pic_data_value(pic_state *, void *ptr, const pic_data_type *type); +pic_value pic_data_value(pic_state *, void *ptr, const pic_data_type *type); enum { PIC_TYPE_INVALID = 1, diff --git a/extlib/benz/include/picrin/object.h b/extlib/benz/include/picrin/object.h index ff3cb20d..1c1ad585 100644 --- a/extlib/benz/include/picrin/object.h +++ b/extlib/benz/include/picrin/object.h @@ -123,12 +123,12 @@ struct pic_port { #define pic_pair_ptr(pic, o) ((struct pic_pair *)pic_obj_ptr(o)) #define pic_blob_ptr(pic, v) ((struct pic_blob *)pic_obj_ptr(v)) #define pic_vec_ptr(pic, o) ((struct pic_vector *)pic_obj_ptr(o)) -#define pic_dict_ptr(pic, v) ((struct pic_dict *)pic_obj_ptr(v)) +#define pic_dict_ptr(pic, o) ((struct pic_dict *)pic_obj_ptr(o)) +#define pic_data_ptr(pic, o) ((struct pic_data *)pic_obj_ptr(o)) #define pic_sym_ptr(v) ((pic_sym *)pic_obj_ptr(v)) #define pic_id_ptr(v) ((pic_id *)pic_obj_ptr(v)) #define pic_str_ptr(o) ((struct pic_string *)pic_obj_ptr(o)) #define pic_weak_ptr(v) ((struct pic_weak *)pic_obj_ptr(v)) -#define pic_data_ptr(o) ((struct pic_data *)pic_obj_ptr(o)) #define pic_context_ptr(o) ((struct pic_context *)pic_obj_ptr(o)) #define pic_proc_ptr(o) ((struct pic_proc *)pic_obj_ptr(o)) #define pic_rec_ptr(v) ((struct pic_record *)pic_obj_ptr(v))