After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 552371 - implement struct field get/set
implement struct field get/set
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks: 560808
 
 
Reported: 2008-09-15 16:11 UTC by Havoc Pennington
Modified: 2015-02-07 17:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add g_field_info_set/get_field() (10.89 KB, patch)
2008-11-14 14:37 UTC, Owen Taylor
committed Details | Review

Description Havoc Pennington 2008-09-15 16:11:58 UTC
Something like:

void g_field_info_get_value(GIFieldInfo *info, GArgument *arg_out);
void g_field_info_set_value(GIFieldInfo *info, GArgument *arg);

All bindings have to implement GArgument to/from their native types anyway, so these would be pretty convenient.
Comment 1 Johan (not receiving bugmail) Dahlin 2008-10-17 18:38:14 UTC
Bitfields need to be calculated as well. ctypes get this right, their implementation can be found here:

http://svn.python.org/view/python/trunk/Modules/_ctypes/cfield.c?rev=66683&view=auto

Comment 2 Andreas Rottmann 2008-10-18 14:53:40 UTC
I have also implemented a struct/union field offset calculator in my Scheme binding for gobject-introspection which supports bitfields and struct/union members as well:

http://download.gna.org/spells/darcs/r6rs/sbank/stypes.sls

The code in question is implemented by 'calculate-sizes', which in turn calls 'calculate'. Note that sbanks is very young and hence the code is not well-test and may well be buggy.
Comment 3 Tommi Komulainen 2008-10-27 15:58:43 UTC
As the typelib is platform dependent, couldn't we use python ctypes to calculate the offsets at compile time?
Comment 4 Johan Bilien 2008-10-27 16:03:10 UTC
(In reply to comment #3)
> As the typelib is platform dependent, couldn't we use python ctypes to
> calculate the offsets at compile time?
> 

But then the typelib would contain more information than the .gir, is that ok?
Comment 5 Andreas Rottmann 2008-10-28 16:52:00 UTC
Additionally to the struct offsets, we need a "bit offset" for bitfield members, for example:

struct {
   guint tag : 5;
   guint deprecated: 1;
};

Would produce offset=0, bit-offset=0 for "tag" and offset=0 and bit-offset=5 for "deprecated". Of course this presumes that the offset data is calculated at compile-time.
Comment 6 Owen Taylor 2008-11-09 19:48:27 UTC
I'm working on some C code for now to go in the compiler to compute field
offsets. Ignoring bitfields for now. 

It uses a little bit of information from libffi - 
ffi_type_pointer.size/alignment, etc; that logic could be easily be
borrowed or duplicated if necessary.

Johan - as I understand it, the plan is that .gir is arch-independent
while the typelib is arch-dependent and thus can contain offsets.
Comment 7 Havoc Pennington 2008-11-09 19:51:30 UTC
Having the offsets in the typelib seems more efficient than requiring bindings to walk over fields adding up field sizes, anyway. May as well precompute these values.
Comment 8 Johan (not receiving bugmail) Dahlin 2008-11-09 21:27:32 UTC
Owen: Yes, girs should be platform independent for now. However I think we'll end up with one gir per library in some cases eg a separate one for each gdk backend, (but that's separate from this bug).
The typelib can be platform dependent for now as we currently don't have any good reasons for making them work between platforms.

Bitfields can go in later, we can worry about that in another bug.

Putting the offsets in the typelib should be okay. I haven't thought enough about it, eg ruling out the possibility of calculate it in runtime in some situations.
Comment 9 Owen Taylor 2008-11-14 14:37:56 UTC
Created attachment 122662 [details] [review]
Add g_field_info_set/get_field()

Here's a patch adding a straightforward set/get field.

Enums are not implemented in this: I want to add extend the typelib and add
g_enum_info_get_storage_type() to keep funky ABI knowledge in the compiler
and make it easier for people not using convenience functions.

Composite fields like GdkRectangle aren't handled here - I think they will
generally need special handling from a language binding, especially for 
write.
Comment 10 Colin Walters 2008-11-14 17:33:49 UTC
Small typo in the docs for _write_field, Returns: ...reading.

What defines G_STRUCT_MEMBER?

Comment 11 Colin Walters 2008-11-14 17:38:47 UTC
Looks good to me.
Comment 12 Owen Taylor 2008-11-16 21:24:14 UTC
Fixed up a memory leak of GFieldInfo and GTypeInfo and committed.
Comment 13 André Klapper 2015-02-07 17:03:15 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]