Skip to content

Commit

Permalink
Drop support for Python 2.7
Browse files Browse the repository at this point in the history
The ship has long sailed, and while we could even restrict Python
version support further, the module itself uses few and stable function
calls that haven't changed throughout the Python 3 series.

Signed-off-by: Rodrigo Tobar <[email protected]>
  • Loading branch information
rtobar committed Aug 7, 2024
1 parent f1e12a5 commit 8dcc2e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
for clarity, and to avoid potential warnings (#46).
* Run test against different memory alignments.
* Mention explicit support for Python 3.13.
* Drop support for Python 2.7.

## [2.4.1]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"Operating System :: OS Independent",
"Programming Language :: C",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
Expand Down Expand Up @@ -67,6 +66,7 @@
classifiers=classifiers,
packages=['crc32c'],
package_dir={'': 'src'},
python_requires=">=3.2",
include_package_data=True,
ext_modules=[crcmod_ext],
test_suite="test")
34 changes: 8 additions & 26 deletions src/crc32c/ext/_crc32c.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ PyObject* crc32c_crc32c(PyObject *self, PyObject *args, PyObject *kwargs) {
static char *kwlist[] = {"data", "value", "gil_release_mode", NULL};

/* In python 3 we accept only bytes-like objects */
const char *format =
#if PY_MAJOR_VERSION >= 3
"y*"
#else
"s*"
#endif
"|Ii:crc32";
const char *format ="y*|Ii:crc32";

if (!PyArg_ParseTupleAndKeywords(args, kwargs, format, kwlist, &pbin, &crc, &gil_release_mode) )
return NULL;
Expand Down Expand Up @@ -133,21 +127,9 @@ static const char *import_error_msg = "\n\n"
" * 'force': use software implementation regardless of hardware support.\n"
" * 'none': fail if no hardware support is found (this error).\n";

/* Support for Python 2/3 */
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT, "_crc32c", "crc32c implementation in hardware and software", -1, CRC32CMethods};
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
#define MOD_DEF(m, name, doc, methods) \
m = PyModule_Create(&moduledef);
#define MOD_VAL(v) v
#else
#define MOD_INIT(name) PyMODINIT_FUNC init##name(void)
#define MOD_DEF(m, name, doc, methods) \
m = Py_InitModule3(name, methods, doc);
#define MOD_VAL(v)
#endif

MOD_INIT(_crc32c)
PyMODINIT_FUNC PyInit__crc32c(void)
{
PyObject *m;
PyObject *hardware_based;
Expand Down Expand Up @@ -178,21 +160,21 @@ MOD_INIT(_crc32c)
}
else if (sw_mode == NONE) {
PyErr_SetString(PyExc_ImportError, import_error_msg);
return MOD_VAL(NULL);
return NULL;
}

is_big_endian = (*(const char *)(&n) == 0);

MOD_DEF(m, "_crc32c", "crc32c implementation in hardware and software", CRC32CMethods);
m = PyModule_Create(&moduledef);
if (m == NULL) {
return MOD_VAL(NULL);
return NULL;
}
Py_INCREF(hardware_based);
if (PyModule_AddObject(m, "hardware_based", hardware_based) < 0) {
return MOD_VAL(NULL);
return NULL;
}
if (PyModule_AddIntConstant(m, "big_endian", is_big_endian) < 0) {
return MOD_VAL(NULL);
return NULL;
}
return MOD_VAL(m);
return m;
}

0 comments on commit 8dcc2e8

Please sign in to comment.