From 392135c7db4d9cb4a14ff5935d7c4c6e21363847 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sat, 22 Oct 2016 04:39:47 +0200 Subject: Remove libxml2 dependency in favor of custom XML parsing --- src/plist.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 15 deletions(-) (limited to 'src/plist.c') diff --git a/src/plist.c b/src/plist.c index af64ed1..a3d88b9 100644 --- a/src/plist.c +++ b/src/plist.c @@ -2,8 +2,8 @@ * plist.c * Builds plist XML structures * + * Copyright (c) 2009-2016 Nikias Bassen All Rights Reserved. * Copyright (c) 2010-2015 Martin Szulecki All Rights Reserved. - * Copyright (c) 2009-2014 Nikias Bassen All Rights Reserved. * Copyright (c) 2008 Zach C. All Rights Reserved. * * This library is free software; you can redistribute it and/or @@ -29,27 +29,83 @@ #include #include +#ifdef WIN32 +#include +#else +#include +#endif + #include #include -#include -#include -#include -#include -#include -#include +extern void plist_xml_init(void); +extern void plist_xml_deinit(void); + +static void internal_plist_init(void) +{ + plist_xml_init(); +} + +static void internal_plist_deinit(void) +{ + plist_xml_deinit(); +} + +#ifdef WIN32 + +typedef volatile struct { + LONG lock; + int state; +} thread_once_t; + +static thread_once_t init_once = {0, 0}; +static thread_once_t deinit_once = {0, 0}; + +void thread_once(thread_once_t *once_control, void (*init_routine)(void)) +{ + while (InterlockedExchange(&(once_control->lock), 1) != 0) { + Sleep(1); + } + if (!once_control->state) { + once_control->state = 1; + init_routine(); + } + InterlockedExchange(&(once_control->lock), 0); +} + +BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) +{ + switch (dwReason) { + case DLL_PROCESS_ATTACH: + thread_once(&init_once, internal_plist_init); + break; + case DLL_PROCESS_DETACH: + thread_once(&deinit_once, internal_plist_deinit); + break; + default: + break; + } + return 1; +} -PLIST_API void plist_cleanup(void) +#else + +static pthread_once_t init_once = PTHREAD_ONCE_INIT; +static pthread_once_t deinit_once = PTHREAD_ONCE_INIT; + +static void __attribute__((constructor)) libplist_initialize(void) { - /* free memory from parser initialization */ - xmlCleanupCharEncodingHandlers(); - xmlDictCleanup(); - xmlResetLastError(); - xmlCleanupGlobals(); - xmlCleanupThreads(); - xmlCleanupMemory(); + pthread_once(&init_once, internal_plist_init); } +static void __attribute__((destructor)) libplist_deinitialize(void) +{ + pthread_once(&deinit_once, internal_plist_deinit); +} + +#endif + + PLIST_API int plist_is_binary(const char *plist_data, uint32_t length) { if (length < 8) { -- cgit v1.1-32-gdbae