On Wed, 2016-03-16 at 11:52 -0400, Frediano Ziglio wrote: > > > > > > Hi, > > > > On Mon, Feb 29, 2016 at 10:36:53AM +0000, Frediano Ziglio wrote: > > > > > > Allow to define functions executed at program/shared object > > > initialization > > > or close. > > > > > > Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> > > > --- > > > common/macros.h | 22 ++++++++++++++++++++++ > > > 1 file changed, 22 insertions(+) > > > > > > diff --git a/common/macros.h b/common/macros.h > > > index 47289be..fe36929 100644 > > > --- a/common/macros.h > > > +++ b/common/macros.h > > > @@ -29,5 +29,27 @@ > > > #define SPICE_ATTR_PRINTF > > > #endif /* __GNUC__ */ > > > > > > +#ifdef __GNUC__ > > > +#define SPICE_CONSTRUCTOR_FUNC(func_name) \ > > > + static void __attribute__((constructor)) func_name(void) > > > +#define SPICE_DESTRUCTOR_FUNC(func_name) \ > > > + static void __attribute__((destructor)) func_name(void) > > > +#elif defined(_MSC_VER) > > > +#define SPICE_CONSTRUCTOR_FUNC(func_name) \ > > > + static void func_name(void); \ > > > + static int func_name ## _wrapper(void) { func_name(); return > > > 0; } \ > > > + __pragma(section(".CRT$XCU",read)) \ > > > + __declspec(allocate(".CRT$XCU")) static int (* _array ## > > > func_name)(void) = func_name ## _wrapper; \ > > > + static void func_name(void) > > > +#define SPICE_DESTRUCTOR_FUNC(func_name) \ > > > + static void func_name(void); \ > > > + static int func_name ## _wrapper(void) { func_name(); return > > > 0; } \ > > > + __pragma(section(".CRT$XPU",read)) \ > > > + __declspec(allocate(".CRT$XPU")) static int (* _array ## > > > func_name)(void) = func_name ## _wrapper; \ > > > + static void func_name(void) > > > +#else > > > +#error Please implement SPICE_CONSTRUCTOR_FUNC and > > > SPICE_DESTRUCTOR_FUNC > > > for this compiler > > > +#endif > > > + > > > > > > #endif /* __MACROS_H */ > > > -- > > > 2.5.0 > > Testes, works without issues. > > > > I'm wondering why not to include the whole header from glib [0] and > > maybe file a bug to ask them to export in the future. > > > > [0] https://git.gnome.org/browse/glib/tree/glib/gconstructor.h > > > > Then, in case G_HAS_CONSTRUCTORS is not defined we can include > > different > > arch constructors. What do you think? > > > > PS: while looking for an open bug: > > aix: https://bugzilla.gnome.org/show_bug.cgi?id=763560 > > hp-ux/ia: https://bugzilla.gnome.org/show_bug.cgi?id=763466 > > > > cheers, > > toso > > > Do we want to support HP-UX or AIX? I did work on HP-UX and from what > I > can see not even HP is supporting that much this OS. > Personally I don't like Gnome implementation, particularly the atexit > call > on Windows. > I don't understand the g_slist_find call either. > > Frediano What about clang ? Does it work there? Pavel > _______________________________________________ > Spice-devel mailing list > Spice-devel@xxxxxxxxxxxxxxxxxxxxx > https://lists.freedesktop.org/mailman/listinfo/spice-devel _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel