[PATCH] Re: initialization problems with static p11-kit on mingw

Mark Brand mabrand at mabrand.nl
Sat Oct 29 16:23:17 PDT 2011


> Is the trick now to get this to happen automatically with static linking?
>
Replying to myself again..

This patch *seems* to work and it's similiar to the way libgpg-error 
solved the problem. Not sure about the safety of using int _p11_once 
like that. Can we get away with this?

Mark

diff --git a/p11-kit/private.h b/p11-kit/private.h
index d23c1e6..bfa9390 100644
--- a/p11-kit/private.h
+++ b/p11-kit/private.h
@@ -59,9 +59,17 @@ p11_local *   
_p11_library_get_thread_local                     (void);

  #ifdef OS_WIN32

+#ifdef DLL_EXPORT
  /* No implementation, because done by DllMain */
  #define     _p11_library_init_once()

+#else
+
+extern int _p11_once;
+#define     _p11_library_init_once() \
+       if (!_p11_once) { _p11_library_init(); _p11_once=1; }
+#endif
+
  #else /* !OS_WIN32 */

  extern pthread_once_t _p11_once;
diff --git a/p11-kit/util.c b/p11-kit/util.c
index c04b636..7e4ed71 100644
--- a/p11-kit/util.c
+++ b/p11-kit/util.c
@@ -60,6 +60,12 @@ mutex_t _p11_mutex;
  pthread_once_t _p11_once;
  #endif

+#ifdef OS_WIN32
+#ifndef DLL_EXPORT
+int _p11_once = 0;
+#endif
+#endif
+
  /**
   * SECTION:p11-kit-future
   * @title: Future




More information about the p11-glue mailing list