Skip to content

Commit b5d09f9

Browse files
committed
py equals
1 parent 5c4f3b4 commit b5d09f9

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

backend/Python/PyLocalReference.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,18 @@ Local<Unsupported> Local<Value>::asUnsupported() const {
178178
throw Exception("can't cast value as Unsupported");
179179
}
180180

181-
bool Local<Value>::operator==(const script::Local<script::Value>& other) const { return false; }
181+
bool Local<Value>::operator==(const script::Local<script::Value>& other) const {
182+
// TODO: nullptr vs None
183+
auto lhs = val_;
184+
auto rhs = other.val_;
185+
186+
// nullptr == nullptr
187+
if (lhs == nullptr || rhs == nullptr) {
188+
return lhs == rhs;
189+
}
190+
191+
return PyObject_RichCompareBool(lhs, rhs, Py_EQ);
192+
}
182193

183194
Local<String> Local<Value>::describe() const { TEMPLATE_NOT_IMPLEMENTED(); }
184195

backend/Python/PyScope.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
namespace script::py_backend {
2424

25-
EngineScopeImpl::EngineScopeImpl(PyEngine &, PyEngine *) { gilState_ = PyGILState_Ensure(); }
25+
EngineScopeImpl::EngineScopeImpl(PyEngine &, PyEngine *) : gilState_(PyGILState_Ensure()) {}
2626
EngineScopeImpl::~EngineScopeImpl() { PyGILState_Release(gilState_); }
2727

28-
ExitEngineScopeImpl::ExitEngineScopeImpl(PyEngine &) { threadState = PyEval_SaveThread(); }
28+
ExitEngineScopeImpl::ExitEngineScopeImpl(PyEngine &) : threadState(PyEval_SaveThread()) {}
2929
ExitEngineScopeImpl::~ExitEngineScopeImpl() { PyEval_RestoreThread(threadState); }
3030

3131
} // namespace script::py_backend

backend/Python/PyScope.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace script::py_backend {
2424
class PyEngine;
2525

2626
class EngineScopeImpl {
27-
PyGILState_STATE gilState_ = PyGILState_UNLOCKED;
27+
PyGILState_STATE gilState_;
2828

2929
public:
3030
explicit EngineScopeImpl(PyEngine &, PyEngine *);
@@ -33,7 +33,7 @@ class EngineScopeImpl {
3333
};
3434

3535
class ExitEngineScopeImpl {
36-
PyThreadState *threadState = nullptr;
36+
PyThreadState *threadState;
3737

3838
public:
3939
explicit ExitEngineScopeImpl(PyEngine &);

0 commit comments

Comments
 (0)