Skip to content

Commit

Permalink
コンストラクタが呼ばれる前に tp_traverse されることがある
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Nov 3, 2024
1 parent b8c9c34 commit de43231
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/sora_sdk_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ using namespace nb::literals;
* やっておかないと終了時にリークエラーが発生する。
*/
int audio_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) {
if (!nb::inst_ready(self)) {
return 0;
}

// インスタンスを取得する
SoraAudioSinkImpl* audio_sink = nb::inst_ptr<SoraAudioSinkImpl>(self);

Expand All @@ -51,6 +55,10 @@ int audio_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) {
}

int audio_sink_tp_clear(PyObject* self) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraAudioSinkImpl* audio_sink = nb::inst_ptr<SoraAudioSinkImpl>(self);
audio_sink->on_format_ = nullptr;
audio_sink->on_data_ = nullptr;
Expand All @@ -67,6 +75,10 @@ PyType_Slot audio_sink_slots[] = {
{0, nullptr}};

int audio_stream_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraAudioStreamSinkImpl* audio_sink =
nb::inst_ptr<SoraAudioStreamSinkImpl>(self);

Expand All @@ -79,6 +91,10 @@ int audio_stream_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) {
}

int audio_stream_sink_tp_clear(PyObject* self) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraAudioStreamSinkImpl* audio_sink =
nb::inst_ptr<SoraAudioStreamSinkImpl>(self);
audio_sink->on_frame_ = nullptr;
Expand All @@ -91,6 +107,10 @@ PyType_Slot audio_stream_sink_slots[] = {
{0, nullptr}};

int video_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraVideoSinkImpl* video_sink = nb::inst_ptr<SoraVideoSinkImpl>(self);

if (video_sink->on_frame_) {
Expand All @@ -102,6 +122,10 @@ int video_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) {
}

int video_sink_tp_clear(PyObject* self) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraVideoSinkImpl* video_sink = nb::inst_ptr<SoraVideoSinkImpl>(self);
video_sink->on_frame_ = nullptr;
return 0;
Expand All @@ -115,6 +139,10 @@ PyType_Slot video_sink_slots[] = {
int audio_frame_transformer_tp_traverse(PyObject* self,
visitproc visit,
void* arg) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraAudioFrameTransformer* audio_frame_transformer =
nb::inst_ptr<SoraAudioFrameTransformer>(self);

Expand All @@ -127,6 +155,10 @@ int audio_frame_transformer_tp_traverse(PyObject* self,
}

int audio_frame_transformer_tp_clear(PyObject* self) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraAudioFrameTransformer* audio_frame_transformer =
nb::inst_ptr<SoraAudioFrameTransformer>(self);
audio_frame_transformer->on_transform_ = nullptr;
Expand All @@ -141,6 +173,10 @@ PyType_Slot audio_frame_transformer_slots[] = {
int video_frame_transformer_tp_traverse(PyObject* self,
visitproc visit,
void* arg) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraVideoFrameTransformer* video_frame_transformer =
nb::inst_ptr<SoraVideoFrameTransformer>(self);

Expand All @@ -153,6 +189,10 @@ int video_frame_transformer_tp_traverse(PyObject* self,
}

int video_frame_transformer_tp_clear(PyObject* self) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraVideoFrameTransformer* video_frame_transformer =
nb::inst_ptr<SoraVideoFrameTransformer>(self);
video_frame_transformer->on_transform_ = nullptr;
Expand All @@ -165,6 +205,10 @@ PyType_Slot video_frame_transformer_slots[] = {
{0, nullptr}};

int connection_tp_traverse(PyObject* self, visitproc visit, void* arg) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraConnection* conn = nb::inst_ptr<SoraConnection>(self);

if (conn->on_set_offer_) {
Expand Down Expand Up @@ -221,6 +265,10 @@ int connection_tp_traverse(PyObject* self, visitproc visit, void* arg) {
}

int connection_tp_clear(PyObject* self) {
if (!nb::inst_ready(self)) {
return 0;
}

SoraConnection* conn = nb::inst_ptr<SoraConnection>(self);
conn->on_set_offer_ = nullptr;
conn->on_ws_close_ = nullptr;
Expand Down

0 comments on commit de43231

Please # to comment.