Skip to content

Commit

Permalink
Consistent dictionary check for unpickle
Browse files Browse the repository at this point in the history
  • Loading branch information
mtheall committed Jun 3, 2024
1 parent cf515bd commit c13d897
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 2 deletions.
6 changes: 6 additions & 0 deletions python-mtheall/Angle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ PyObject *Angle::Pickle (Angle *self_) noexcept

PyObject *Angle::Unpickle (Angle *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion python-mtheall/Arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ PyObject *Arena::Pickle (Arena *self_) noexcept

PyObject *Arena::Unpickle (Arena *self_, PyObject *dict_) noexcept
{
if (!Py_IS_TYPE (dict_, &PyDict_Type))
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/ArenaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ PyObject *ArenaConfig::Pickle (ArenaConfig *self_) noexcept

PyObject *ArenaConfig::Unpickle (ArenaConfig *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/BallHitInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ PyObject *BallHitInfo::Pickle (BallHitInfo *self_) noexcept

PyObject *BallHitInfo::Unpickle (BallHitInfo *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion python-mtheall/BallPredictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ PyObject *BallPredictor::Pickle (BallPredictor *self_) noexcept

PyObject *BallPredictor::Unpickle (BallPredictor *self_, PyObject *dict_) noexcept
{
if (!Py_IS_TYPE (dict_, &PyDict_Type))
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/BallState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ PyObject *BallState::Pickle (BallState *self_) noexcept

PyObject *BallState::Unpickle (BallState *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/BoostPadState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ PyObject *BoostPadState::Pickle (BoostPadState *self_) noexcept

PyObject *BoostPadState::Unpickle (BoostPadState *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/Car.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ PyObject *Car::InternalPickle (Car *self_) noexcept

PyObject *Car::InternalUnpickle (std::shared_ptr<RocketSim::Arena> arena_, Car *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const dummy = PyObjectRef::steal (PyTuple_New (0));
if (!dummy)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/CarConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ PyObject *CarConfig::Pickle (CarConfig *self_) noexcept

PyObject *CarConfig::Unpickle (CarConfig *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/CarControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ PyObject *CarControls::Pickle (CarControls *self_) noexcept

PyObject *CarControls::Unpickle (CarControls *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/CarState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,12 @@ PyObject *CarState::Pickle (CarState *self_) noexcept

PyObject *CarState::Unpickle (CarState *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/MutatorConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,12 @@ PyObject *MutatorConfig::Pickle (MutatorConfig *self_) noexcept

PyObject *MutatorConfig::Unpickle (MutatorConfig *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/RotMat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ PyObject *RotMat::Pickle (RotMat *self_) noexcept

PyObject *RotMat::Unpickle (RotMat *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/Vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ PyObject *Vec::Pickle (Vec *self_) noexcept

PyObject *Vec::Unpickle (Vec *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions python-mtheall/WheelPairConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ PyObject *WheelPairConfig::Pickle (WheelPairConfig *self_) noexcept

PyObject *WheelPairConfig::Unpickle (WheelPairConfig *self_, PyObject *dict_) noexcept
{
if (!PyDict_Check (dict_))
{
PyErr_SetString (PyExc_ValueError, "Pickled object is not a dict");
return nullptr;
}

auto const args = PyObjectRef::steal (PyTuple_New (0));
if (!args)
return nullptr;
Expand Down

0 comments on commit c13d897

Please sign in to comment.