girepository: Read static vfunc attribute exposing via callable is_method()

Read the static attribute for virtual functions, and make sure that
g_callable_info_is_method() returns false for such cases.
This commit is contained in:
Marco Trevisan (Treviño) 2022-10-05 17:55:54 -07:00 committed by Philip Chimento
parent fe142e3b32
commit 7ea9840cf4
5 changed files with 24 additions and 5 deletions

View File

@ -135,10 +135,12 @@ gi_callable_info_can_throw_gerror (GICallableInfo *info)
* *
* Determines if the callable info is a method. * Determines if the callable info is a method.
* *
* For [class@GIRepository.VFuncInfo]s and [class@GIRepository.SignalInfo]s, * For [class@GIRepository.SignalInfo]s, this is always true, and for
* this is always true, and for [class@GIRepository.CallbackInfo]s always false. * [class@GIRepository.CallbackInfo]s always false.
* Otherwise, this looks at the `GI_FUNCTION_IS_METHOD` flag on the * For [class@GIRepository.FunctionInfo]s this looks at the
* [class@GIRepository.FunctionInfo]. * `GI_FUNCTION_IS_METHOD` flag on the [class@GIRepository.FunctionInfo].
* For [class@GIRepository.VFuncInfo]s this is true when the virtual function
* has an instance parameter.
* *
* Concretely, this function returns whether * Concretely, this function returns whether
* [method@GIRepository.CallableInfo.get_n_args] matches the number of arguments * [method@GIRepository.CallableInfo.get_n_args] matches the number of arguments
@ -160,6 +162,11 @@ gi_callable_info_is_method (GICallableInfo *info)
return (!blob->constructor && !blob->is_static); return (!blob->constructor && !blob->is_static);
} }
case GI_INFO_TYPE_VFUNC: case GI_INFO_TYPE_VFUNC:
{
VFuncBlob *blob;
blob = (VFuncBlob *) &rinfo->typelib->data[rinfo->offset];
return !blob->is_static;
}
case GI_INFO_TYPE_SIGNAL: case GI_INFO_TYPE_SIGNAL:
return TRUE; return TRUE;
case GI_INFO_TYPE_CALLBACK: case GI_INFO_TYPE_CALLBACK:

View File

@ -243,6 +243,8 @@ struct _GIIrNodeVFunc
uint8_t instance_transfer_full : 1; uint8_t instance_transfer_full : 1;
uint8_t is_async : 1; uint8_t is_async : 1;
uint8_t is_static : 1;
char *invoker; /* (owned) */ char *invoker; /* (owned) */
char *finish_func; /* (owned) */ char *finish_func; /* (owned) */
char *sync_func; /* (owned) */ char *sync_func; /* (owned) */

View File

@ -2029,6 +2029,7 @@ gi_ir_node_build_typelib (GIIrNode *node,
blob->struct_offset = vfunc->offset; blob->struct_offset = vfunc->offset;
blob->reserved2 = 0; blob->reserved2 = 0;
blob->signature = signature; blob->signature = signature;
blob->is_static = vfunc->is_static;
gi_ir_node_build_typelib ((GIIrNode *)vfunc->result->type, gi_ir_node_build_typelib ((GIIrNode *)vfunc->result->type,
node, build, &signature, offset2, NULL); node, build, &signature, offset2, NULL);

View File

@ -2660,6 +2660,7 @@ start_vfunc (GMarkupParseContext *context,
const char *offset; const char *offset;
const char *invoker; const char *invoker;
const char *throws; const char *throws;
const char *is_static;
const char *finish_func; const char *finish_func;
const char *async_func; const char *async_func;
const char *sync_func; const char *sync_func;
@ -2682,6 +2683,7 @@ start_vfunc (GMarkupParseContext *context,
offset = find_attribute ("offset", attribute_names, attribute_values); offset = find_attribute ("offset", attribute_names, attribute_values);
invoker = find_attribute ("invoker", attribute_names, attribute_values); invoker = find_attribute ("invoker", attribute_names, attribute_values);
throws = find_attribute ("throws", attribute_names, attribute_values); throws = find_attribute ("throws", attribute_names, attribute_values);
is_static = find_attribute ("glib:static", attribute_names, attribute_values);
finish_func = find_attribute ("glib:finish-func", attribute_names, attribute_values); finish_func = find_attribute ("glib:finish-func", attribute_names, attribute_values);
sync_func = find_attribute ("glib:sync-func", attribute_names, attribute_values); sync_func = find_attribute ("glib:sync-func", attribute_names, attribute_values);
async_func = find_attribute ("glib:async-func", attribute_names, attribute_values); async_func = find_attribute ("glib:async-func", attribute_names, attribute_values);
@ -2728,6 +2730,11 @@ start_vfunc (GMarkupParseContext *context,
else else
vfunc->throws = FALSE; vfunc->throws = FALSE;
if (is_static && strcmp (is_static, "1") == 0)
vfunc->is_static = TRUE;
else
vfunc->is_static = FALSE;
if (offset == NULL) if (offset == NULL)
vfunc->offset = 0xFFFF; vfunc->offset = 0xFFFF;
else if (g_ascii_string_to_unsigned (offset, 10, 0, G_MAXSIZE, &parsed_offset, error)) else if (g_ascii_string_to_unsigned (offset, 10, 0, G_MAXSIZE, &parsed_offset, error))

View File

@ -1117,6 +1117,7 @@ typedef struct {
* @invoker: If a method invoker for this virtual exists, this is the offset * @invoker: If a method invoker for this virtual exists, this is the offset
* in the class structure of the method. If no method is known, this value * in the class structure of the method. If no method is known, this value
* will be 0x3ff. * will be 0x3ff.
* @is_static: True if the vfunc has no instance parameter.
* @reserved: Reserved for future use. * @reserved: Reserved for future use.
* @finish: The index of the finish function if is_async is TRUE, otherwise ASYNC_SENTINEL * @finish: The index of the finish function if is_async is TRUE, otherwise ASYNC_SENTINEL
* @reserved2: Reserved for future use. * @reserved2: Reserved for future use.
@ -1142,7 +1143,8 @@ typedef struct {
uint16_t struct_offset; uint16_t struct_offset;
uint16_t invoker : 10; /* Number of bits matches @index in FunctionBlob */ uint16_t invoker : 10; /* Number of bits matches @index in FunctionBlob */
uint16_t reserved : 6; uint16_t is_static : 1;
uint16_t reserved : 5;
uint16_t finish : 10; uint16_t finish : 10;
uint16_t reserved2 : 6; uint16_t reserved2 : 6;