Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
gobject-introspection
gobject-introspection
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 227
    • Issues 227
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 18
    • Merge Requests 18
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • GNOME
  • gobject-introspectiongobject-introspection
  • Issues
  • #122

Closed
Open
Opened Feb 23, 2015 by bugzilla-migration@bugzilla-migrationReporter

GByteArray element type information in typelib files may not match that in GIR files

Submitted by Keri Harris

Link to original bug (#745001)

Description

I've noticed some unexpected behaviour when extracting GByteArray element type information from typelib files. When multiple functions with GByteArray arguments share similar argument names it appears that the first such function appearing in the GIR file determines the element type for all other such functions.

As an example, consider the following:

$ cat test.h

#include <glib-object.h>

void test_func1 (GByteArray* v); void test_func2 (GByteArray* v);

$ cat test.c

#include "test.h"

/**

  • test_func1:
  • @v: (element-type gint8): */ void test_func1 (GByteArray *v) { }

/**

  • test_func2:
  • @v: (element-type guint8): */ void test_func2 (GByteArray *v) { }

Notice that test_func1 and test_func2 are identical except for the element-type annotation - test_func1 specifies a gint8 element type; test_func2 specifies a guint8 element type. Both functions name their argument 'v' in the header file.

Generating a GIR + typelib file, along with a small program to query the typelib file:

$ gcc -shared $(pkg-config --cflags gobject-2.0) -o libtest-1.0.so test.c $(pkg-config --libs gobject-2.0)

$ CC=gcc CFLAGS=$(pkg-config --cflags gobject-2.0) g-ir-scanner --warn-all --quiet --namespace=Test --nsversion=1.0 --symbol-prefix=test --no-libtool --library=test-1.0 --output=Test-1.0.gir test.h test.c

$ g-ir-compiler Test-1.0.gir -o Test-1.0.typelib

$ cat query.c

#include <girepository.h> #include <stdio.h>

int main(int argc, char *argv[]) { GIBaseInfo *base_info; GIArgInfo *arg_info; GITypeInfo *type_info; GITypeTag type_tag; GError *error = NULL;

if ( argc != 2 )
{
    printf("usage %s `<function name>`\n", argv[0]);
    return -1;
}

    g_irepository_require_private(NULL, ".", "Test", NULL, 0, &error);
if ( error )
{
    printf("ERROR: %s\n", error->message);
    g_error_free(error);
    return -1;
}

base_info = g_irepository_find_by_name(NULL, "Test", argv[1]);
if ( !base_info )
{
    printf("entry %s not found\n", argv[1]);
    return -1;
}

if ( !GI_IS_FUNCTION_INFO(base_info) )
{
    printf("expected function info\n");
    return -1;
}
printf("function name: %s\n", g_base_info_get_name(base_info));

arg_info = g_callable_info_get_arg(base_info, 0);
type_info = g_arg_info_get_type(arg_info);
type_tag = g_type_info_get_tag(type_info);
printf("arg type: %s\n", g_type_tag_to_string(type_tag));

type_info = g_type_info_get_param_type(type_info, 0);
type_tag = g_type_info_get_tag(type_info);
printf("array element type: %s\n", g_type_tag_to_string(type_tag));

return 0;

}

$ gcc -o query query.c $(pkg-config --cflags gobject-introspection-1.0) $(pkg-config --libs gobject-introspection-1.0)

Querying the typelib returns the element type of func1 for both func1 and func2:

$ ./query func1 function name: func1 arg type: array array element type: gint8

$ ./query func2 function name: func2 arg type: array array element type: gint8 <== should be guint8

This behaviour seems restricted to GByteArray types; other array types return the correct element type.

It seems odd to me to specify anything other than a guint8 element type for GByteArray args, but this unexpected behaviour was picked up when extending some of the GByteArray test cases in the gimarshallingtest.c file in order to test a language binding I am writing. At the moment the GByteArray functions in the GIMarshallingTests-1.0.typelib file all use guint8 element types by virtue of the gi_marshalling_tests_bytearray_full_return() appearing first in the GIR file. Adding a gi_marshalling_tests_bytearray_full_in() test case based on gi_marshalling_tests_bytearray_none_in() is enough to cause all GByteArray functions in the marshalling test typelib all use gint8 element types.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: GNOME/gobject-introspection#122