gh-103583: Add ref. dependency between multibytecodec modules (#103589)

This commit is contained in:
Erlend E. Aasland 2023-04-19 10:02:17 -06:00 committed by GitHub
parent bd2ed066c8
commit a6b07b5a34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 14 deletions

View file

@ -720,9 +720,17 @@ static struct PyMethodDef multibytecodec_methods[] = {
};
static int
multibytecodec_traverse(PyObject *self, visitproc visit, void *arg)
multibytecodec_clear(MultibyteCodecObject *self)
{
Py_CLEAR(self->cjk_module);
return 0;
}
static int
multibytecodec_traverse(MultibyteCodecObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->cjk_module);
return 0;
}
@ -731,6 +739,7 @@ multibytecodec_dealloc(MultibyteCodecObject *self)
{
PyObject_GC_UnTrack(self);
PyTypeObject *tp = Py_TYPE(self);
(void)multibytecodec_clear(self);
tp->tp_free(self);
Py_DECREF(tp);
}
@ -740,6 +749,7 @@ static PyType_Slot multibytecodec_slots[] = {
{Py_tp_getattro, PyObject_GenericGetAttr},
{Py_tp_methods, multibytecodec_methods},
{Py_tp_traverse, multibytecodec_traverse},
{Py_tp_clear, multibytecodec_clear},
{0, NULL},
};
@ -1953,14 +1963,14 @@ _multibytecodec___create_codec(PyObject *module, PyObject *arg)
/*[clinic end generated code: output=cfa3dce8260e809d input=6840b2a6b183fcfa]*/
{
MultibyteCodecObject *self;
const MultibyteCodec *codec;
if (!PyCapsule_IsValid(arg, PyMultibyteCodec_CAPSULE_NAME)) {
if (!PyCapsule_IsValid(arg, CODEC_CAPSULE)) {
PyErr_SetString(PyExc_ValueError, "argument type invalid");
return NULL;
}
codec = PyCapsule_GetPointer(arg, PyMultibyteCodec_CAPSULE_NAME);
codec_capsule *data = PyCapsule_GetPointer(arg, CODEC_CAPSULE);
const MultibyteCodec *codec = data->codec;
if (codec->codecinit != NULL && codec->codecinit(codec->config) != 0)
return NULL;
@ -1969,6 +1979,7 @@ _multibytecodec___create_codec(PyObject *module, PyObject *arg)
if (self == NULL)
return NULL;
self->codec = codec;
self->cjk_module = Py_NewRef(data->cjk_module);
PyObject_GC_Track(self);
return (PyObject *)self;