Commit Graph

7 Commits

Author SHA1 Message Date
Sergey Bugaev
964affb1cc Stop using enums in bitfields
The C standard does not specify whether the underlying type of an enum
is signed or unsigned, and until C23 there was no way to control this
explicitly. GCC appears to make enums unsigned unless there is a
negative value among cases of the enum, in which case it becomes signed.
MSCV appears to make enums signed by default.

A bitfield of an enum type (which is not specificied in the C standard
either) behaves as if it was an instance of a numeric type with a
reduced value range. Specifically, a 'signed int val : 2;' bitfield will
have the possible values of -2, -1, 0, and 1, with the usual wraparound
behavior for the values that don't fit (although this too is
implementation-defined).

This causes the following issue, if we have:

typedef enum
{
  GTK_ZERO,
  GTK_ONE,
  GTK_TWO
} GtkFoo;

struct _GtkBar
{
  GtkFoo foo : 2;
};

and then assign bar.foo = GTK_TWO and read it back, it will have the
expected value of 2 (aka GTK_TWO) on GCC, but a value of -2 (not
matching any of the enum variants) on MSVC.

There does not seem to be any way to influence signedness of an enum
prior to C23, nor is there a 'unsigned GtkFoo foo : 2;' syntax. The only
remaining options seems to be never using enums in bitfields, which is
what this change implements.

In practice, this fixes GdkPipeIOStream crashing with an assertion when
trying to copy-paste in-app in MSVC builds on GTK.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-10-10 11:23:08 +03:00
Matthias Clasen
98ff6c0d4d gdk: Stop using g_slice 2023-03-14 14:56:42 -04:00
Benjamin Otte
248e33e3c9 gdk: Plug a memleak
Free GdkIOPipe struct when freeing it
Don't just free all its members.

Fixes #5110
2022-08-19 02:38:11 +02:00
Matthias Clasen
fff2b3c710 gdk: Clean up docs syntax
Replace leftover gtk-doc syntax (#Type) with backquotes.
2021-05-22 17:25:26 -04:00
Benjamin Otte
d7266b25ba Replace "gint" with "int" 2020-07-25 00:47:36 +02:00
Benjamin Otte
03a85ff2a0 gdk: Remove unnecessary assignments
The variable is never read again.
2018-05-06 02:10:20 +02:00
Benjamin Otte
12ca641ff5 clipboard: Implement local fallback clipboard transfers
This requires implementing a "pipe" so we can have 2 streams running:
  contentprovider => serializer => outputstream
  inputstream => deserializer => reader
And the pipe shoves the data from the outputstream into the inputstream.
2017-12-03 05:46:47 +01:00