Skip to content
Permalink
Browse files

Fix #400 refactor expression parser to accurate follow refcounts

  • Loading branch information
klirichek committed Aug 23, 2018
1 parent 8a649c7 commit 71ff77737e63d1019b7c9804dca7fa2351025dba
Showing with 234 additions and 253 deletions.
  1. +12 −17 src/searchd.cpp
  2. +3 −2 src/sphinx.cpp
  3. +9 −6 src/sphinx.h
  4. +182 −178 src/sphinxexpr.cpp
  5. +16 −21 src/sphinxfilter.cpp
  6. +1 −1 src/sphinxint.h
  7. +11 −28 src/sphinxsearch.cpp
@@ -6136,8 +6136,8 @@ ESphSpz GetPassageBoundary ( const CSphString & );
/// suddenly, searchd-level expression function!
struct Expr_Snippet_c : public ISphStringExpr
{
ISphExpr * m_pArgs;
ISphExpr * m_pText = nullptr;
CSphRefcountedPtr<ISphExpr> m_pArgs;
CSphRefcountedPtr<ISphExpr> m_pText;
CSphIndex * m_pIndex;
SnippetContext_t m_tCtx;
mutable ExcerptQuery_t m_tHighlight;
@@ -6148,8 +6148,10 @@ struct Expr_Snippet_c : public ISphStringExpr
, m_pIndex ( pIndex )
, m_pProfiler ( pProfiler )
{
SafeAddRef ( pArglist );
assert ( pArglist->IsArglist() );
m_pText = pArglist->GetArg(0);
SafeAddRef ( m_pText );

CSphMatch tDummy;
char * pWords;
@@ -6238,11 +6240,6 @@ struct Expr_Snippet_c : public ISphStringExpr
m_tCtx.Setup ( m_pIndex, m_tHighlight, sError );
}

~Expr_Snippet_c() final
{
SafeRelease ( m_pArgs );
}

int StringEval ( const CSphMatch & tMatch, const BYTE ** ppStr ) const final
{
CSphScopedProfile ( m_pProfiler, SPH_QSTATE_SNIPPET );
@@ -6336,11 +6333,11 @@ struct ExprHook_t : public ISphExprHook
if ( pEvalStage )
*pEvalStage = SPH_EVAL_POSTLIMIT;

ISphExpr * pRes = new Expr_Snippet_c ( pLeft, m_pIndex, m_pProfiler, sError );
if ( sError.Length() )
SafeDelete ( pRes );
CSphRefcountedPtr<ISphExpr> pRes { new Expr_Snippet_c ( pLeft, m_pIndex, m_pProfiler, sError ) };
if ( !sError.IsEmpty () )
pRes = nullptr;

return pRes;
return pRes.Leak();
}

ESphAttr GetIdentType ( int ) final
@@ -12325,8 +12322,8 @@ bool PercolateParseFilters ( const char * sFilters, ESphCollation eCollation, co
if ( iRes!=0 && !dFilters.GetLength() && sError.Begins ( "percolate filters: syntax error" ) )
{
ESphAttr eAttrType = SPH_ATTR_NONE;
CSphScopedPtr<ISphExpr> pExpr ( sphExprParse ( sFilters, tSchema, &eAttrType, NULL, sError, NULL, eCollation ) );
if ( pExpr.Ptr() )
CSphScopedPtr<ISphExpr> pExpr { sphExprParse ( sFilters, tSchema, &eAttrType, NULL, sError, NULL, eCollation ) };
if ( pExpr )
{
sError = "";
iRes = 0;
@@ -16344,7 +16341,7 @@ void HandleMysqlSelectDual ( SqlRowBuffer_c & tOut, const SqlStmt_t & tStmt )
ESphAttr eAttrType;
CSphString sError;

ISphExpr * pExpr = sphExprParse ( sVar.cstr(), tSchema, &eAttrType, NULL, sError, NULL );
CSphRefcountedPtr<ISphExpr> pExpr { sphExprParse ( sVar.cstr(), tSchema, &eAttrType, NULL, sError, NULL ) };

if ( !pExpr )
{
@@ -16357,7 +16354,7 @@ void HandleMysqlSelectDual ( SqlRowBuffer_c & tOut, const SqlStmt_t & tStmt )
tOut.HeadEnd();

CSphMatch tMatch;
const BYTE * pStr = NULL;
const BYTE * pStr = nullptr;

switch ( eAttrType )
{
@@ -16374,8 +16371,6 @@ void HandleMysqlSelectDual ( SqlRowBuffer_c & tOut, const SqlStmt_t & tStmt )
break;
}

SafeDelete ( pExpr );

// done
tOut.Commit();
tOut.Eof();
@@ -6104,7 +6104,7 @@ CSphSchema & CSphSchema::operator = ( const ISphSchema & rhs )
}


CSphSchema & CSphSchema::operator = ( CSphSchema && rhs )
CSphSchema & CSphSchema::operator = ( CSphSchema && rhs ) noexcept
{
if ( this!=&rhs )
{
@@ -16597,7 +16597,8 @@ bool CSphQueryContext::SetupCalc ( CSphQueryResult * pResult, const ISphSchema &
CalcItem_t tCalc;
tCalc.m_eType = tIn.m_eAttrType;
tCalc.m_tLoc = tIn.m_tLocator;
tCalc.m_pExpr = pExpr;
tCalc.m_pExpr = pExpr; // is not owned, so stink but seems to be ok for now
SafeAddRef ( pExpr );
PoolPtrs_t tMva;
tMva.m_pMva = pMvaPool;
tMva.m_bArenaProhibit = bArenaProhibit;
@@ -1479,7 +1479,7 @@ struct CSphColumnInfo
CSphString m_sQuery; ///< query to retrieve values (for multi-valued attrs only)
CSphString m_sQueryRange; ///< query to retrieve range (for multi-valued attrs only)

CSphRefcountedPtr<ISphExpr> m_pExpr { nullptr };///< evaluator for expression items
CSphRefcountedPtr<ISphExpr> m_pExpr;///< evaluator for expression items
ESphAggrFunc m_eAggrFunc { SPH_AGGR_NONE }; ///< aggregate function on top of expression (for GROUP BY)
ESphEvalStage m_eStage { SPH_EVAL_STATIC };///< column evaluation stage (who and how computes this column)
bool m_bPayload = false;
@@ -1565,9 +1565,9 @@ class ISphSchema
class CSphSchemaHelper : public ISphSchema
{
public:
virtual void FreeDataPtrs ( CSphMatch * pMatch ) const;
virtual void CloneMatch ( CSphMatch * pDst, const CSphMatch & rhs ) const;
void DiscardPtr ( int iAttr );
void FreeDataPtrs ( CSphMatch * pMatch ) const final;
void CloneMatch ( CSphMatch * pDst, const CSphMatch & rhs ) const final;
void DiscardPtr ( int iAttr );

protected:
CSphVector<int> m_dDataPtrAttrs; // rowitems of pointers to data that are stored inside matches
@@ -1594,11 +1594,10 @@ class CSphSchema : public CSphSchemaHelper
/// ctor
explicit CSphSchema ( const char * sName="(nameless)" );
CSphSchema ( const CSphSchema & rhs );
~CSphSchema(){}

CSphSchema & operator = ( const ISphSchema & rhs );
CSphSchema & operator = ( const CSphSchema & rhs );
CSphSchema & operator = ( CSphSchema && rhs );
CSphSchema & operator = ( CSphSchema && rhs ) noexcept;

/// visitor-style uber-virtual assignment implementation
virtual void AssignTo ( CSphRsetSchema & lhs ) const;
@@ -1719,6 +1718,10 @@ class CSphRsetSchema : public CSphSchemaHelper

public:
CSphRsetSchema();
~CSphRsetSchema() override
{
assert (true);
};
CSphRsetSchema & operator = ( const ISphSchema & rhs );
CSphRsetSchema & operator = ( const CSphSchema & rhs );

0 comments on commit 71ff777

Please sign in to comment.
You can’t perform that action at this time.