cython

Форк
0
69 строк · 1.7 Кб
1
/* embedded_main.c */
2

3
/* This include file is automatically generated by Cython for 'public' functions. */
4
#include "embedded.h"
5

6
#ifdef __cplusplus
7
extern "C" {
8
#endif
9

10
int
11
main(int argc, char *argv[])
12
{
13
    PyObject *pmodule;
14
    wchar_t *program;
15

16
    program = Py_DecodeLocale(argv[0], NULL);
17
    if (program == NULL) {
18
        fprintf(stderr, "Fatal error: cannot decode argv[0], got %d arguments\n", argc);
19
        exit(1);
20
    }
21

22
    /* Add a built-in module, before Py_Initialize */
23
    if (PyImport_AppendInittab("embedded", PyInit_embedded) == -1) {
24
        fprintf(stderr, "Error: could not extend in-built modules table\n");
25
        exit(1);
26
    }
27

28
    /* Pass argv[0] to the Python interpreter */
29
    Py_SetProgramName(program);
30

31
    /* Initialize the Python interpreter.  Required.
32
       If this step fails, it will be a fatal error. */
33
    Py_Initialize();
34

35
    /* Optionally import the module; alternatively,
36
       import can be deferred until the embedded script
37
       imports it. */
38
    pmodule = PyImport_ImportModule("embedded");
39
    if (!pmodule) {
40
        PyErr_Print();
41
        fprintf(stderr, "Error: could not import module 'embedded'\n");
42
        goto exit_with_error;
43
    }
44

45
    /* Now call into your module code. */
46
    if (say_hello_from_python() < 0) {
47
        PyErr_Print();
48
        fprintf(stderr, "Error in Python code, exception was printed.\n");
49
        goto exit_with_error;
50
    }
51

52
    /* ... */
53

54
    /* Clean up after using CPython. */
55
    PyMem_RawFree(program);
56
    Py_Finalize();
57

58
    return 0;
59

60
    /* Clean up in the error cases above. */
61
exit_with_error:
62
    PyMem_RawFree(program);
63
    Py_Finalize();
64
    return 1;
65
}
66

67
#ifdef __cplusplus
68
}
69
#endif
70

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.