Blame gio/tests/plugin_resources.c

Packit ae235b
#include <gio/gio.h>
Packit ae235b
Packit ae235b
#if defined (__ELF__) && ( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6))
Packit ae235b
# define SECTION __attribute__ ((section (".gresource.g_plugin"), aligned (8)))
Packit ae235b
#else
Packit ae235b
# define SECTION
Packit ae235b
#endif
Packit ae235b
Packit ae235b
static const SECTION union { const guint8 data[180]; const double alignment; void * const ptr;}  _g_plugin_resource_data = { {
Packit ae235b
  0x47, 0x56, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x74, 
Packit ae235b
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
Packit ae235b
  0x18, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 
Packit ae235b
  0x00, 0x00, 0x00, 0x28, 0x03, 0x00, 0x00, 0x00, 
Packit ae235b
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
Packit ae235b
  0x02, 0x00, 0x00, 0x00, 0xba, 0x2c, 0xfd, 0xa6, 
Packit ae235b
  0x02, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 
Packit ae235b
  0x0f, 0x00, 0x4c, 0x00, 0x84, 0x00, 0x00, 0x00, 
Packit ae235b
  0x88, 0x00, 0x00, 0x00, 0x59, 0xea, 0x29, 0x39, 
Packit ae235b
  0x00, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 
Packit ae235b
  0x09, 0x00, 0x76, 0x00, 0x98, 0x00, 0x00, 0x00, 
Packit ae235b
  0xae, 0x00, 0x00, 0x00, 0xd4, 0xb5, 0x02, 0x00, 
Packit ae235b
  0xff, 0xff, 0xff, 0xff, 0xae, 0x00, 0x00, 0x00, 
Packit ae235b
  0x01, 0x00, 0x4c, 0x00, 0xb0, 0x00, 0x00, 0x00, 
Packit ae235b
  0xb4, 0x00, 0x00, 0x00, 0x72, 0x65, 0x73, 0x6f, 
Packit ae235b
  0x75, 0x72, 0x63, 0x65, 0x70, 0x6c, 0x75, 0x67, 
Packit ae235b
  0x69, 0x6e, 0x2f, 0x00, 0x01, 0x00, 0x00, 0x00, 
Packit ae235b
  0x74, 0x65, 0x73, 0x74, 0x31, 0x2e, 0x74, 0x78, 
Packit ae235b
  0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
Packit ae235b
  0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
Packit ae235b
  0x74, 0x65, 0x73, 0x74, 0x31, 0x0a, 0x00, 0x00, 
Packit ae235b
  0x28, 0x75, 0x75, 0x61, 0x79, 0x29, 0x2f, 0x00, 
Packit ae235b
  0x00, 0x00, 0x00, 0x00
Packit ae235b
} };
Packit ae235b
Packit ae235b
static GStaticResource static_resource = { _g_plugin_resource_data.data, sizeof (_g_plugin_resource_data.data), NULL, NULL, NULL };
Packit ae235b
extern GResource *_g_plugin_get_resource (void);
Packit ae235b
GResource *_g_plugin_get_resource (void)
Packit ae235b
{
Packit ae235b
  return g_static_resource_get_resource (&static_resource);
Packit ae235b
}
Packit ae235b
/*
Packit ae235b
  If G_HAS_CONSTRUCTORS is true then the compiler support *both* constructors and
Packit ae235b
  destructors, in a sane way, including e.g. on library unload. If not you're on
Packit ae235b
  your own.
Packit ae235b
Packit ae235b
  Some compilers need #pragma to handle this, which does not work with macros,
Packit ae235b
  so the way you need to use this is (for constructors):
Packit ae235b
Packit ae235b
  #ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
Packit ae235b
  #pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(my_constructor)
Packit ae235b
  #endif
Packit ae235b
  G_DEFINE_CONSTRUCTOR(my_constructor)
Packit ae235b
  static void my_constructor(void) {
Packit ae235b
   ...
Packit ae235b
  }
Packit ae235b
Packit ae235b
*/
Packit ae235b
Packit ae235b
#ifndef __GTK_DOC_IGNORE__
Packit ae235b
Packit ae235b
#if  __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
Packit ae235b
Packit ae235b
#define G_HAS_CONSTRUCTORS 1
Packit ae235b
Packit ae235b
#define G_DEFINE_CONSTRUCTOR(_func) static void __attribute__((constructor)) _func (void);
Packit ae235b
#define G_DEFINE_DESTRUCTOR(_func) static void __attribute__((destructor)) _func (void);
Packit ae235b
Packit ae235b
#elif defined (_MSC_VER) && (_MSC_VER >= 1500)
Packit ae235b
/* Visual studio 2008 and later has _Pragma */
Packit ae235b
Packit ae235b
#define G_HAS_CONSTRUCTORS 1
Packit ae235b
Packit ae235b
/* We do some weird things to avoid the constructors being optimized
Packit ae235b
 * away on VS2015 if WholeProgramOptimization is enabled. First we
Packit ae235b
 * make a reference to the array from the wrapper to make sure its
Packit ae235b
 * references. Then we use a pragma to make sure the wrapper function
Packit ae235b
 * symbol is always included at the link stage. Also, the symbols
Packit ae235b
 * need to be extern (but not dllexport), even though they are not
Packit ae235b
 * really used from another object file.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/* We need to account for differences between the mangling of symbols
Packit ae235b
 * for Win32 (x86) and x64 programs, as symbols on Win32 are prefixed
Packit ae235b
 * with an underscore but symbols on x64 are not.
Packit ae235b
 */
Packit ae235b
#ifdef _WIN64
Packit ae235b
#define G_MSVC_SYMBOL_PREFIX ""
Packit ae235b
#else
Packit ae235b
#define G_MSVC_SYMBOL_PREFIX "_"
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#define G_DEFINE_CONSTRUCTOR(_func) G_MSVC_CTOR (_func, G_MSVC_SYMBOL_PREFIX)
Packit ae235b
#define G_DEFINE_DESTRUCTOR(_func) G_MSVC_DTOR (_func, G_MSVC_SYMBOL_PREFIX)
Packit ae235b
Packit ae235b
#define G_MSVC_CTOR(_func,_sym_prefix) \
Packit ae235b
  static void _func(void); \
Packit ae235b
  extern int (* _array ## _func)(void);              \
Packit ae235b
  int _func ## _wrapper(void) { _func(); g_slist_find (NULL,  _array ## _func); return 0; } \
Packit ae235b
  __pragma(comment(linker,"/include:" _sym_prefix # _func "_wrapper")) \
Packit ae235b
  __pragma(section(".CRT$XCU",read)) \
Packit ae235b
  __declspec(allocate(".CRT$XCU")) int (* _array ## _func)(void) = _func ## _wrapper;
Packit ae235b
Packit ae235b
#define G_MSVC_DTOR(_func,_sym_prefix) \
Packit ae235b
  static void _func(void); \
Packit ae235b
  extern int (* _array ## _func)(void);              \
Packit ae235b
  int _func ## _constructor(void) { atexit (_func); g_slist_find (NULL,  _array ## _func); return 0; } \
Packit ae235b
   __pragma(comment(linker,"/include:" _sym_prefix # _func "_constructor")) \
Packit ae235b
  __pragma(section(".CRT$XCU",read)) \
Packit ae235b
  __declspec(allocate(".CRT$XCU")) int (* _array ## _func)(void) = _func ## _constructor;
Packit ae235b
Packit ae235b
#elif defined (_MSC_VER)
Packit ae235b
Packit ae235b
#define G_HAS_CONSTRUCTORS 1
Packit ae235b
Packit ae235b
/* Pre Visual studio 2008 must use #pragma section */
Packit ae235b
#define G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA 1
Packit ae235b
#define G_DEFINE_DESTRUCTOR_NEEDS_PRAGMA 1
Packit ae235b
Packit ae235b
#define G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(_func) \
Packit ae235b
  section(".CRT$XCU",read)
Packit ae235b
#define G_DEFINE_CONSTRUCTOR(_func) \
Packit ae235b
  static void _func(void); \
Packit ae235b
  static int _func ## _wrapper(void) { _func(); return 0; } \
Packit ae235b
  __declspec(allocate(".CRT$XCU")) static int (*p)(void) = _func ## _wrapper;
Packit ae235b
Packit ae235b
#define G_DEFINE_DESTRUCTOR_PRAGMA_ARGS(_func) \
Packit ae235b
  section(".CRT$XCU",read)
Packit ae235b
#define G_DEFINE_DESTRUCTOR(_func) \
Packit ae235b
  static void _func(void); \
Packit ae235b
  static int _func ## _constructor(void) { atexit (_func); return 0; } \
Packit ae235b
  __declspec(allocate(".CRT$XCU")) static int (* _array ## _func)(void) = _func ## _constructor;
Packit ae235b
Packit ae235b
#elif defined(__SUNPRO_C)
Packit ae235b
Packit ae235b
/* This is not tested, but i believe it should work, based on:
Packit ae235b
 * http://opensource.apple.com/source/OpenSSL098/OpenSSL098-35/src/fips/fips_premain.c
Packit ae235b
 */
Packit ae235b
Packit ae235b
#define G_HAS_CONSTRUCTORS 1
Packit ae235b
Packit ae235b
#define G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA 1
Packit ae235b
#define G_DEFINE_DESTRUCTOR_NEEDS_PRAGMA 1
Packit ae235b
Packit ae235b
#define G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(_func) \
Packit ae235b
  init(_func)
Packit ae235b
#define G_DEFINE_CONSTRUCTOR(_func) \
Packit ae235b
  static void _func(void);
Packit ae235b
Packit ae235b
#define G_DEFINE_DESTRUCTOR_PRAGMA_ARGS(_func) \
Packit ae235b
  fini(_func)
Packit ae235b
#define G_DEFINE_DESTRUCTOR(_func) \
Packit ae235b
  static void _func(void);
Packit ae235b
Packit ae235b
#else
Packit ae235b
Packit ae235b
/* constructors not supported for this compiler */
Packit ae235b
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#endif /* __GTK_DOC_IGNORE__ */
Packit ae235b
Packit ae235b
#ifdef G_HAS_CONSTRUCTORS
Packit ae235b
Packit ae235b
#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
Packit ae235b
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(resource_constructor)
Packit ae235b
#endif
Packit ae235b
G_DEFINE_CONSTRUCTOR(resource_constructor)
Packit ae235b
#ifdef G_DEFINE_DESTRUCTOR_NEEDS_PRAGMA
Packit ae235b
#pragma G_DEFINE_DESTRUCTOR_PRAGMA_ARGS(resource_destructor)
Packit ae235b
#endif
Packit ae235b
G_DEFINE_DESTRUCTOR(resource_destructor)
Packit ae235b
Packit ae235b
#else
Packit ae235b
#warning "Constructor not supported on this compiler, linking in resources will not work"
Packit ae235b
#endif
Packit ae235b
Packit ae235b
static void resource_constructor (void)
Packit ae235b
{
Packit ae235b
  g_static_resource_init (&static_resource);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void resource_destructor (void)
Packit ae235b
{
Packit ae235b
  g_static_resource_fini (&static_resource);
Packit ae235b
}