Skip to content

Commit

Permalink
py equals
Browse files Browse the repository at this point in the history
  • Loading branch information
LanderlYoung committed Feb 8, 2024
1 parent 5c4f3b4 commit b5d09f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion backend/Python/PyLocalReference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,18 @@ Local<Unsupported> Local<Value>::asUnsupported() const {
throw Exception("can't cast value as Unsupported");
}

bool Local<Value>::operator==(const script::Local<script::Value>& other) const { return false; }
bool Local<Value>::operator==(const script::Local<script::Value>& other) const {
// TODO: nullptr vs None
auto lhs = val_;
auto rhs = other.val_;

// nullptr == nullptr
if (lhs == nullptr || rhs == nullptr) {
return lhs == rhs;
}

return PyObject_RichCompareBool(lhs, rhs, Py_EQ);
}

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

Expand Down
4 changes: 2 additions & 2 deletions backend/Python/PyScope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

namespace script::py_backend {

EngineScopeImpl::EngineScopeImpl(PyEngine &, PyEngine *) { gilState_ = PyGILState_Ensure(); }
EngineScopeImpl::EngineScopeImpl(PyEngine &, PyEngine *) : gilState_(PyGILState_Ensure()) {}
EngineScopeImpl::~EngineScopeImpl() { PyGILState_Release(gilState_); }

ExitEngineScopeImpl::ExitEngineScopeImpl(PyEngine &) { threadState = PyEval_SaveThread(); }
ExitEngineScopeImpl::ExitEngineScopeImpl(PyEngine &) : threadState(PyEval_SaveThread()) {}
ExitEngineScopeImpl::~ExitEngineScopeImpl() { PyEval_RestoreThread(threadState); }

} // namespace script::py_backend
4 changes: 2 additions & 2 deletions backend/Python/PyScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace script::py_backend {
class PyEngine;

class EngineScopeImpl {
PyGILState_STATE gilState_ = PyGILState_UNLOCKED;
PyGILState_STATE gilState_;

public:
explicit EngineScopeImpl(PyEngine &, PyEngine *);
Expand All @@ -33,7 +33,7 @@ class EngineScopeImpl {
};

class ExitEngineScopeImpl {
PyThreadState *threadState = nullptr;
PyThreadState *threadState;

public:
explicit ExitEngineScopeImpl(PyEngine &);
Expand Down

0 comments on commit b5d09f9

Please sign in to comment.