forked from pyinstaller/pyinstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyi_python.c
160 lines (140 loc) · 4.29 KB
/
pyi_python.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* ****************************************************************************
* Copyright (c) 2013-2020, PyInstaller Development Team.
*
* Distributed under the terms of the GNU General Public License (version 2
* or later) with exception for distributing the bootloader.
*
* The full license is in the file COPYING.txt, distributed with this software.
*
* SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
* ****************************************************************************
*/
/*
* Python.h replacements.
*/
#ifdef _WIN32
#include <windows.h> /* HMODULE */
#include <winsock.h> /* ntohl */
#else
#include <dlfcn.h> /* dlsym */
#endif
#include <stddef.h> /* ptrdiff_t */
#include <stdlib.h>
/* PyInstaller headers. */
#include "pyi_global.h"
#include "pyi_python.h"
/*
* Python Entry point declarations (see macros in pyi_python.h).
*/
/* external variables */
DECLVAR(Py_DontWriteBytecodeFlag);
DECLVAR(Py_FileSystemDefaultEncoding);
DECLVAR(Py_FrozenFlag);
DECLVAR(Py_IgnoreEnvironmentFlag);
DECLVAR(Py_NoSiteFlag);
DECLVAR(Py_NoUserSiteDirectory);
DECLVAR(Py_OptimizeFlag);
DECLVAR(Py_VerboseFlag);
/* functions with prefix `Py_` */
DECLPROC(Py_BuildValue);
DECLPROC(Py_DecRef);
DECLPROC(Py_Finalize);
DECLPROC(Py_IncRef);
DECLPROC(Py_Initialize);
DECLPROC(Py_SetPath);
DECLPROC(Py_GetPath);
DECLPROC(Py_SetProgramName);
DECLPROC(Py_SetPythonHome);
/* other functions */
DECLPROC(PyDict_GetItemString);
DECLPROC(PyErr_Clear);
DECLPROC(PyErr_Occurred);
DECLPROC(PyErr_Print);
DECLPROC(PyErr_Fetch);
DECLPROC(PyImport_AddModule);
DECLPROC(PyImport_ExecCodeModule);
DECLPROC(PyImport_ImportModule);
DECLPROC(PyList_Append);
DECLPROC(PyList_New);
DECLPROC(PyLong_AsLong);
DECLPROC(PyModule_GetDict);
DECLPROC(PyObject_CallFunction);
DECLPROC(PyObject_CallFunctionObjArgs);
DECLPROC(PyObject_SetAttrString);
DECLPROC(PyObject_GetAttrString);
DECLPROC(PyObject_Str);
DECLPROC(PyRun_SimpleString);
DECLPROC(PySys_AddWarnOption);
DECLPROC(PySys_SetArgvEx);
DECLPROC(PySys_GetObject);
DECLPROC(PySys_SetObject);
DECLPROC(PySys_SetPath);
DECLPROC(PyUnicode_FromString);
DECLPROC(Py_DecodeLocale);
DECLPROC(PyUnicode_FromFormat);
DECLPROC(PyUnicode_DecodeFSDefault);
DECLPROC(PyUnicode_Decode);
DECLPROC(PyUnicode_AsUTF8);
DECLPROC(PyEval_EvalCode);
DECLPROC(PyMarshal_ReadObjectFromString);
/*
* Get all of the entry points from libpython
* that we are interested in.
*/
int
pyi_python_map_names(HMODULE dll, int pyvers)
{
GETVAR(dll, Py_DontWriteBytecodeFlag);
GETVAR(dll, Py_FileSystemDefaultEncoding);
GETVAR(dll, Py_FrozenFlag);
GETVAR(dll, Py_IgnoreEnvironmentFlag);
GETVAR(dll, Py_NoSiteFlag);
GETVAR(dll, Py_NoUserSiteDirectory);
GETVAR(dll, Py_OptimizeFlag);
GETVAR(dll, Py_VerboseFlag);
/* functions with prefix `Py_` */
GETPROC(dll, Py_BuildValue);
GETPROC(dll, Py_DecRef);
GETPROC(dll, Py_Finalize);
GETPROC(dll, Py_IncRef);
GETPROC(dll, Py_Initialize);
GETPROC(dll, Py_SetPath);
GETPROC(dll, Py_GetPath);
GETPROC(dll, Py_SetProgramName);
GETPROC(dll, Py_SetPythonHome);
/* other functions */
GETPROC(dll, PyDict_GetItemString);
GETPROC(dll, PyErr_Clear);
GETPROC(dll, PyErr_Occurred);
GETPROC(dll, PyErr_Print);
GETPROC(dll, PyErr_Fetch);
GETPROC(dll, PyImport_AddModule);
GETPROC(dll, PyImport_ExecCodeModule);
GETPROC(dll, PyImport_ImportModule);
GETPROC(dll, PyList_Append);
GETPROC(dll, PyList_New);
GETPROC(dll, PyLong_AsLong);
GETPROC(dll, PyModule_GetDict);
GETPROC(dll, PyObject_CallFunction);
GETPROC(dll, PyObject_CallFunctionObjArgs);
GETPROC(dll, PyObject_SetAttrString);
GETPROC(dll, PyObject_GetAttrString);
GETPROC(dll, PyObject_Str);
GETPROC(dll, PyRun_SimpleString);
GETPROC(dll, PySys_AddWarnOption);
GETPROC(dll, PySys_SetArgvEx);
GETPROC(dll, PySys_GetObject);
GETPROC(dll, PySys_SetObject);
GETPROC(dll, PySys_SetPath);
GETPROC(dll, PyEval_EvalCode);
GETPROC(dll, PyMarshal_ReadObjectFromString);
GETPROC(dll, PyUnicode_FromString);
GETPROC(dll, Py_DecodeLocale);
GETPROC(dll, PyUnicode_FromFormat);
GETPROC(dll, PyUnicode_Decode);
GETPROC(dll, PyUnicode_DecodeFSDefault);
GETPROC(dll, PyUnicode_AsUTF8);
VS("LOADER: Loaded functions from Python library.\n");
return 0;
}