From 0fecb5f2775f0c07ec602a9284fb8ba2641cec97 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 28 Jul 2020 20:31:48 +0100 Subject: [PATCH] Be more explicit about string/character conversions. This *may* fix the bug where a layer name isn't displayed correctly in the error dialog. But probably not. --- include/libeval_compiler/libeval_compiler.h | 5 ++--- pcbnew/drc/drc_rule.cpp | 2 +- pcbnew/pcb_expr_evaluator.cpp | 24 ++++++++++----------- pcbnew/pcb_expr_evaluator.h | 8 +++---- qa/drc_proto/drc_rule.cpp | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/libeval_compiler/libeval_compiler.h b/include/libeval_compiler/libeval_compiler.h index dbd73593a1..ebf6e22c9c 100644 --- a/include/libeval_compiler/libeval_compiler.h +++ b/include/libeval_compiler/libeval_compiler.h @@ -309,13 +309,12 @@ public: VALUE* Run( CONTEXT* ctx ); std::string Dump() const; - virtual VAR_REF* createVarRef( COMPILER* aCompiler, const std::string& var, - const std::string& field ) + virtual VAR_REF* createVarRef( COMPILER* aCompiler, const char* var, const char* field ) { return nullptr; }; - virtual FUNC_PTR createFuncCall( COMPILER* aCompiler, const std::string& name ) + virtual FUNC_PTR createFuncCall( COMPILER* aCompiler, const char* name ) { return nullptr; }; diff --git a/pcbnew/drc/drc_rule.cpp b/pcbnew/drc/drc_rule.cpp index 8df921ca30..05a1117663 100644 --- a/pcbnew/drc/drc_rule.cpp +++ b/pcbnew/drc/drc_rule.cpp @@ -140,7 +140,7 @@ bool DRC_RULE_CONDITION::Compile() PCB_EXPR_CONTEXT preflightContext; - bool ok = compiler.Compile( (const char*) m_Expression.c_str(), m_ucode, &preflightContext ); + bool ok = compiler.Compile( m_Expression.ToUTF8().data(), m_ucode, &preflightContext ); if( ok ) return true; diff --git a/pcbnew/pcb_expr_evaluator.cpp b/pcbnew/pcb_expr_evaluator.cpp index 181d2701a1..47e664fce8 100644 --- a/pcbnew/pcb_expr_evaluator.cpp +++ b/pcbnew/pcb_expr_evaluator.cpp @@ -139,28 +139,28 @@ LIBEVAL::VALUE PCB_EXPR_VAR_REF::GetValue( LIBEVAL::CONTEXT* aCtx ) LIBEVAL::UCODE::FUNC_PTR PCB_EXPR_UCODE::createFuncCall( LIBEVAL::COMPILER* aCompiler, - const std::string& name ) + const char* aName ) { PCB_EXPR_BUILTIN_FUNCTIONS& registry = PCB_EXPR_BUILTIN_FUNCTIONS::Instance(); - auto f = registry.Get( boost::to_lower_copy( name ) ); + std::string lowerName( aName ); + boost::to_lower( lowerName ); - return f; + return registry.Get( lowerName ); } -LIBEVAL::VAR_REF* PCB_EXPR_UCODE::createVarRef( LIBEVAL::COMPILER *aCompiler, - const std::string& aVar, - const std::string& aField ) +LIBEVAL::VAR_REF* PCB_EXPR_UCODE::createVarRef( LIBEVAL::COMPILER *aCompiler, const char* aVar, + const char* aField ) { PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); PCB_EXPR_VAR_REF* vref = nullptr; - if( aVar == "A" ) + if( *aVar == 'A' ) { vref = new PCB_EXPR_VAR_REF( 0 ); } - else if( aVar == "B" ) + else if( *aVar == 'B' ) { vref = new PCB_EXPR_VAR_REF( 1 ); } @@ -170,11 +170,11 @@ LIBEVAL::VAR_REF* PCB_EXPR_UCODE::createVarRef( LIBEVAL::COMPILER *aCompiler, return vref; } - if( aField.empty() ) // return reference to base object + if( strlen( aField ) == 0 ) // return reference to base object return vref; - std::string field( aField ); - std::replace( field.begin(), field.end(), '_', ' '); + wxString field = wxString::FromUTF8( aField ); + field.Replace( "_", " " ); for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() ) { @@ -267,7 +267,7 @@ bool PCB_EXPR_EVALUATOR::Evaluate( const wxString& aExpr ) PCB_EXPR_UCODE ucode; LIBEVAL::CONTEXT preflightContext; - if( !m_compiler.Compile( (const char*) aExpr.c_str(), &ucode, &preflightContext ) ) + if( !m_compiler.Compile( aExpr.ToUTF8().data(), &ucode, &preflightContext ) ) { m_errorStatus = m_compiler.GetErrorStatus(); return false; diff --git a/pcbnew/pcb_expr_evaluator.h b/pcbnew/pcb_expr_evaluator.h index 19db5c53df..82a455a52d 100644 --- a/pcbnew/pcb_expr_evaluator.h +++ b/pcbnew/pcb_expr_evaluator.h @@ -40,12 +40,10 @@ class PCB_EXPR_VAR_REF; class PCB_EXPR_UCODE final : public LIBEVAL::UCODE { public: - virtual LIBEVAL::VAR_REF* createVarRef( LIBEVAL::COMPILER *aCompiler, - const std::string& aVar, - const std::string& aField ) override; + virtual LIBEVAL::VAR_REF* createVarRef( LIBEVAL::COMPILER *aCompiler, const char* aVar, + const char* aField ) override; - virtual FUNC_PTR createFuncCall( LIBEVAL::COMPILER* aCompiler, - const std::string& name ) override; + virtual FUNC_PTR createFuncCall( LIBEVAL::COMPILER* aCompiler, const char* aName ) override; }; diff --git a/qa/drc_proto/drc_rule.cpp b/qa/drc_proto/drc_rule.cpp index 51a9938f47..0723f11deb 100644 --- a/qa/drc_proto/drc_rule.cpp +++ b/qa/drc_proto/drc_rule.cpp @@ -70,7 +70,7 @@ bool test::DRC_RULE_CONDITION::Compile() if (!m_ucode) m_ucode = new PCB_EXPR_UCODE; - bool ok = compiler.Compile( (const char*) m_Expression.c_str(), m_ucode ); + bool ok = compiler.Compile( m_Expression.ToUTF8().data(), m_ucode ); if( ok ) return true;