[Vala] How to initialize a Glib.Pid?



Hello Folks,

I have a switch, that will actually always initialize a variable of type
Glib.Pid, but valac wouldn't trust me and say it might be uninitialized.

Now there are two things:

 * The variable is actually initialized in the resulting C code, by means of
   [CCode (default_value = "0")] attribute applied to Glib.Pid type in vapi.
   However, valac insists that I have to initialize it nevertheless.

 * I am not able to initialize it. I unsuccessfuly tried:
   - pid = 0;
     (gives error, that int can't be converted to Glib.Pid, because vala does
     not know it can (GPid is a typedef at C level, but Glib.Pid is empty
     struct as far as vala knows)).
   - pid = new Pid();
     (gives a warning, that new is deprecated for structs AND generates
     invalid C code. In particular, the generated code says:
         pid = memset(0, sizeof(GPid));
     (memset needs a pointer to set))
   - pid = Pid();
     (gives no warning, but generates the same invalid C code)

(Besides there is no way to check pid for invalid value, but I guess I don't
really need it, because I can only get pid from the g_spawn_* functions and
they will either give me valid pid or throw an error.)

(I moved the code using it into the cases, but it seems somewhat wrong anyway.)

Regards,
Jan
        




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]