+ // access the object creating it on demand
+ ValueType *Get()
+ {
+ void *value = m_key.Get();
+ if ( !value )
+ {
+ // ValueType must be POD to be used in wxHAS_COMPILER_TLS case
+ // anyhow (at least gcc doesn't accept non-POD values being
+ // declared with __thread) so initialize it as a POD too
+ value = calloc(1, sizeof(ValueType));
+
+ if ( !m_key.Set(value) )
+ {
+ free(value);
+
+ // this will probably result in a crash in the caller but
+ // it's arguably better to crash immediately instead of
+ // slowly dying from out-of-memory errors which would
+ // happen as the next access to this object would allocate
+ // another ValueType instance and so on forever
+ value = NULL;
+ }
+ }
+
+ return static_cast<ValueType *>(value);