Aleksey N. Vinogradov 10 месяцев назад
Родитель
Сommit
fb8ad3aaf7

+ 1 - 1
config/config_cmake.h.in

@@ -32,7 +32,7 @@
 /* Define to 1 if you have the `clock_gettime' function. */
 #cmakedefine HAVE_CLOCK_GETTIME ${HAVE_CLOCK_GETTIME}
 
-/* Define to 1 if you have the `dlopen' function. */
+/* Define to 1 if you have the `dlopen' function. Use header libutil.h to have all variants available */
 #cmakedefine01 HAVE_DLOPEN
 
 /* Define if  you have async 'getaddrinfo_a' */

+ 0 - 1
src/columnarlib.cpp

@@ -12,7 +12,6 @@
 #include "sphinxutils.h"
 #include "sphinxexpr.h"
 #include "libutils.h"
-#include "fileutils.h"
 #include "schema/columninfo.h"
 #include "schema/schema.h"
 

+ 1 - 1
src/compressed_mysql_layer.cpp

@@ -11,7 +11,7 @@
 #include "compressed_mysql_layer.h"
 
 // for UNALIGNED_RAM_ACCESS
-#include "sphinxdefs.h"
+#include "config.h"
 
 
 DWORD MysqlCompressedSocket_c::ReadLSBSmallDword ( InputBuffer_c& tIn )

+ 1 - 3
src/coro_stack.h

@@ -10,8 +10,6 @@
 
 #pragma once
 
-#include "config.h"
-
 #if __has_include( <valgrind/valgrind.h>)
 #define BOOST_USE_VALGRIND 1
 #include <valgrind/valgrind.h>
@@ -20,8 +18,8 @@
 #endif
 
 #include <boost/context/stack_context.hpp>
-#include "std/vector.h"
 #include "std/ints.h"
+#include "std/vectraits.h"
 
 namespace Threads
 {

+ 1 - 2
src/debug_cmds.cpp

@@ -18,12 +18,11 @@
 #include "digest_sha1.h"
 #include "tracer.h"
 #include "netfetch.h"
+#include "config.h"
 
 #include "taskmalloctrim.h"
 #include "tasksavestate.h"
 
-#include <csignal>
-
 /////////////////////////////////////////////////////////////////////////////
 namespace DebugCmd {
 enum Traits_e : BYTE

+ 2 - 0
src/dict/template_dict_traits.cpp

@@ -26,6 +26,8 @@
 #include "sphinxjson.h"
 #include "tokenizer/tok_internals.h"
 
+#include <sys/stat.h>
+
 CSphString g_sLemmatizerBase;
 
 /// morphology

+ 0 - 2
src/event.h

@@ -11,8 +11,6 @@
 
 #pragma once
 
-#include "config.h"
-
 #include "sphinxstd.h"
 #include <mutex>
 

+ 1 - 0
src/fileio.cpp

@@ -12,6 +12,7 @@
 
 #include "fileio.h"
 #include "sphinxint.h"
+#include <sys/stat.h>
 
 #define SPH_READ_NOPROGRESS_CHUNK (32768*1024)
 

+ 1 - 0
src/fileutils.cpp

@@ -13,6 +13,7 @@
 #include "fileutils.h"
 #include "sphinxint.h"
 #include "std/crc32.h"
+#include <sys/stat.h>
 
 #if _WIN32
 	#define getcwd		_getcwd

+ 0 - 2
src/fileutils.h

@@ -17,8 +17,6 @@
 #include "std/strerrorm.h"
 #include <fcntl.h>
 
-#include <sys/stat.h>
-
 #if !_WIN32
  #include <sys/mman.h>
 #endif

+ 1 - 0
src/global_idf.cpp

@@ -13,6 +13,7 @@
 #include "sphinxint.h"
 #include "fileutils.h"
 
+#include <sys/stat.h>
 #include <math.h>
 
 

+ 1 - 0
src/gtests/gtests_rtstuff.cpp

@@ -19,6 +19,7 @@
 #include "searchdaemon.h"
 #include "binlog.h"
 #include "accumulator.h"
+#include "sphinxudf.h"
 
 #include <gmock/gmock.h>
 

+ 1 - 1
src/indexer.cpp

@@ -26,8 +26,8 @@
 #include "tokenizer/tokenizer.h"
 #include "secondarylib.h"
 #include "knnlib.h"
+#include "config.h"
 
-#include <sys/stat.h>
 #include <sys/types.h>
 #include <ctype.h>
 #include <errno.h>

+ 25 - 2
src/libutils.cpp

@@ -46,9 +46,32 @@ const char * dlerror()
 
 #endif // _WIN32
 
-std::optional<CSphString> TryPath ( const CSphString& sFullpath, int iVersion )
+ScopedHandle_c::~ScopedHandle_c ()
 {
-	// first try versioned variant. So, that non-versioned libs from 'ancient age' doesn't suppress new one one
+	if ( m_pHandle )
+		dlclose ( m_pHandle );
+}
+
+void * DlSym ( void * pHandle, const char * szFunc, const CSphString & sLib, CSphString & sError )
+{
+#if HAVE_DLOPEN
+	auto * pSym = dlsym ( pHandle, szFunc );
+	if ( !pSym )
+	{
+		sError.SetSprintf ( "symbol '%s' not found in '%s'", szFunc, sLib.cstr() );
+		dlclose ( pHandle );
+	}
+
+	return pSym;
+#else
+	return nullptr;
+#endif
+}
+
+
+std::optional<CSphString> TryPath ( const CSphString & sFullpath, int iVersion )
+{
+	// first try versioned variant. So, that non-versioned libs from 'ancient age' doesn't suppress new one
 	auto sVersionedFullPath = SphSprintf ( "%s.%i", sFullpath.cstr(), iVersion );
 	if ( sphFileExists ( sVersionedFullPath.cstr() ) )
 		return sVersionedFullPath;

+ 14 - 32
src/libutils.h

@@ -12,8 +12,9 @@
 
 #pragma once
 
-#include "sphinxstd.h"
-
+// HAVE_DLOPEN
+#include "config.h"
+#if HAVE_DLOPEN
 #if _WIN32
 	#define RTLD_LAZY		0
 	#define RTLD_NOW		0
@@ -24,16 +25,13 @@
 	void *			dlopen ( const char * libname, int );
 	int				dlclose ( void * lib );
 	const char *	dlerror();
-#else // !_WIN32
-#include "config.h"
-#if HAVE_DLOPEN
+#else
 #	include <dlfcn.h>
-#endif // HAVE_DLOPEN
+#endif
+#include "std/string.h"
+#include <utility>
 #endif // _WIN32
 
-#if HAVE_DLOPEN
-
-#include <utility>
 
 class ScopedHandle_c final
 {
@@ -42,42 +40,26 @@ public:
 		: m_pHandle ( pHandle )
 	{}
 
-	~ScopedHandle_c()
-	{
-		if ( m_pHandle )
-			dlclose ( m_pHandle );
-	}
+	~ScopedHandle_c();
 
-	void * Leak()
+	void * Leak() noexcept
 	{
 		return std::exchange ( m_pHandle, nullptr );
 	}
 
-	void * Get() { return m_pHandle; }
+	void * Get() const noexcept { return m_pHandle; }
 
 private:
 	void * m_pHandle = nullptr;
 };
 
-template <typename T>
-bool LoadFunc ( T & pFunc, void * pHandle, const char * szFunc, const CSphString & sLib, CSphString & sError )
-{
-	pFunc = (T) dlsym ( pHandle, szFunc );
-	if ( !pFunc )
-	{
-		sError.SetSprintf ( "symbol '%s' not found in '%s'", szFunc, sLib.cstr() );
-		dlclose ( pHandle );
-		return false;
-	}
+void * DlSym ( void * pHandle, const char * szFunc, const CSphString & sLib, CSphString & sError );
 
-	return true;
-}
-#else
-template <typename T>
+template<typename T>
 bool LoadFunc ( T & pFunc, void * pHandle, const char * szFunc, const CSphString & sLib, CSphString & sError )
 {
-	return false;
+	pFunc = (T) DlSym ( pHandle, szFunc, sLib, sError  );
+	return !!pFunc;
 }
-#endif // HAVE_DLOPEN
 
 CSphString TryDifferentPaths ( const CSphString & sLibfile, const CSphString & sFullpath, int iVersion );

+ 1 - 0
src/pollable_event.cpp

@@ -14,6 +14,7 @@
 
 #include "searchdaemon.h"
 
+#include "config.h"
 #if HAVE_EVENTFD
 #include <sys/eventfd.h>
 #endif

+ 4 - 0
src/searchd.cpp

@@ -44,6 +44,7 @@
 #include "frontendschema.h"
 #include "skip_cache.h"
 #include "jieba.h"
+#include "sphinxexcerpt.h"
 #include "daemon/winservice.h"
 #include "daemon/crash_logger.h"
 
@@ -64,11 +65,14 @@
 #include <csignal>
 #include <clocale>
 
+#include <sys/stat.h>
 #if !_WIN32
 	#include <sys/wait.h>
 	#include <netinet/in.h>
 #endif
 
+// USE_SYSLOG, HAVE_GETRLIMIT, HAVE_SETRLIMIT
+#include "config.h"
 #if USE_SYSLOG
 	#include <syslog.h>
 #endif

+ 1 - 3
src/searchdaemon.cpp

@@ -17,8 +17,6 @@
 #include "searchdaemon.h"
 #include "coroutine.h"
 
-#include <optional>
-
 #if _WIN32
 	#define USE_PSI_INTERFACE 1
 
@@ -43,7 +41,7 @@
 #include <netinet/in.h>
 #endif
 
-#include <cmath>
+#include "config.h"
 
 /////////////////////////////////////////////////////////////////////////////
 // MISC GLOBALS

+ 1 - 0
src/searchdaemon.h

@@ -20,6 +20,7 @@
 #include "searchdconfig.h"
 #include "memio.h"
 #include "accumulator.h"
+#include "config.h"
 
 /////////////////////////////////////////////////////////////////////////////
 // MACHINE-DEPENDENT STUFF

+ 0 - 2
src/searchdconfig.cpp

@@ -30,7 +30,6 @@ static Coro::RWLock_c g_tCfgIndexesLock;
 static CSphVector<ClusterDesc_t> g_dCfgClusters;
 static CSphVector<IndexDesc_t> g_dCfgIndexes GUARDED_BY ( g_tCfgIndexesLock );
 
-static CSphString	g_sLogFile;
 static CSphString	g_sDataDir;
 static CSphString	g_sConfigPath;
 static bool			g_bConfigless = false;
@@ -699,7 +698,6 @@ static const char * g_sJsonConfName = "manticore.json";
 bool LoadConfigInt ( const CSphConfig & hConf, const CSphString & sConfigFile, CSphString & sError ) REQUIRES (MainThread)
 {
 	const CSphConfigSection & hSearchd = hConf["searchd"]["searchd"];
-	g_sLogFile = hSearchd.GetStr ( "log", "" );
 
 	g_bConfigless = hSearchd.Exists("data_dir");
 	if ( !g_bConfigless )

+ 1 - 1
src/searchdha.cpp

@@ -16,7 +16,6 @@
 #include "searchdha.h"
 #include "searchdtask.h"
 #include "coroutine.h"
-#include "mini_timer.h"
 #include "pollable_event.h"
 #include "netpoll.h"
 
@@ -33,6 +32,7 @@
 	#include <WS2tcpip.h>
 #endif
 
+#include "config.h"
 #if HAVE_GETADDRINFO_A
 	#include <signal.h>
 #endif

+ 1 - 4
src/searchnode.cpp

@@ -13,14 +13,11 @@
 #include "searchnode.h"
 #include "sphinxquery.h"
 #include "sphinxint.h"
-#include "sphinxplugin.h"
 #include "sphinxqcache.h"
-#include "attribute.h"
 #include "mini_timer.h"
 #include "coroutine.h"
 #include "secondaryindex.h"
-
-#include <math.h>
+#include "client_task_info.h"
 
 //////////////////////////////////////////////////////////////////////////
 

+ 2 - 4
src/secondarylib.cpp

@@ -11,11 +11,9 @@
 
 #include "sphinxutils.h"
 #include "libutils.h"
-#include "fileutils.h"
-#include "schema/columninfo.h"
-#include "schema/schema.h"
-#include "columnarmisc.h"
 #include "secondarylib.h"
+#include "std/env.h"
+#include "std/sys.h"
 
 namespace sec {
 using CheckStorage_fn =			void (*) ( const std::string & sFilename, uint32_t uNumRows, std::function<void (const char*)> & fnError, std::function<void (const char*)> & fnProgress );

+ 1 - 1
src/snippetfunctor.h

@@ -14,7 +14,7 @@
 #define _snippetfunctor_
 
 #include "sphinxstd.h"
-#include "sphinxquery.h"
+#include "sphinxexcerpt.h"
 #include "sphinxsearch.h"
 #include "sphinxdefs.h"
 

+ 1 - 1
src/snippetindex.cpp

@@ -12,7 +12,7 @@
 
 #include "snippetindex.h"
 #include "sphinxint.h"
-
+#include "sphinxexcerpt.h"
 
 struct KeywordCmp_t
 {

+ 0 - 2
src/sphinxint.h

@@ -16,8 +16,6 @@
 #include "sphinxstd.h"
 #include "sphinxfilter.h"
 #include "sphinxquery.h"
-#include "sphinxexcerpt.h"
-#include "sphinxudf.h"
 #include "sphinxjsonquery.h"
 #include "sphinxutils.h"
 #include "fileio.h"

+ 2 - 0
src/sphinxjson.cpp

@@ -19,6 +19,8 @@
 #include <io.h> // for isatty() in sphinxjson.c
 #endif
 
+// for UNALIGNED_RAM_ACCESS
+#include "config.h"
 
 //////////////////////////////////////////////////////////////////////////
 // helpers

+ 1 - 0
src/sphinxjson.h

@@ -16,6 +16,7 @@
 #include "sphinxutils.h"
 #include "sphinxdefs.h"
 #include "grouper.h"
+#include "config.h"
 
 class ISphExpr;
 

+ 1 - 1
src/sphinxjsonquery.cpp

@@ -18,8 +18,8 @@
 #include "searchdsql.h"
 #include "searchdha.h"
 #include "knnmisc.h"
-#include "datetime.h"
 #include "sorterscroll.h"
+#include "sphinxexcerpt.h"
 
 #include "json/cJSON.h"
 

+ 2 - 0
src/sphinxplugin.cpp

@@ -13,6 +13,8 @@
 #include "sphinxint.h"
 #include "sphinxutils.h"
 #include "sphinxplugin.h"
+
+// for HAVE_DLOPEN
 #include "libutils.h"
 
 //////////////////////////////////////////////////////////////////////////

+ 0 - 1
src/sphinxsearch.h

@@ -15,7 +15,6 @@
 
 #include "sphinxquery.h"
 #include "sphinxint.h"
-#include "client_task_info.h"
 
 //////////////////////////////////////////////////////////////////////////
 

+ 2 - 1
src/sphinxstemen.cpp

@@ -9,7 +9,8 @@
 // did not, you can find it at http://www.gnu.org/
 //
 
-#include "sphinxdefs.h" // for UNALIGNED_RAM_ACCESS
+// for UNALIGNED_RAM_ACCESS
+#include "config.h"
 
 #if defined(_MSC_VER) && !defined(__cplusplus)
 #define inline

+ 9 - 7
src/sphinxutils.cpp

@@ -21,19 +21,24 @@
 #include "threadutils.h"
 #include "indexfiles.h"
 #include "datetime.h"
+#include "coroutine.h"
+#include "sphinxexcerpt.h"
 
-#include <codecvt>
+// COMPILER, OS_UNAME, etc
+#include "config.h"
+#include "libutils.h"
+
+#include <sys/stat.h>
 #include <ctype.h>
 #include <fcntl.h>
-#include <errno.h>
 #if __has_include(<execinfo.h>)
 #include <execinfo.h>
 #endif
 
-#include <sstream>
 #include <iomanip>
 
 #if _WIN32
+#include <codecvt>
 #include <io.h> // for ::open on windows
 #include <dbghelp.h>
 #else
@@ -47,9 +52,6 @@
 #include <sys/prctl.h>
 #endif
 
-#include "libutils.h"
-#include "coroutine.h"
-
 #if __has_include (<malloc.h>)
 #include <malloc.h>
 #endif
@@ -67,7 +69,7 @@ CSphString g_sWinInstallPath;
 // STRING FUNCTIONS
 //////////////////////////////////////////////////////////////////////////
 
-inline static char * ltrim ( char * sLine )
+static char * ltrim ( char * sLine )
 {
 	while ( *sLine && sphIsSpace(*sLine) )
 		sLine++;

+ 1 - 3
src/sphinxutils.h

@@ -16,12 +16,10 @@
 #ifndef _sphinxutils_
 #define _sphinxutils_
 
-#include <csignal>
-
-#include "config.h"
 #include "std/stringhash.h"
 #include "std/stringbuilder.h"
 
+#include <csignal>
 //////////////////////////////////////////////////////////////////////////
 
 /// my own isalpha (let's build our own theme park!)

+ 1 - 0
src/std/autoevent.cpp

@@ -13,6 +13,7 @@
 #include "autoevent.h"
 
 #include "timers.h"
+// for HAVE_PTHREAD_COND_TIMEDWAIT
 #include "config.h"
 
 

+ 0 - 1
src/std/checks.h

@@ -20,7 +20,6 @@
 /////////////////////////////////////////////////////////////////////////////
 
 #define VARIABLE_IS_NOT_USED __attribute__((unused))
-#define MAYBE_UNUSED( expr ) do { (void)( expr ); } while ( 0 )
 
 #define STATIC_SIZE_ASSERT(_type,_size)	static_assert ( sizeof(_type)==_size, "sizeof " #_type " must be " #_size " bytes" )
 

+ 1 - 0
src/std/env.cpp

@@ -13,6 +13,7 @@
 #include "env.h"
 
 #include "sphinxutils.h"
+#include "config.h"
 
 #ifdef _WIN32
 #include "fileutils.h"

+ 0 - 1
src/std/format.h

@@ -12,7 +12,6 @@
 
 #pragma once
 
-#include "config.h"
 #include <limits.h>
 #include <cstring>
 

+ 0 - 2
src/std/ints.h

@@ -12,8 +12,6 @@
 
 #pragma once
 
-#include "config.h"
-
 #include <cstdio>
 
 // for 64-bit types

+ 2 - 0
src/std/mem.cpp

@@ -13,6 +13,8 @@
 #include "mem.h"
 #include "format.h"
 #include "fatal.h"
+#include "config.h"
+
 #include <cstdlib>
 
 /////////////////////////////////////////////////////////////////////////////

+ 1 - 0
src/std/rwlock.cpp

@@ -11,6 +11,7 @@
 //
 
 #include "rwlock.h"
+#include "config.h"
 
 //////////////////////////////////////////////////////////////////////////
 // RWLOCK

+ 3 - 0
src/std/timers.cpp

@@ -12,6 +12,9 @@
 
 #include "timers.h"
 
+// for HAVE_CLOCK_GETTIME
+#include "config.h"
+
 #if !_WIN32
 #include <sys/time.h> // for gettimeofday
 #include <time.h>

+ 1 - 0
src/taskmalloctrim.cpp

@@ -12,6 +12,7 @@
 
 #include "taskmalloctrim.h"
 
+#include "config.h"
 #if HAVE_MALLOC_TRIM
 
 #include <malloc.h>