Commit 1f3984c9 authored by Giovanni Campagna's avatar Giovanni Campagna Committed by Philip Chimento

arg-cache: extend to handle interface types too

Handle enums, objects and boxed types through the argument cache
rather than using the generic marshaller.

(Philip Chimento: rebased and fixed coding style and bugs, and added
stubs for GParamSpec and GdkAtom.)
parent 10e234b1
This diff is collapsed.
......@@ -27,8 +27,10 @@
#include <config.h>
#include <stddef.h>
#include <stdint.h>
#include <girepository.h>
#include <glib-object.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -47,6 +49,7 @@ typedef struct _GjsArgumentCache {
bool (*release)(JSContext* cx, struct _GjsArgumentCache* cache,
GjsFunctionCallState* state, GIArgument* in_argument,
GIArgument* out_argument);
void (*free)(struct _GjsArgumentCache* cache);
const char* arg_name;
int arg_pos;
......@@ -76,6 +79,22 @@ typedef struct _GjsArgumentCache {
bool is_unsigned : 1;
} number;
// boxed / union / GObject
struct {
GType gtype;
GIBaseInfo* info;
} object;
// foreign structures
GIStructInfo* tmp_foreign_info;
// enum / flags
struct {
int64_t enum_min;
int64_t enum_max;
} enum_type;
uint64_t flags_mask;
// string / filename
bool string_is_filename : 1;
......
......@@ -147,6 +147,13 @@ GJS_USE inline decltype(auto) gjs_arg_member<int, GI_TYPE_TAG_INTERFACE>(
return gjs_arg_member(arg, &GIArgument::v_int);
}
// Unsigned enums
template <>
GJS_USE inline decltype(auto) gjs_arg_member<unsigned, GI_TYPE_TAG_INTERFACE>(
GIArgument* arg) {
return gjs_arg_member(arg, &GIArgument::v_uint);
}
template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID>
inline std::enable_if_t<!std::is_pointer_v<T>> gjs_arg_set(GIArgument* arg,
T v) {
......
......@@ -1119,15 +1119,22 @@ GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT(function)
static void
uninit_cached_function_data (Function *function)
{
g_assert(function->info && "Don't know how to free cache without GI info");
if (function->arguments) {
// Careful! function->arguments is offset by one element inside
// the allocated space, so we have to free index -1.
int gi_argc = g_callable_info_get_n_args(function->info);
for (int ix = -1; ix < gi_argc; ix++) {
if (function->arguments[ix].free)
function->arguments[ix].free(&function->arguments[ix]);
}
g_free(&function->arguments[-1]);
function->arguments = nullptr;
}
if (function->info)
g_base_info_unref( (GIBaseInfo*) function->info);
g_base_info_unref(function->info);
g_function_invoker_destroy(&function->invoker);
}
......
......@@ -147,6 +147,7 @@ using GjsAutoObjectInfo = GjsAutoInfo<GI_INFO_TYPE_OBJECT>;
using GjsAutoPropertyInfo = GjsAutoInfo<GI_INFO_TYPE_PROPERTY>;
using GjsAutoStructInfo = GjsAutoInfo<GI_INFO_TYPE_STRUCT>;
using GjsAutoTypeInfo = GjsAutoInfo<GI_INFO_TYPE_TYPE>;
using GjsAutoValueInfo = GjsAutoInfo<GI_INFO_TYPE_VALUE>;
using GjsAutoVFuncInfo = GjsAutoInfo<GI_INFO_TYPE_VFUNC>;
// GICallableInfo can be one of several tags, so we have to have a separate
......
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