]> arthur.barton.de Git - bup.git/blob - src/bup/compat.c
Update base_version to 0.34~ for 0.34 development
[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     assert(argc > 0);
18     wchar_t **wargv = PyMem_RawMalloc(argc * sizeof(wchar_t *));
19     if (!wargv)
20         die(2, "memory insufficient to decode command line arguments");
21     int i;
22     for (i = 0; i < argc; i++) {
23         size_t wargn;
24         wargv[i] = Py_DecodeLocale(argv[i], &wargn);
25         if (!wargv[i]) {
26             switch (wargn) {
27             case (size_t) -1:
28                 die(2, "too little memory to decode command line argument %d\n",
29                     i);
30                 break;
31             case (size_t) -2:
32                 die(2, "unable to decode command line argument %d\n", i);
33                 break;
34             default:
35                 die(2, "unexpected error from Py_DecodeLocale(): %zu\n", wargn);
36                 break;
37             }
38             exit(2);
39         }
40     }
41     return Py_Main(argc, wargv);
42 }
43
44 #endif // PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 8