Skip to content

Commit

Permalink
Turn crc32c module into a package
Browse files Browse the repository at this point in the history
The package's __init__ module exposes the same objects that the module
does, so this change is fully backwards compatible in terms of the
import logic used by the users. However, it has a few advantages over
the previous implementation:

 * It allows us to organise our source code better
 * It opens the door to adding typing stub files for our C extension
 * Opens the door for providing other modules (C or Python) alongside
   what we currently provide

Signed-off-by: Rodrigo Tobar <[email protected]>
  • Loading branch information
rtobar committed Aug 6, 2024
1 parent 5db7c19 commit 9deaac5
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Release GIL during the computation of the CRC32C hash. A new `gil_release_mode` argument lets users choose between always/never/automatically releasing it (#47).
* Add keyword support to `crc32c` function (`crc32c(data, value=0, gil_release_mode=-1)`).
* Turned ``crc32c`` from a module-only distribution into a package.
* Adding explicit fallthrough annotations
in several ``switch`` C statements
for clarity, and to avoid potential warnings (#46).
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include *.h
include LICENSE*
include AUTHORS*
include crc32c/ext/*.h
1 change: 1 addition & 0 deletions crc32c/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._crc32c import big_endian, crc32, crc32c, hardware_based
6 changes: 3 additions & 3 deletions _crc32c.c → crc32c/ext/_crc32c.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static const char *import_error_msg = "\n\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};
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);
Expand All @@ -147,7 +147,7 @@ static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT, "crc32c", "crc32c
#define MOD_VAL(v)
#endif

MOD_INIT(crc32c)
MOD_INIT(_crc32c)
{
PyObject *m;
PyObject *hardware_based;
Expand Down Expand Up @@ -183,7 +183,7 @@ MOD_INIT(crc32c)

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

MOD_DEF(m, "crc32c", "crc32c implementation in hardware and software", CRC32CMethods);
MOD_DEF(m, "_crc32c", "crc32c implementation in hardware and software", CRC32CMethods);
if (m == NULL) {
return MOD_VAL(NULL);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
from setuptools.command.build_ext import build_ext


crcmod_ext = Extension('crc32c',
crcmod_ext = Extension('crc32c._crc32c',
define_macros=[('NDEBUG', None)],
depends=glob.glob('*.h'),
depends=glob.glob('crc32c/ext/*.h'),
language='c',
sources=['_crc32c.c', 'checkarm.c', 'checksse42.c', 'crc32c_adler.c', 'crc32c_arm64.c', 'crc32c_sw.c'],
include_dirs=['.'])
sources=glob.glob('crc32c/ext/*.c'),
include_dirs=['cc32c/ext/'])

classifiers = [
# There's no more specific classifier for LGPLv2.1+
Expand All @@ -59,6 +59,7 @@

setup(name='crc32c',
author='The ICRAR DIA Team',
packages=['crc32c'],
url='https://github.com/ICRAR/crc32c',
author_email='[email protected]',
version='2.4.1',
Expand Down

0 comments on commit 9deaac5

Please sign in to comment.