]> arthur.barton.de Git - bup.git/blob - src/bup/compat.c
Drop support for python 2
[bup.git] / src / bup / compat.c
1
2 #define PY_SSIZE_T_CLEAN
3 #define _GNU_SOURCE  1 // asprintf
4 #undef NDEBUG
5
6 // According to Python, its header has to go first:
7 //   http://docs.python.org/3/c-api/intro.html#include-files
8 #include <Python.h>
9
10 #include "bup/compat.h"
11 #include "bup/io.h"
12
13 #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 8
14
15 int bup_py_bytes_main(int argc, char **argv)
16 {
17     wchar_t **wargv = PyMem_RawMalloc(argc * sizeof(wchar_t *));
18     if (!wargv)
19         die(2, "memory insufficient to decode command line arguments");
20     int i;
21     for (i = 0; i < argc; i++) {
22         size_t wargn;
23         wargv[i] = Py_DecodeLocale(argv[i], &wargn);
24         if (!wargv[i]) {
25             switch (wargn) {
26             case (size_t) -1:
27                 die(2, "too little memory to decode command line argument %d\n",
28                     i);
29                 break;
30             case (size_t) -2:
31                 die(2, "unable to decode command line argument %d\n", i);
32                 break;
33             default:
34                 die(2, "unexpected error from Py_DecodeLocale(): %zu\n", wargn);
35                 break;
36             }
37             exit(2);
38         }
39     }
40     return Py_Main(argc, wargv);
41 }
42
43 #endif // PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 8