1 /*------------------------------------------------------------------------------
2 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
3 *
4 * Distributable under the terms of either the Apache License (Version 2.0) or
5 * the GNU Lesser General Public License, as specified in the COPYING file.
6 *
7 * Changes are Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
8 ------------------------------------------------------------------------------*/
9 #include "CLucene/StdHeader.h"
10 #include "CLucene/util/Misc.h"
11 
12 #include "CLucene/search/Sort.h"
13 #include "CLucene/search/Similarity.h"
14 #include "CLucene/search/FieldCache.h"
15 #include "CLucene/search/FieldSortedHitQueue.h"
16 
17 #if defined(_CLCOMPILER_MSVC) && defined(_DEBUG)
18 #   define CRTDBG_MAP_ALLOC
19 #   include <stdlib.h>
20 #ifndef UNDER_CE
21 #   include <crtdbg.h>
22 #endif
23 #endif
24 
25 CL_NS_USE(util)
26 
27 TCHAR* _LUCENE_BLANK_STRING = _T("");
28 char* _LUCENE_BLANK_ASTRING = "";
29 
30 #ifndef Q_CC_MIPS
31 #if defined(_LUCENE_THREADMUTEX_USINGDEFAULT)
32 #    if defined(_LUCENE_PRAGMA_WARNINGS)
33 #        pragma message ("==================Using clunky thread mutex!!!==================")
34 #    else
35 #       if !defined(Q_OS_SOLARIS)
36 #           warning "==================Using clunky thread mutex!!!=================="
37 #       endif
38 #    endif
39 #endif
40 
41 #if defined(_ASCII)
42 #    if defined(_LUCENE_PRAGMA_WARNINGS)
43 #        pragma message ("==================Using ascii mode!!!==================")
44 #    else
45 #        if !defined(Q_OS_SOLARIS)
46 #            warning "==================Using ascii mode!!!=================="
47 #        endif
48 #    endif
49 #endif
50 
51 //This causes confusion, because CLucene doesn't really need hashed maps/sets. My experience with the
52 //hash maps on linux are that there are no significant improvements in using them (infact it adversely
53 //affected performance... therefore we'll just silently ignore
54 /*#if defined(LUCENE_DISABLE_HASHING)
55 #    if defined(_LUCENE_PRAGMA_WARNINGS)
56 #        pragma message ("==================Hashing not available or is disabled! CLucene may run slower than optimal ==================")
57 #    else
58 #        if !defined(Q_OS_SOLARIS)
59 #            warning "==================Hashing not available or is disabled! CLucene may run slower than optimal =================="
60 #        endif
61 #    endif
62 #endif*/
63 #endif
64 
65 //clears all static memory. do not attempt to do anything else
66 //in clucene after calling this function
_lucene_shutdown()67 void _lucene_shutdown(){
68     CL_NS(search)::FieldSortedHitQueue::Comparators.clear();
69 	_CLDELETE(CL_NS(search)::Sort::RELEVANCE);
70 	_CLDELETE(CL_NS(search)::Sort::INDEXORDER);
71 	_CLDELETE(CL_NS(search)::ScoreDocComparator::INDEXORDER);
72 	_CLDELETE(CL_NS(search)::ScoreDocComparator::RELEVANCE);
73 	_CLDELETE(CL_NS(search)::SortField::FIELD_SCORE);
74 	_CLDELETE(CL_NS(search)::SortField::FIELD_DOC);
75 	_CLDELETE(CL_NS(search)::FieldCache::DEFAULT);
76 
77 	_CLLDELETE(CL_NS(search)::Similarity::getDefault());
78 
79     CL_NS(util)::CLStringIntern::shutdown();
80 }
81 
CLDebugBreak()82 void CLDebugBreak(){
83 	//can be used for debug breaking...
84 #if defined(_CLCOMPILER_MSVC) && defined(_DEBUG)
85 	_CrtDbgBreak();
86 #else
87 	int i=0; //a line to put breakpoint on
88 #endif
89 }
90 
91 //these are functions that lucene uses which
92 //are not replacement functions
lucenestrdup(const char * v CL_FILELINEPARAM)93 char* lucenestrdup(const char* v CL_FILELINEPARAM){
94     size_t len = strlen(v);
95     char* ret = new char[len+1];
96     strncpy(ret,v,len+1);
97 #if defined(LUCENE_ENABLE_MEMLEAKTRACKING)
98 #   if defined(LUCENE_ENABLE_FILELINEINFO)
99 		CL_NS(debug)::LuceneBase::__cl_voidpadd((void*)ret,file,line,len);
100 #   else
101 		CL_NS(debug)::LuceneBase::__cl_voidpadd((void*)ret,__FILE__,__LINE__,len);
102 #   endif
103 #endif
104     return ret;
105 }
106 
107 #ifdef _UCS2
lucenewcsdup(const wchar_t * v CL_FILELINEPARAM)108 wchar_t* lucenewcsdup(const wchar_t* v CL_FILELINEPARAM){
109     size_t len = _tcslen(v);
110     wchar_t* ret = new wchar_t[len+1];
111     _tcsncpy(ret,v,len+1);
112 #if defined(LUCENE_ENABLE_MEMLEAKTRACKING)
113 #   if defined(LUCENE_ENABLE_FILELINEINFO)
114 		CL_NS(debug)::LuceneBase::__cl_voidpadd((void*)ret,file,line,len);
115 #   else
116 		CL_NS(debug)::LuceneBase::__cl_voidpadd((void*)ret,__FILE__,__LINE__,len);
117 #   endif
118 #endif
119     return ret;
120 }
121 #endif //ucs2
122 
123 
124 //ok, these are the exceptions, but these never
125 //exist on non-msvc platform, so lets put it here
126 #ifndef _CL_HAVE_FILELENGTH
lucene_filelength(int filehandle)127 int64_t lucene_filelength(int filehandle)
128 {
129     struct fileStat info;
130     if (fileHandleStat(filehandle, &info) == -1)
131  	 _CLTHROWA( CL_ERR_IO,"fileStat error" );
132     return info.st_size;
133 }
134 #endif
135