11
11
#define PY_SSIZE_T_CLEAN
12
12
#include <Python.h>
13
13
#include <isa-l.h>
14
- #include <stdio.h>
15
14
16
15
static struct PyModuleDef _isal_module = {
17
16
PyModuleDef_HEAD_INIT ,
@@ -34,19 +33,9 @@ PyInit__isal(void)
34
33
PyModule_AddIntMacro (m , ISAL_MAJOR_VERSION );
35
34
PyModule_AddIntMacro (m , ISAL_MINOR_VERSION );
36
35
PyModule_AddIntMacro (m , ISAL_PATCH_VERSION );
37
- // UINT64_MAX is 20 characters long. A version contains:
38
- // 3 numbers, 2 dots, one null byte. So the maximum size
39
- // in charcters is 3x20+2+1=63. Round up to the nearest
40
- // power of 2 is 64.
41
- char version [64 ];
42
- int length = snprintf (version , 64 , "%d.%d.%d" ,
43
- ISAL_MAJOR_VERSION , ISAL_MINOR_VERSION , ISAL_PATCH_VERSION );
44
- if (length > 64 ){
45
- // This is extremely unlikely to happen given the calculation above.
46
- PyErr_SetString (PyExc_MemoryError , "Could not allocate enough memory for ISA-L version string" );
47
- return NULL ;
48
- }
49
- PyObject * isal_version = PyUnicode_DecodeASCII (version , length , "strict" );
36
+
37
+ PyObject * isal_version = PyUnicode_FromFormat (
38
+ "%d.%d.%d" , ISAL_MAJOR_VERSION , ISAL_MINOR_VERSION , ISAL_PATCH_VERSION );
50
39
if (isal_version == NULL )
51
40
return NULL ;
52
41
PyModule_AddObject (m , "ISAL_VERSION" , isal_version );
0 commit comments