Skip to content

Commit

Permalink
Add Python 3.10 support
Browse files Browse the repository at this point in the history
* Replace "Py_TYPE(obj) = type;" with "Py_SET_TYPE(obj, type);"
* Add pythoncapi_compat.h header file to get Py_SET_TYPE() on Python
  2.7-3.8. Header file added to c-ext/.

In Python 3.10, Py_TYPE(obj) must not longer be used as an l-value.

pythoncapi_compat.h comes from:
https://github.com/pythoncapi/pythoncapi_compat
  • Loading branch information
vstinner authored and indygreg committed Dec 24, 2020
1 parent 89c3a37 commit e5a3baf
Show file tree
Hide file tree
Showing 17 changed files with 301 additions and 20 deletions.
8 changes: 4 additions & 4 deletions c-ext/bufferutil.c
Expand Up @@ -668,31 +668,31 @@ PyTypeObject ZstdBufferWithSegmentsCollectionType = {
};

void bufferutil_module_init(PyObject* mod) {
Py_TYPE(&ZstdBufferWithSegmentsType) = &PyType_Type;
Py_SET_TYPE(&ZstdBufferWithSegmentsType, &PyType_Type);
if (PyType_Ready(&ZstdBufferWithSegmentsType) < 0) {
return;
}

Py_INCREF(&ZstdBufferWithSegmentsType);
PyModule_AddObject(mod, "BufferWithSegments", (PyObject*)&ZstdBufferWithSegmentsType);

Py_TYPE(&ZstdBufferSegmentsType) = &PyType_Type;
Py_SET_TYPE(&ZstdBufferSegmentsType, &PyType_Type);
if (PyType_Ready(&ZstdBufferSegmentsType) < 0) {
return;
}

Py_INCREF(&ZstdBufferSegmentsType);
PyModule_AddObject(mod, "BufferSegments", (PyObject*)&ZstdBufferSegmentsType);

Py_TYPE(&ZstdBufferSegmentType) = &PyType_Type;
Py_SET_TYPE(&ZstdBufferSegmentType, &PyType_Type);
if (PyType_Ready(&ZstdBufferSegmentType) < 0) {
return;
}

Py_INCREF(&ZstdBufferSegmentType);
PyModule_AddObject(mod, "BufferSegment", (PyObject*)&ZstdBufferSegmentType);

Py_TYPE(&ZstdBufferWithSegmentsCollectionType) = &PyType_Type;
Py_SET_TYPE(&ZstdBufferWithSegmentsCollectionType, &PyType_Type);
if (PyType_Ready(&ZstdBufferWithSegmentsCollectionType) < 0) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions c-ext/compressionchunker.c
Expand Up @@ -344,12 +344,12 @@ PyTypeObject ZstdCompressionChunkerType = {
};

void compressionchunker_module_init(PyObject* module) {
Py_TYPE(&ZstdCompressionChunkerIteratorType) = &PyType_Type;
Py_SET_TYPE(&ZstdCompressionChunkerIteratorType, &PyType_Type);
if (PyType_Ready(&ZstdCompressionChunkerIteratorType) < 0) {
return;
}

Py_TYPE(&ZstdCompressionChunkerType) = &PyType_Type;
Py_SET_TYPE(&ZstdCompressionChunkerType, &PyType_Type);
if (PyType_Ready(&ZstdCompressionChunkerType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/compressiondict.c
Expand Up @@ -400,7 +400,7 @@ PyTypeObject ZstdCompressionDictType = {
};

void compressiondict_module_init(PyObject* mod) {
Py_TYPE(&ZstdCompressionDictType) = &PyType_Type;
Py_SET_TYPE(&ZstdCompressionDictType, &PyType_Type);
if (PyType_Ready(&ZstdCompressionDictType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/compressionparams.c
Expand Up @@ -548,7 +548,7 @@ PyTypeObject ZstdCompressionParametersType = {
};

void compressionparams_module_init(PyObject* mod) {
Py_TYPE(&ZstdCompressionParametersType) = &PyType_Type;
Py_SET_TYPE(&ZstdCompressionParametersType, &PyType_Type);
if (PyType_Ready(&ZstdCompressionParametersType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/compressionreader.c
Expand Up @@ -811,7 +811,7 @@ PyTypeObject ZstdCompressionReaderType = {
void compressionreader_module_init(PyObject* mod) {
/* TODO make reader a sub-class of io.RawIOBase */

Py_TYPE(&ZstdCompressionReaderType) = &PyType_Type;
Py_SET_TYPE(&ZstdCompressionReaderType, &PyType_Type);
if (PyType_Ready(&ZstdCompressionReaderType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/compressionwriter.c
Expand Up @@ -353,7 +353,7 @@ PyTypeObject ZstdCompressionWriterType = {
};

void compressionwriter_module_init(PyObject* mod) {
Py_TYPE(&ZstdCompressionWriterType) = &PyType_Type;
Py_SET_TYPE(&ZstdCompressionWriterType, &PyType_Type);
if (PyType_Ready(&ZstdCompressionWriterType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/compressobj.c
Expand Up @@ -245,7 +245,7 @@ PyTypeObject ZstdCompressionObjType = {
};

void compressobj_module_init(PyObject* module) {
Py_TYPE(&ZstdCompressionObjType) = &PyType_Type;
Py_SET_TYPE(&ZstdCompressionObjType, &PyType_Type);
if (PyType_Ready(&ZstdCompressionObjType) < 0) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions c-ext/compressor.c
Expand Up @@ -610,7 +610,7 @@ static PyObject* ZstdCompressor_compress(ZstdCompressor* self, PyObject* args, P
goto finally;
}

Py_SIZE(output) = outBuffer.pos;
Py_SET_SIZE(output, outBuffer.pos);

finally:
PyBuffer_Release(&source);
Expand Down Expand Up @@ -1653,7 +1653,7 @@ PyTypeObject ZstdCompressorType = {
};

void compressor_module_init(PyObject* mod) {
Py_TYPE(&ZstdCompressorType) = &PyType_Type;
Py_SET_TYPE(&ZstdCompressorType, &PyType_Type);
if (PyType_Ready(&ZstdCompressorType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/compressoriterator.c
Expand Up @@ -228,7 +228,7 @@ PyTypeObject ZstdCompressorIteratorType = {
};

void compressoriterator_module_init(PyObject* mod) {
Py_TYPE(&ZstdCompressorIteratorType) = &PyType_Type;
Py_SET_TYPE(&ZstdCompressorIteratorType, &PyType_Type);
if (PyType_Ready(&ZstdCompressorIteratorType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/decompressionreader.c
Expand Up @@ -774,7 +774,7 @@ PyTypeObject ZstdDecompressionReaderType = {
void decompressionreader_module_init(PyObject* mod) {
/* TODO make reader a sub-class of io.RawIOBase */

Py_TYPE(&ZstdDecompressionReaderType) = &PyType_Type;
Py_SET_TYPE(&ZstdDecompressionReaderType, &PyType_Type);
if (PyType_Ready(&ZstdDecompressionReaderType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/decompressionwriter.c
Expand Up @@ -280,7 +280,7 @@ PyTypeObject ZstdDecompressionWriterType = {
};

void decompressionwriter_module_init(PyObject* mod) {
Py_TYPE(&ZstdDecompressionWriterType) = &PyType_Type;
Py_SET_TYPE(&ZstdDecompressionWriterType, &PyType_Type);
if (PyType_Ready(&ZstdDecompressionWriterType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/decompressobj.c
Expand Up @@ -191,7 +191,7 @@ PyTypeObject ZstdDecompressionObjType = {
};

void decompressobj_module_init(PyObject* module) {
Py_TYPE(&ZstdDecompressionObjType) = &PyType_Type;
Py_SET_TYPE(&ZstdDecompressionObjType, &PyType_Type);
if (PyType_Ready(&ZstdDecompressionObjType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/decompressor.c
Expand Up @@ -1805,7 +1805,7 @@ PyTypeObject ZstdDecompressorType = {
};

void decompressor_module_init(PyObject* mod) {
Py_TYPE(&ZstdDecompressorType) = &PyType_Type;
Py_SET_TYPE(&ZstdDecompressorType, &PyType_Type);
if (PyType_Ready(&ZstdDecompressorType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/decompressoriterator.c
Expand Up @@ -242,7 +242,7 @@ PyTypeObject ZstdDecompressorIteratorType = {
};

void decompressoriterator_module_init(PyObject* mod) {
Py_TYPE(&ZstdDecompressorIteratorType) = &PyType_Type;
Py_SET_TYPE(&ZstdDecompressorIteratorType, &PyType_Type);
if (PyType_Ready(&ZstdDecompressorIteratorType) < 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion c-ext/frameparams.c
Expand Up @@ -124,7 +124,7 @@ PyTypeObject FrameParametersType = {
};

void frameparams_module_init(PyObject* mod) {
Py_TYPE(&FrameParametersType) = &PyType_Type;
Py_SET_TYPE(&FrameParametersType, &PyType_Type);
if (PyType_Ready(&FrameParametersType) < 0) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions c-ext/python-zstandard.h
Expand Up @@ -12,6 +12,7 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "structmember.h"
#include <pythoncapi_compat.h>

#define ZSTD_STATIC_LINKING_ONLY
#define ZDICT_STATIC_LINKING_ONLY
Expand Down

0 comments on commit e5a3baf

Please sign in to comment.