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 728274 - Using sizeof() with classes is borked
Using sizeof() with classes is borked
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Semantic Analyzer
0.24.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2014-04-15 16:03 UTC by Poprádi Árpád
Modified: 2018-05-22 15:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
codegen: Avoid passing a pointer to sizeof() if is not intended (6.39 KB, patch)
2018-03-08 17:09 UTC, Rico Tzschichholz
needs-work Details | Review

Description Poprádi Árpád 2014-04-15 16:03:51 UTC
From version 0.23.2 the GDK event structures are compact classes.
To create/setup/destroy them manually this kind of code should work:

  Gdk.EventKey* eventkey = (Gdk.EventKey*) GLib.malloc (sizeof (Gdk.EventKey));
  (*eventkey).keyval = (uint)Gdk.Key.k;
  GLib.free(eventkey);

but it results
 error: Pointer indirection not supported for this expression
  (*eventkey).keyval = (uint)Gdk.Key.k;
   ^^^^^^^^^

This version:
  Gdk.EventKey* eventkey = (Gdk.EventKey*) GLib.malloc (sizeof (Gdk.EventKey));
  eventkey->keyval = (uint)Gdk.Key.k;
  GLib.free(eventkey);

compiles but results in:
 free(): invalid next size (fast): 0x0000000001240010 ***

without the line "eventkey->keyval = (uint)Gdk.Key.k" compiles and runs without error.
Comment 1 Luca Bruno 2014-04-16 10:52:56 UTC
Just found Gdk.Event has a constructor:

var ev = new Gdk.Event (Gdk.EventType.KEY_PRESS); for example.
Comment 2 Rico Tzschichholz 2018-03-08 11:59:14 UTC
class Foo {
}

sizeof(Foo) doesn't work for classes while a pointer is passed and therefore results in sizeof(Foo*)
Comment 3 Rico Tzschichholz 2018-03-08 17:09:01 UTC
Created attachment 369467 [details] [review]
codegen: Avoid passing a pointer to sizeof() if is not intended
Comment 4 Rico Tzschichholz 2018-03-09 21:43:57 UTC
Review of attachment 369467 [details] [review]:

Still breaks a bunch of stuff.
Comment 5 GNOME Infrastructure Team 2018-05-22 15:08:26 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/442.