Commit 959b4f9c authored by Giovanni Campagna's avatar Giovanni Campagna Committed by Philip Chimento

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.

(Philip Chimento: rebased and fixed coding style and bugs.)
parent 7cf93501
This diff is collapsed.
......@@ -26,33 +26,66 @@
#include <config.h>
#include <stddef.h>
#include <girepository.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include "gi/function.h"
#include "gjs/macros.h"
struct GjsFunctionCallState;
typedef struct _GjsArgumentCache {
// For compatibility
GjsParamType param_type;
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);
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 {
// for explicit array only
struct {
int length_pos;
GITypeTag length_tag;
} array;
struct {
GIScopeType scope;
int closure_pos;
int destroy_pos;
} callback;
// out caller allocates (FIXME: should be in object)
size_t caller_allocates_size;
} contents;
} GjsArgumentCache;
GJS_JSAPI_RETURN_CONVENTION
bool gjs_arg_cache_build_arg(JSContext* cx, GjsArgumentCache* self,
GjsParamType* param_types, int gi_index,
GjsArgumentCache* arguments, int gi_index,
GIDirection direction, GIArgInfo* arg,
GICallableInfo* callable, bool* inc_counter_out);
GJS_JSAPI_RETURN_CONVENTION
bool gjs_arg_cache_build_inout_arg(JSContext* cx, GjsArgumentCache* in_self,
GjsArgumentCache* out_self,
GjsParamType* param_types, int gi_index,
GIArgInfo* arg, bool* inc_counter_out);
GJS_JSAPI_RETURN_CONVENTION
bool gjs_arg_cache_build_return(JSContext* cx, GjsArgumentCache* self,
GjsParamType* param_types, GICallableInfo* info,
GjsArgumentCache* arguments,
GICallableInfo* callable,
bool* inc_counter_out);
#endif // GI_ARG_CACHE_H_
......@@ -1496,17 +1496,11 @@ throw_invalid_argument(JSContext *context,
}
GJS_JSAPI_RETURN_CONVENTION
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 found_length;
gjs_debug_marshal(
......@@ -2172,15 +2166,9 @@ _Pragma("GCC diagnostic pop")
}
}
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;
}
......@@ -2370,24 +2358,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(arg_info),
GJS_ARGUMENT_ARGUMENT, g_arg_info_get_ownership_transfer(arg_info),
g_arg_info_may_be_null(arg_info), &gjs_arg_member<void*>(arg),
length_p);
}
GJS_JSAPI_RETURN_CONVENTION
static bool
gjs_array_from_g_list (JSContext *context,
......
......@@ -57,11 +57,11 @@ bool gjs_value_to_arg(JSContext *context,
GIArgument *arg);
GJS_JSAPI_RETURN_CONVENTION
bool gjs_value_to_explicit_array(JSContext *context,
JS::HandleValue value,
GIArgInfo *arg_info,
GIArgument *arg,
size_t *length_p);
bool gjs_array_to_explicit_array(JSContext* cx, 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);
void gjs_gi_argument_init_default(GITypeInfo* type_info, GIArgument* arg);
......
This diff is collapsed.
......@@ -30,6 +30,7 @@
#include <girepository.h>
#include <glib-object.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include "gjs/macros.h"
......@@ -67,6 +68,18 @@ GjsCallbackTrampoline* gjs_callback_trampoline_new(
void gjs_callback_trampoline_unref(GjsCallbackTrampoline *trampoline);
void gjs_callback_trampoline_ref(GjsCallbackTrampoline *trampoline);
// Stack allocation only!
struct GjsFunctionCallState {
GIArgument* in_cvalues;
GIArgument* out_cvalues;
GIArgument* inout_original_cvalues;
JS::RootedObject instance_object;
bool call_completed;
explicit GjsFunctionCallState(JSContext* cx)
: instance_object(cx), call_completed(false) {}
};
GJS_JSAPI_RETURN_CONVENTION
JSObject *gjs_define_function(JSContext *context,
JS::HandleObject in_object,
......
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