diff options
author | eninng <eninng@yandex-team.ru> | 2022-05-13 12:02:40 +0300 |
---|---|---|
committer | eninng <eninng@yandex-team.ru> | 2022-05-13 12:02:40 +0300 |
commit | dcd3e269e3c79fdedc5fc7f79f4a6e5440765084 (patch) | |
tree | 9bd3795025d31007759d1b2e401659e194c2353c /contrib/libs/libxml/dict.c | |
parent | 647fde571299faf9f74c7682c660a9c4795f3318 (diff) | |
download | ydb-dcd3e269e3c79fdedc5fc7f79f4a6e5440765084.tar.gz |
[libxml] Get rid of utilRandom dependency. Add NO_RUNTIME if util is unused
- Return native libxml random implementation.
- Use thread_local instead of mutex if rand_r is used
- Add NO_RUNTIME if util is unused
Task: SK-6086
ref:aae9538109bc91f0eb832032ff6431325d0ad5e9
Diffstat (limited to 'contrib/libs/libxml/dict.c')
-rw-r--r-- | contrib/libs/libxml/dict.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/contrib/libs/libxml/dict.c b/contrib/libs/libxml/dict.c index e198c22d35..96a407b39d 100644 --- a/contrib/libs/libxml/dict.c +++ b/contrib/libs/libxml/dict.c @@ -58,7 +58,6 @@ typedef unsigned __int32 uint32_t; #include <libxml/xmlmemory.h> #include <libxml/xmlerror.h> #include <libxml/globals.h> -#include "rand.h" /* #define DEBUG_GROW */ /* #define DICT_DEBUG_PATTERNS */ @@ -140,6 +139,15 @@ static xmlRMutexPtr xmlDictMutex = NULL; */ static int xmlDictInitialized = 0; +#ifdef DICT_RANDOMIZATION +#ifdef HAVE_RAND_R +/* + * Internal data for random function + */ +static _Thread_local unsigned int rand_seed = 0; +#endif +#endif + /** * xmlInitializeDict: * @@ -173,6 +181,11 @@ int __xmlInitializeDict(void) { return(0); xmlRMutexLock(xmlDictMutex); +#ifdef DICT_RANDOMIZATION +#ifndef HAVE_RAND_R + srand(time(NULL)); +#endif +#endif xmlDictInitialized = 1; xmlRMutexUnlock(xmlDictMutex); return(1); @@ -185,7 +198,16 @@ int __xmlRandom(void) { if (xmlDictInitialized == 0) __xmlInitializeDict(); - return utilRandom(); +#ifdef HAVE_RAND_R + if (rand_seed == 0) + rand_seed = time(NULL); + ret = rand_r(& rand_seed); +#else + xmlRMutexLock(xmlDictMutex); + ret = rand(); + xmlRMutexUnlock(xmlDictMutex); +#endif + return(ret); } #endif |