Fix compares to null, part of bug1030.

This commit is contained in:
Wilson Snyder 2016-02-02 19:35:44 -05:00
parent 0725999f0a
commit 850100c9c2
3 changed files with 9 additions and 9 deletions

View File

@ -1324,7 +1324,7 @@ VerilatedVar* VerilatedScope::varFind(const char* namep) const {
return NULL; return NULL;
} }
void* VerilatedScope::exportFindNullError(int funcnum) const { void* VerilatedScope::exportFindNullError(int funcnum) {
// Slowpath - Called only when find has failed // Slowpath - Called only when find has failed
string msg = (string("Testbench C called '") string msg = (string("Testbench C called '")
+VerilatedImp::exportName(funcnum) +VerilatedImp::exportName(funcnum)

View File

@ -201,16 +201,16 @@ public: // But internals only - called from VerilatedModule's
inline VerilatedSyms* symsp() const { return m_symsp; } inline VerilatedSyms* symsp() const { return m_symsp; }
VerilatedVar* varFind(const char* namep) const; VerilatedVar* varFind(const char* namep) const;
VerilatedVarNameMap* varsp() const { return m_varsp; } VerilatedVarNameMap* varsp() const { return m_varsp; }
void* exportFindError(int funcnum) const;
void* exportFindNullError(int funcnum) const;
void scopeDump() const; void scopeDump() const;
inline void* exportFind(int funcnum) const { void* exportFindError(int funcnum) const;
if (VL_UNLIKELY(!this)) return exportFindNullError(funcnum); static void* exportFindNullError(int funcnum);
if (VL_LIKELY(funcnum < m_funcnumMax)) { static inline void* exportFind(const VerilatedScope* scopep, int funcnum) {
if (VL_UNLIKELY(!scopep)) return exportFindNullError(funcnum);
if (VL_LIKELY(funcnum < scopep->m_funcnumMax)) {
// m_callbacksp must be declared, as Max'es are > 0 // m_callbacksp must be declared, as Max'es are > 0
return m_callbacksp[funcnum]; return scopep->m_callbacksp[funcnum];
} else { } else {
return exportFindError(funcnum); return scopep->exportFindError(funcnum);
} }
} }
}; };

View File

@ -674,7 +674,7 @@ private:
stmt += "const VerilatedScope* __Vscopep = Verilated::dpiScope();\n"; stmt += "const VerilatedScope* __Vscopep = Verilated::dpiScope();\n";
// If dpiScope is fails and is null; the exportFind function throws and error // If dpiScope is fails and is null; the exportFind function throws and error
string cbtype = v3Global.opt.prefix()+"__Vcb_"+nodep->cname()+"_t"; string cbtype = v3Global.opt.prefix()+"__Vcb_"+nodep->cname()+"_t";
stmt += cbtype+" __Vcb = ("+cbtype+")__Vscopep->exportFind(__Vfuncnum);\n"; stmt += cbtype+" __Vcb = ("+cbtype+")(VerilatedScope::exportFind(__Vscopep, __Vfuncnum));\n"; // Can't use static_cast
// If __Vcb is null the exportFind function throws and error // If __Vcb is null the exportFind function throws and error
dpip->addStmtsp(new AstCStmt(nodep->fileline(), stmt)); dpip->addStmtsp(new AstCStmt(nodep->fileline(), stmt));
} }