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 | |
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')
-rw-r--r-- | contrib/libs/libxml/CMakeLists.txt | 1 | ||||
-rw-r--r-- | contrib/libs/libxml/config-linux.h | 5 | ||||
-rw-r--r-- | contrib/libs/libxml/config-win.h | 1 | ||||
-rw-r--r-- | contrib/libs/libxml/dict.c | 26 | ||||
-rw-r--r-- | contrib/libs/libxml/rand.cpp | 10 | ||||
-rw-r--r-- | contrib/libs/libxml/rand.h | 15 |
6 files changed, 29 insertions, 29 deletions
diff --git a/contrib/libs/libxml/CMakeLists.txt b/contrib/libs/libxml/CMakeLists.txt index 84050ca56f..3edadf3eaa 100644 --- a/contrib/libs/libxml/CMakeLists.txt +++ b/contrib/libs/libxml/CMakeLists.txt @@ -53,7 +53,6 @@ target_sources(contrib-libs-libxml PRIVATE ${CMAKE_SOURCE_DIR}/contrib/libs/libxml/parser.c ${CMAKE_SOURCE_DIR}/contrib/libs/libxml/parserInternals.c ${CMAKE_SOURCE_DIR}/contrib/libs/libxml/pattern.c - ${CMAKE_SOURCE_DIR}/contrib/libs/libxml/rand.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/libxml/relaxng.c ${CMAKE_SOURCE_DIR}/contrib/libs/libxml/schematron.c ${CMAKE_SOURCE_DIR}/contrib/libs/libxml/threads.c diff --git a/contrib/libs/libxml/config-linux.h b/contrib/libs/libxml/config-linux.h index 04bc93369e..aff6e0033f 100644 --- a/contrib/libs/libxml/config-linux.h +++ b/contrib/libs/libxml/config-linux.h @@ -78,7 +78,7 @@ /* #undef HAVE_LZMA_H */ /* Define to 1 if you have the <malloc.h> header file. */ -// #define HAVE_MALLOC_H 1 +#define HAVE_MALLOC_H 1 /* Define to 1 if you have the <math.h> header file. */ #define HAVE_MATH_H 1 @@ -118,6 +118,9 @@ /* Define to 1 if you have the `rand' function. */ #define HAVE_RAND 1 +/* Define to 1 if you have the `rand_r' function. */ +#define HAVE_RAND_R 1 + /* Define to 1 if you have the <resolv.h> header file. */ #define HAVE_RESOLV_H 1 diff --git a/contrib/libs/libxml/config-win.h b/contrib/libs/libxml/config-win.h index c2a19e4e10..1a7cc47804 100644 --- a/contrib/libs/libxml/config-win.h +++ b/contrib/libs/libxml/config-win.h @@ -5,6 +5,7 @@ #undef HAVE_LIBPTHREAD #undef HAVE_PTHREAD_H #undef HAVE_UNISTD_H +#undef HAVE_RAND_R // Under Windows, use compiler-specific TLS: it seems broken the other way round. #define HAVE_COMPILER_TLS 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 diff --git a/contrib/libs/libxml/rand.cpp b/contrib/libs/libxml/rand.cpp deleted file mode 100644 index 459a806e8e..0000000000 --- a/contrib/libs/libxml/rand.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "rand.h" - -#include <cstdlib> -#include <util/random/random.h> -#include <util/system/types.h> - -int utilRandom() { - return (int)RandomNumber((ui32)RAND_MAX); -} - diff --git a/contrib/libs/libxml/rand.h b/contrib/libs/libxml/rand.h deleted file mode 100644 index eab92ea13f..0000000000 --- a/contrib/libs/libxml/rand.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __XML_RAND_H__ -#define __XML_RAND_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -int utilRandom(); - -#ifdef __cplusplus -} -#endif - -#endif - |