mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-31 21:34:12 +02:00
girepository: Add APIs for sync, async, and finish function annotations
This commit is contained in:
committed by
Philip Withnall
parent
93271385f9
commit
453dd4be9e
@@ -391,6 +391,17 @@ locate_gir (GIIrParser *parser,
|
||||
line_number, char_number, attribute, element); \
|
||||
} while (0)
|
||||
|
||||
#define INVALID_ATTRIBUTE(context,error,element,attribute,reason) \
|
||||
do { \
|
||||
int line_number, char_number; \
|
||||
g_markup_parse_context_get_position (context, &line_number, &char_number); \
|
||||
g_set_error (error, \
|
||||
G_MARKUP_ERROR, \
|
||||
G_MARKUP_ERROR_INVALID_CONTENT, \
|
||||
"Line %d, character %d: The attribute '%s' on the element '%s' is not valid: %s", \
|
||||
line_number, char_number, attribute, element, reason); \
|
||||
} while (0)
|
||||
|
||||
static const char *
|
||||
find_attribute (const char *name,
|
||||
const char **attribute_names,
|
||||
@@ -901,6 +912,9 @@ start_function (GMarkupParseContext *context,
|
||||
const char *throws;
|
||||
const char *set_property;
|
||||
const char *get_property;
|
||||
const char *finish_func;
|
||||
const char *async_func;
|
||||
const char *sync_func;
|
||||
GIIrNodeFunction *function;
|
||||
gboolean found = FALSE;
|
||||
ParseState in_embedded_state = STATE_NONE;
|
||||
@@ -951,6 +965,9 @@ start_function (GMarkupParseContext *context,
|
||||
throws = find_attribute ("throws", attribute_names, attribute_values);
|
||||
set_property = find_attribute ("glib:set-property", attribute_names, attribute_values);
|
||||
get_property = find_attribute ("glib:get-property", 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);
|
||||
async_func = find_attribute ("glib:async-func", attribute_names, attribute_values);
|
||||
|
||||
if (name == NULL)
|
||||
{
|
||||
@@ -977,6 +994,55 @@ start_function (GMarkupParseContext *context,
|
||||
else
|
||||
function->deprecated = FALSE;
|
||||
|
||||
function->is_async = FALSE;
|
||||
function->async_func = NULL;
|
||||
function->sync_func = NULL;
|
||||
function->finish_func = NULL;
|
||||
|
||||
// Only asynchronous functions have a glib:sync-func defined
|
||||
if (sync_func != NULL)
|
||||
{
|
||||
if (G_UNLIKELY (async_func != NULL))
|
||||
{
|
||||
INVALID_ATTRIBUTE (context, error, element_name, "glib:sync-func", "glib:sync-func should only be defined with asynchronous "
|
||||
"functions");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function->is_async = TRUE;
|
||||
function->sync_func = g_strdup (sync_func);
|
||||
}
|
||||
|
||||
// Only synchronous functions have a glib:async-func defined
|
||||
if (async_func != NULL)
|
||||
{
|
||||
if (G_UNLIKELY (sync_func != NULL))
|
||||
{
|
||||
INVALID_ATTRIBUTE (context, error, element_name, "glib:async-func", "glib:async-func should only be defined with synchronous "
|
||||
"functions");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function->is_async = FALSE;
|
||||
function->async_func = g_strdup (async_func);
|
||||
}
|
||||
|
||||
if (finish_func != NULL)
|
||||
{
|
||||
if (G_UNLIKELY (async_func != NULL))
|
||||
{
|
||||
INVALID_ATTRIBUTE (context, error, element_name, "glib:finish-func", "glib:finish-func should only be defined with asynchronous "
|
||||
"functions");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function->is_async = TRUE;
|
||||
function->finish_func = g_strdup (finish_func);
|
||||
}
|
||||
|
||||
if (strcmp (element_name, "method") == 0 ||
|
||||
strcmp (element_name, "constructor") == 0)
|
||||
{
|
||||
@@ -2594,6 +2660,9 @@ start_vfunc (GMarkupParseContext *context,
|
||||
const char *offset;
|
||||
const char *invoker;
|
||||
const char *throws;
|
||||
const char *finish_func;
|
||||
const char *async_func;
|
||||
const char *sync_func;
|
||||
GIIrNodeInterface *iface;
|
||||
GIIrNodeVFunc *vfunc;
|
||||
guint64 parsed_offset;
|
||||
@@ -2613,6 +2682,9 @@ start_vfunc (GMarkupParseContext *context,
|
||||
offset = find_attribute ("offset", attribute_names, attribute_values);
|
||||
invoker = find_attribute ("invoker", attribute_names, attribute_values);
|
||||
throws = find_attribute ("throws", 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);
|
||||
async_func = find_attribute ("glib:async-func", attribute_names, attribute_values);
|
||||
|
||||
if (name == NULL)
|
||||
{
|
||||
@@ -2666,6 +2738,56 @@ start_vfunc (GMarkupParseContext *context,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
vfunc->is_async = FALSE;
|
||||
vfunc->async_func = NULL;
|
||||
vfunc->sync_func = NULL;
|
||||
vfunc->finish_func = NULL;
|
||||
|
||||
// Only asynchronous functions have a glib:sync-func defined
|
||||
if (sync_func != NULL)
|
||||
{
|
||||
if (G_UNLIKELY (async_func != NULL))
|
||||
{
|
||||
INVALID_ATTRIBUTE (context, error, element_name, "glib:sync-func", "glib:sync-func should only be defined with asynchronous "
|
||||
"functions");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
vfunc->is_async = TRUE;
|
||||
vfunc->sync_func = g_strdup (sync_func);
|
||||
}
|
||||
|
||||
// Only synchronous functions have a glib:async-func defined
|
||||
if (async_func != NULL)
|
||||
{
|
||||
if (G_UNLIKELY (sync_func != NULL))
|
||||
{
|
||||
INVALID_ATTRIBUTE (context, error, element_name, "glib:async-func", "glib:async-func should only be defined with synchronous "
|
||||
"functions");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
vfunc->is_async = FALSE;
|
||||
vfunc->async_func = g_strdup (async_func);
|
||||
}
|
||||
|
||||
if (finish_func != NULL)
|
||||
{
|
||||
if (G_UNLIKELY (async_func != NULL))
|
||||
{
|
||||
INVALID_ATTRIBUTE (context, error, element_name, "glib:finish-func", "glib:finish-func should only be defined with asynchronous "
|
||||
"functions");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
vfunc->is_async = TRUE;
|
||||
vfunc->finish_func = g_strdup (finish_func);
|
||||
}
|
||||
|
||||
|
||||
vfunc->invoker = g_strdup (invoker);
|
||||
|
||||
iface = (GIIrNodeInterface *)CURRENT_NODE (ctx);
|
||||
|
Reference in New Issue
Block a user