mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-31 12:53:07 +02:00
Add support for the (skip) annotation on parameters or return values
This was discussed in bug 649657. https://bugzilla.gnome.org/show_bug.cgi?id=649657 Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
parent
eeddf77567
commit
b35c985e15
22
giarginfo.c
22
giarginfo.c
@ -164,6 +164,28 @@ g_arg_info_may_be_null (GIArgInfo *info)
|
|||||||
return blob->allow_none;
|
return blob->allow_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_arg_info_is_skip:
|
||||||
|
* @info: a #GIArgInfo
|
||||||
|
*
|
||||||
|
* Obtain if an argument is only useful in C.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if argument is only useful in C.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
g_arg_info_is_skip (GIArgInfo *info)
|
||||||
|
{
|
||||||
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
||||||
|
ArgBlob *blob;
|
||||||
|
|
||||||
|
g_return_val_if_fail (info != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (GI_IS_ARG_INFO (info), FALSE);
|
||||||
|
|
||||||
|
blob = (ArgBlob *)&rinfo->typelib->data[rinfo->offset];
|
||||||
|
|
||||||
|
return blob->skip;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_arg_info_get_ownership_transfer:
|
* g_arg_info_get_ownership_transfer:
|
||||||
* @info: a #GIArgInfo
|
* @info: a #GIArgInfo
|
||||||
|
@ -38,6 +38,7 @@ gboolean g_arg_info_is_return_value (GIArgInfo *info);
|
|||||||
gboolean g_arg_info_is_optional (GIArgInfo *info);
|
gboolean g_arg_info_is_optional (GIArgInfo *info);
|
||||||
gboolean g_arg_info_is_caller_allocates (GIArgInfo *info);
|
gboolean g_arg_info_is_caller_allocates (GIArgInfo *info);
|
||||||
gboolean g_arg_info_may_be_null (GIArgInfo *info);
|
gboolean g_arg_info_may_be_null (GIArgInfo *info);
|
||||||
|
gboolean g_arg_info_is_skip (GIArgInfo *info);
|
||||||
GITransfer g_arg_info_get_ownership_transfer (GIArgInfo *info);
|
GITransfer g_arg_info_get_ownership_transfer (GIArgInfo *info);
|
||||||
GIScopeType g_arg_info_get_scope (GIArgInfo *info);
|
GIScopeType g_arg_info_get_scope (GIArgInfo *info);
|
||||||
gint g_arg_info_get_closure (GIArgInfo *info);
|
gint g_arg_info_get_closure (GIArgInfo *info);
|
||||||
|
@ -152,6 +152,28 @@ g_callable_info_may_return_null (GICallableInfo *info)
|
|||||||
return blob->may_return_null;
|
return blob->may_return_null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_callable_info_skip_return:
|
||||||
|
* @info: a #GICallableInfo
|
||||||
|
*
|
||||||
|
* See if a callable's return value is only useful in C.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if return value is only useful in C.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
g_callable_info_skip_return (GICallableInfo *info)
|
||||||
|
{
|
||||||
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
||||||
|
SignatureBlob *blob;
|
||||||
|
|
||||||
|
g_return_val_if_fail (info != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), FALSE);
|
||||||
|
|
||||||
|
blob = (SignatureBlob *)&rinfo->typelib->data[signature_offset (info)];
|
||||||
|
|
||||||
|
return blob->skip_return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_callable_info_get_caller_owns:
|
* g_callable_info_get_caller_owns:
|
||||||
* @info: a #GICallableInfo
|
* @info: a #GICallableInfo
|
||||||
|
@ -47,6 +47,7 @@ gboolean g_callable_info_iterate_return_attributes (GICallableInfo
|
|||||||
char **value);
|
char **value);
|
||||||
GITransfer g_callable_info_get_caller_owns (GICallableInfo *info);
|
GITransfer g_callable_info_get_caller_owns (GICallableInfo *info);
|
||||||
gboolean g_callable_info_may_return_null (GICallableInfo *info);
|
gboolean g_callable_info_may_return_null (GICallableInfo *info);
|
||||||
|
gboolean g_callable_info_skip_return (GICallableInfo *info);
|
||||||
gint g_callable_info_get_n_args (GICallableInfo *info);
|
gint g_callable_info_get_n_args (GICallableInfo *info);
|
||||||
GIArgInfo * g_callable_info_get_arg (GICallableInfo *info,
|
GIArgInfo * g_callable_info_get_arg (GICallableInfo *info,
|
||||||
gint n);
|
gint n);
|
||||||
|
@ -1685,6 +1685,7 @@ _g_ir_node_build_typelib (GIrNode *node,
|
|||||||
blob2->may_return_null = function->result->allow_none;
|
blob2->may_return_null = function->result->allow_none;
|
||||||
blob2->caller_owns_return_value = function->result->transfer;
|
blob2->caller_owns_return_value = function->result->transfer;
|
||||||
blob2->caller_owns_return_container = function->result->shallow_transfer;
|
blob2->caller_owns_return_container = function->result->shallow_transfer;
|
||||||
|
blob2->skip_return = function->result->skip;
|
||||||
blob2->reserved = 0;
|
blob2->reserved = 0;
|
||||||
blob2->n_arguments = n;
|
blob2->n_arguments = n;
|
||||||
|
|
||||||
@ -1869,6 +1870,7 @@ _g_ir_node_build_typelib (GIrNode *node,
|
|||||||
blob->out = param->out;
|
blob->out = param->out;
|
||||||
blob->caller_allocates = param->caller_allocates;
|
blob->caller_allocates = param->caller_allocates;
|
||||||
blob->allow_none = param->allow_none;
|
blob->allow_none = param->allow_none;
|
||||||
|
blob->skip = param->skip;
|
||||||
blob->optional = param->optional;
|
blob->optional = param->optional;
|
||||||
blob->transfer_ownership = param->transfer;
|
blob->transfer_ownership = param->transfer;
|
||||||
blob->transfer_container_ownership = param->shallow_transfer;
|
blob->transfer_container_ownership = param->shallow_transfer;
|
||||||
|
@ -147,6 +147,7 @@ struct _GIrNodeParam
|
|||||||
gboolean optional;
|
gboolean optional;
|
||||||
gboolean retval;
|
gboolean retval;
|
||||||
gboolean allow_none;
|
gboolean allow_none;
|
||||||
|
gboolean skip;
|
||||||
gboolean transfer;
|
gboolean transfer;
|
||||||
gboolean shallow_transfer;
|
gboolean shallow_transfer;
|
||||||
GIScopeType scope;
|
GIScopeType scope;
|
||||||
|
14
girparser.c
14
girparser.c
@ -1030,6 +1030,7 @@ start_parameter (GMarkupParseContext *context,
|
|||||||
const gchar *scope;
|
const gchar *scope;
|
||||||
const gchar *closure;
|
const gchar *closure;
|
||||||
const gchar *destroy;
|
const gchar *destroy;
|
||||||
|
const gchar *skip;
|
||||||
GIrNodeParam *param;
|
GIrNodeParam *param;
|
||||||
|
|
||||||
if (!(strcmp (element_name, "parameter") == 0 &&
|
if (!(strcmp (element_name, "parameter") == 0 &&
|
||||||
@ -1046,6 +1047,7 @@ start_parameter (GMarkupParseContext *context,
|
|||||||
scope = find_attribute ("scope", attribute_names, attribute_values);
|
scope = find_attribute ("scope", attribute_names, attribute_values);
|
||||||
closure = find_attribute ("closure", attribute_names, attribute_values);
|
closure = find_attribute ("closure", attribute_names, attribute_values);
|
||||||
destroy = find_attribute ("destroy", attribute_names, attribute_values);
|
destroy = find_attribute ("destroy", attribute_names, attribute_values);
|
||||||
|
skip = find_attribute ("skip", attribute_names, attribute_values);
|
||||||
|
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
name = "unknown";
|
name = "unknown";
|
||||||
@ -1095,6 +1097,11 @@ start_parameter (GMarkupParseContext *context,
|
|||||||
else
|
else
|
||||||
param->allow_none = FALSE;
|
param->allow_none = FALSE;
|
||||||
|
|
||||||
|
if (skip && strcmp (skip, "1") == 0)
|
||||||
|
param->skip = TRUE;
|
||||||
|
else
|
||||||
|
param->skip = FALSE;
|
||||||
|
|
||||||
if (!parse_param_transfer (param, transfer, name, error))
|
if (!parse_param_transfer (param, transfer, name, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -2200,6 +2207,7 @@ start_return_value (GMarkupParseContext *context,
|
|||||||
{
|
{
|
||||||
GIrNodeParam *param;
|
GIrNodeParam *param;
|
||||||
const gchar *transfer;
|
const gchar *transfer;
|
||||||
|
const gchar *skip;
|
||||||
|
|
||||||
if (!(strcmp (element_name, "return-value") == 0 &&
|
if (!(strcmp (element_name, "return-value") == 0 &&
|
||||||
ctx->state == STATE_FUNCTION))
|
ctx->state == STATE_FUNCTION))
|
||||||
@ -2215,6 +2223,12 @@ start_return_value (GMarkupParseContext *context,
|
|||||||
|
|
||||||
state_switch (ctx, STATE_FUNCTION_RETURN);
|
state_switch (ctx, STATE_FUNCTION_RETURN);
|
||||||
|
|
||||||
|
skip = find_attribute ("skip", attribute_names, attribute_values);
|
||||||
|
if (skip && strcmp (skip, "1") == 0)
|
||||||
|
param->skip = TRUE;
|
||||||
|
else
|
||||||
|
param->skip = FALSE;
|
||||||
|
|
||||||
transfer = find_attribute ("transfer-ownership", attribute_names, attribute_values);
|
transfer = find_attribute ("transfer-ownership", attribute_names, attribute_values);
|
||||||
if (!parse_param_transfer (param, transfer, NULL, error))
|
if (!parse_param_transfer (param, transfer, NULL, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -482,6 +482,9 @@ write_callable_info (const gchar *namespace,
|
|||||||
if (g_callable_info_may_return_null (info))
|
if (g_callable_info_may_return_null (info))
|
||||||
xml_printf (file, " allow-none=\"1\"");
|
xml_printf (file, " allow-none=\"1\"");
|
||||||
|
|
||||||
|
if (g_callable_info_skip_return (info))
|
||||||
|
xml_printf (file, " skip=\"1\"");
|
||||||
|
|
||||||
write_return_value_attributes (file, info);
|
write_return_value_attributes (file, info);
|
||||||
|
|
||||||
write_type_info (namespace, type, file);
|
write_type_info (namespace, type, file);
|
||||||
@ -545,6 +548,9 @@ write_callable_info (const gchar *namespace,
|
|||||||
if (g_arg_info_get_destroy (arg) >= 0)
|
if (g_arg_info_get_destroy (arg) >= 0)
|
||||||
xml_printf (file, " destroy=\"%d\"", g_arg_info_get_destroy (arg));
|
xml_printf (file, " destroy=\"%d\"", g_arg_info_get_destroy (arg));
|
||||||
|
|
||||||
|
if (g_arg_info_is_skip (arg))
|
||||||
|
xml_printf (file, " skip=\"1\"");
|
||||||
|
|
||||||
write_attributes (file, (GIBaseInfo*) arg);
|
write_attributes (file, (GIBaseInfo*) arg);
|
||||||
|
|
||||||
type = g_arg_info_get_type (arg);
|
type = g_arg_info_get_type (arg);
|
||||||
|
@ -409,6 +409,7 @@ typedef union
|
|||||||
* @destroy: Index of the destroy notfication callback parameter associated with
|
* @destroy: Index of the destroy notfication callback parameter associated with
|
||||||
* the callback, or -1.
|
* the callback, or -1.
|
||||||
* @arg_type: Describes the type of the parameter. See details below.
|
* @arg_type: Describes the type of the parameter. See details below.
|
||||||
|
* @skip: Indicates that the parameter is only useful in C and should be skipped.
|
||||||
*
|
*
|
||||||
* Types are specified by four bytes. If the three high bytes are zero,
|
* Types are specified by four bytes. If the three high bytes are zero,
|
||||||
* the low byte describes a basic type, otherwise the 32bit number is an
|
* the low byte describes a basic type, otherwise the 32bit number is an
|
||||||
@ -426,8 +427,9 @@ typedef struct {
|
|||||||
guint transfer_container_ownership : 1;
|
guint transfer_container_ownership : 1;
|
||||||
guint return_value : 1;
|
guint return_value : 1;
|
||||||
guint scope : 3;
|
guint scope : 3;
|
||||||
|
guint skip : 1;
|
||||||
/* <private> */
|
/* <private> */
|
||||||
guint reserved :21;
|
guint reserved :20;
|
||||||
/* <public> */
|
/* <public> */
|
||||||
gint8 closure;
|
gint8 closure;
|
||||||
gint8 destroy;
|
gint8 destroy;
|
||||||
@ -445,6 +447,7 @@ typedef struct {
|
|||||||
* @caller_owns_return_container: This flag is only relevant if the return type is a container type.
|
* @caller_owns_return_container: This flag is only relevant if the return type is a container type.
|
||||||
* If the flag is set, the caller is resonsible for freeing the
|
* If the flag is set, the caller is resonsible for freeing the
|
||||||
* container, but not its contents.
|
* container, but not its contents.
|
||||||
|
* @skip_return: Indicates that the return value is only useful in C and should be skipped.
|
||||||
* @n_arguments: The number of arguments that this function expects, also the length
|
* @n_arguments: The number of arguments that this function expects, also the length
|
||||||
* of the array of ArgBlobs.
|
* of the array of ArgBlobs.
|
||||||
* @arguments: An array of ArgBlob for the arguments of the function.
|
* @arguments: An array of ArgBlob for the arguments of the function.
|
||||||
@ -455,7 +458,8 @@ typedef struct {
|
|||||||
guint16 may_return_null : 1;
|
guint16 may_return_null : 1;
|
||||||
guint16 caller_owns_return_value : 1;
|
guint16 caller_owns_return_value : 1;
|
||||||
guint16 caller_owns_return_container : 1;
|
guint16 caller_owns_return_container : 1;
|
||||||
guint16 reserved :13;
|
guint16 skip_return : 1;
|
||||||
|
guint16 reserved :12;
|
||||||
|
|
||||||
guint16 n_arguments;
|
guint16 n_arguments;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user