Commit b49cfb54 authored by Giovanni Campagna's avatar Giovanni Campagna Committed by Philip Chimento

FIXME arg-cache: make actual use of the argument cache

Move handling of very special arguments (arrays, callback, caller
allocates) to the argcache virtual functions, and clean up
function invocations.
We now have three straight loops: marshal_in, marshal_out and
release. Some pointer arithmetics is introduced to ensure that
all indexes line up correctly.

FIXME: js_arg_pos can overrun js_out_argc sometimes when marshalling out

(Philip Chimento: rebased and fixed coding style.)
parent 6f47fd25
This diff is collapsed.
......@@ -33,42 +33,76 @@
G_BEGIN_DECLS
typedef struct _GjsArgumentCache {
bool (*marshal) (struct _GjsArgumentCache *, GIArgument *, JS::HandleValue);
bool (*release) (struct _GjsArgumentCache *, GIArgument *);
bool (*free) (struct _GjsArgumentCache *);
bool (*marshal_in) (JSContext *cx,
struct _GjsArgumentCache *cache,
GjsFunctionCallState *state,
GIArgument *in_argument,
JS::HandleValue value);
bool (*marshal_out) (JSContext *cx,
struct _GjsArgumentCache *cache,
GjsFunctionCallState *state,
GIArgument *out_argument,
JS::MutableHandleValue value);
bool (*release) (JSContext *cx,
struct _GjsArgumentCache *cache,
GjsFunctionCallState *state,
GIArgument *in_argument,
GIArgument *out_argument);
bool (*free) (struct _GjsArgumentCache *cache);
/* For compatibility */
GjsParamType param_type;
const char *arg_name;
int arg_pos;
GITypeInfo type_info;
bool skip_in : 1;
bool skip_out : 1;
GITransfer transfer : 2;
bool nullable : 1;
bool is_return : 1;
union {
int dummy;
} contents;
} GjsArgumentCache;
/* for explicit array only */
struct {
int length_pos;
GITypeTag length_tag;
} array;
bool gjs_arg_cache_build_in_arg(GjsArgumentCache *self,
GjsParamType *param_types,
int gi_index,
GIArgInfo *arg,
bool& inc_counter);
struct {
GIScopeType scope;
int closure_pos;
int destroy_pos;
} callback;
bool gjs_arg_cache_build_out_arg(GjsArgumentCache *self,
GjsParamType *param_types,
int gi_index,
GIArgInfo *arg,
bool& inc_counter);
/* out caller allocates (FIXME: should be in object) */
size_t caller_allocates_size;
} contents;
} GjsArgumentCache;
bool gjs_arg_cache_build_inout_arg(GjsArgumentCache *in_self,
GjsArgumentCache *out_self,
GjsParamType *param_types,
int gi_index,
GIArgInfo *arg,
bool& inc_counter);
bool gjs_arg_cache_build_arg(GjsArgumentCache *self,
GjsArgumentCache *arguments,
int gi_index,
GIDirection direction,
GIArgInfo *arg,
GICallableInfo *callable,
bool& inc_counter);
bool gjs_arg_cache_build_return(GjsArgumentCache *self,
GjsParamType *param_types,
GjsArgumentCache *arguments,
GICallableInfo *info,
bool& inc_counter);
static inline bool
gjs_arg_cache_is_skip_in(GjsArgumentCache *cache)
{
return cache->skip_in;
}
static inline bool
gjs_arg_cache_is_skip_out(GjsArgumentCache *cache)
{
return cache->skip_out;
}
G_END_DECLS
#endif /* GJS_ARG_CACHE_H */
......@@ -1248,16 +1248,16 @@ throw_invalid_argument(JSContext *context,
g_free(display_name);
}
static bool
gjs_array_to_explicit_array_internal(JSContext *context,
JS::HandleValue value,
GITypeInfo *type_info,
const char *arg_name,
GjsArgumentType arg_type,
GITransfer transfer,
bool may_be_null,
gpointer *contents,
gsize *length_p)
bool
gjs_array_to_explicit_array(JSContext *context,
JS::HandleValue value,
GITypeInfo *type_info,
const char *arg_name,
GjsArgumentType arg_type,
GITransfer transfer,
bool may_be_null,
void **contents,
size_t *length_p)
{
bool ret = false;
GITypeInfo *param_info;
......@@ -1957,15 +1957,9 @@ gjs_value_to_g_argument(JSContext *context,
}
}
if (!gjs_array_to_explicit_array_internal(context,
value,
type_info,
arg_name,
arg_type,
transfer,
may_be_null,
&data,
&length)) {
if (!gjs_array_to_explicit_array(context, value, type_info, arg_name,
arg_type, transfer, may_be_null,
&data, &length)) {
wrong = true;
break;
}
......@@ -2176,28 +2170,6 @@ gjs_value_to_arg(JSContext *context,
arg);
}
bool
gjs_value_to_explicit_array (JSContext *context,
JS::HandleValue value,
GIArgInfo *arg_info,
GIArgument *arg,
size_t *length_p)
{
GITypeInfo type_info;
g_arg_info_load_type(arg_info, &type_info);
return gjs_array_to_explicit_array_internal(context,
value,
&type_info,
g_base_info_get_name((GIBaseInfo*) arg_info),
GJS_ARGUMENT_ARGUMENT,
g_arg_info_get_ownership_transfer(arg_info),
g_arg_info_may_be_null(arg_info),
&arg->v_pointer,
length_p);
}
static bool
gjs_array_from_g_list (JSContext *context,
JS::MutableHandleValue value_p,
......
......@@ -48,10 +48,14 @@ bool gjs_value_to_arg(JSContext *context,
GIArgInfo *arg_info,
GIArgument *arg);
bool gjs_value_to_explicit_array(JSContext *context,
bool gjs_array_to_explicit_array(JSContext *cx,
JS::HandleValue value,
GIArgInfo *arg_info,
GIArgument *arg,
GITypeInfo *type_info,
const char *arg_name,
GjsArgumentType arg_type,
GITransfer transfer,
bool may_be_null,
void **contents,
size_t *length_p);
void gjs_g_argument_init_default (JSContext *context,
......
This diff is collapsed.
......@@ -64,6 +64,12 @@ GjsCallbackTrampoline* gjs_callback_trampoline_new(JSContext *context,
void gjs_callback_trampoline_unref(GjsCallbackTrampoline *trampoline);
void gjs_callback_trampoline_ref(GjsCallbackTrampoline *trampoline);
typedef struct {
GIArgument *in_cvalues;
GIArgument *out_cvalues;
GIArgument *inout_original_cvalues;
} GjsFunctionCallState;
JSObject *gjs_define_function(JSContext *context,
JS::HandleObject in_object,
GType gtype,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment