forked from JonathanPenner3D/PythonKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonLibrary+Symbols.swift
More file actions
298 lines (225 loc) · 11.1 KB
/
Copy pathPythonLibrary+Symbols.swift
File metadata and controls
298 lines (225 loc) · 11.1 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
//===-- PythonLibrary+Symbols.swift ---------------------------*- swift -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines the Python symbols required for the interoperability layer.
//
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// Required Python typealiases and constants.
//===----------------------------------------------------------------------===//
@usableFromInline
typealias PyObjectPointer = UnsafeMutableRawPointer
typealias PyMethodDefPointer = UnsafeMutableRawPointer
typealias PyCCharPointer = UnsafePointer<Int8>
typealias PyBinaryOperation =
@convention(c) (PyObjectPointer?, PyObjectPointer?) -> PyObjectPointer?
typealias PyUnaryOperation =
@convention(c) (PyObjectPointer?) -> PyObjectPointer?
let Py_LT: Int32 = 0
let Py_LE: Int32 = 1
let Py_EQ: Int32 = 2
let Py_NE: Int32 = 3
let Py_GT: Int32 = 4
let Py_GE: Int32 = 5
//===----------------------------------------------------------------------===//
// Python library symbols lazily loaded at runtime.
//===----------------------------------------------------------------------===//
let Py_Initialize: @convention(c) () -> Void =
PythonLibrary.loadSymbol(name: "Py_Initialize")
let PyGILState_Ensure: @convention(c) () -> UnsafeMutableRawPointer? =
PythonLibrary.loadSymbol(name: "PyGILState_Ensure")
let PyGILState_Release: @convention(c) (UnsafeMutableRawPointer?) -> Void =
PythonLibrary.loadSymbol(name: "PyGILState_Release")
let Py_IncRef: @convention(c) (PyObjectPointer?) -> Void =
PythonLibrary.loadSymbol(name: "Py_IncRef")
let Py_DecRef: @convention(c) (PyObjectPointer?) -> Void =
PythonLibrary.loadSymbol(name: "Py_DecRef")
let PyImport_ImportModule: @convention(c) (
PyCCharPointer) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyImport_ImportModule")
let PyEval_GetBuiltins: @convention(c) () -> PyObjectPointer =
PythonLibrary.loadSymbol(name: "PyEval_GetBuiltins")
let PyRun_SimpleString: @convention(c) (PyCCharPointer) -> Void =
PythonLibrary.loadSymbol(name: "PyRun_SimpleString")
let PyCFunction_NewEx: @convention(c) (PyMethodDefPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer?) -> PyObjectPointer =
PythonLibrary.loadSymbol(name: "PyCFunction_NewEx")
let PyInstanceMethod_New: @convention(c) (PyObjectPointer) -> PyObjectPointer =
PythonLibrary.loadSymbol(name: "PyInstanceMethod_New")
/// The last argument would ideally be of type `@convention(c) (PyObjectPointer?) -> Void`.
/// Due to SR-15871 and the source-breaking nature of potential workarounds, the
/// static typing was removed. The caller must now manually cast a closure to
/// `OpaquePointer` before passing it into `PyCapsule_New`.
let PyCapsule_New: @convention(c) (
UnsafeMutableRawPointer, UnsafePointer<CChar>?,
OpaquePointer) -> PyObjectPointer =
PythonLibrary.loadSymbol(name: "PyCapsule_New")
let PyCapsule_GetPointer: @convention(c) (PyObjectPointer?, UnsafePointer<CChar>?) -> UnsafeMutableRawPointer =
PythonLibrary.loadSymbol(name: "PyCapsule_GetPointer")
let PyErr_SetString: @convention(c) (PyObjectPointer, UnsafePointer<CChar>?) -> Void =
PythonLibrary.loadSymbol(name: "PyErr_SetString")
let PyErr_Occurred: @convention(c) () -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyErr_Occurred")
let PyErr_Clear: @convention(c) () -> Void =
PythonLibrary.loadSymbol(name: "PyErr_Clear")
let PyErr_Fetch: @convention(c) (
UnsafeMutablePointer<PyObjectPointer?>,
UnsafeMutablePointer<PyObjectPointer?>,
UnsafeMutablePointer<PyObjectPointer?>) -> Void =
PythonLibrary.loadSymbol(name: "PyErr_Fetch")
let PyDict_New: @convention(c) () -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyDict_New")
let PyDict_Contains: @convention(c) (
PyObjectPointer?, PyObjectPointer?) -> Int32 =
PythonLibrary.loadSymbol(name: "PyDict_Contains")
let PyDict_SetItem: @convention(c) (
PyObjectPointer?, PyObjectPointer, PyObjectPointer) -> Void =
PythonLibrary.loadSymbol(name: "PyDict_SetItem")
let PyObject_GetItem: @convention(c) (
PyObjectPointer, PyObjectPointer) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyObject_GetItem")
let PyObject_SetItem: @convention(c) (
PyObjectPointer, PyObjectPointer, PyObjectPointer) -> Void =
PythonLibrary.loadSymbol(name: "PyObject_SetItem")
let PyObject_DelItem: @convention(c) (
PyObjectPointer, PyObjectPointer) -> Void =
PythonLibrary.loadSymbol(name: "PyObject_DelItem")
let PyObject_Call: @convention(c) (
PyObjectPointer, PyObjectPointer,
PyObjectPointer?) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyObject_Call")
let PyObject_CallObject: @convention(c) (
PyObjectPointer, PyObjectPointer) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyObject_CallObject")
let PyObject_GetAttrString: @convention(c) (
PyObjectPointer, PyCCharPointer) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyObject_GetAttrString")
let PyObject_SetAttrString: @convention(c) (
PyObjectPointer, PyCCharPointer, PyObjectPointer) -> Int32 =
PythonLibrary.loadSymbol(name: "PyObject_SetAttrString")
let PySlice_New: @convention(c) (
PyObjectPointer?, PyObjectPointer?,
PyObjectPointer?) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PySlice_New")
let Py_BuildValue: @convention(c) (UnsafeRawPointer) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "Py_BuildValue")
let PySequence_Check: @convention(c) (UnsafeRawPointer) -> Int =
PythonLibrary.loadSymbol(name: "PySequence_Check")
let PyTuple_New: @convention(c) (Int) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyTuple_New")
let PyTuple_SetItem: @convention(c) (
PyObjectPointer, Int, PyObjectPointer) -> Void =
PythonLibrary.loadSymbol(name: "PyTuple_SetItem")
let PyObject_RichCompare: @convention(c) (
PyObjectPointer, PyObjectPointer, Int32) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyObject_RichCompare")
let PyObject_RichCompareBool: @convention(c) (
PyObjectPointer, PyObjectPointer, Int32) -> Int32 =
PythonLibrary.loadSymbol(name: "PyObject_RichCompareBool")
let PyDict_Next: @convention(c) (
PyObjectPointer, UnsafeMutablePointer<Int>,
UnsafeMutablePointer<PyObjectPointer?>,
UnsafeMutablePointer<PyObjectPointer?>) -> Int32 =
PythonLibrary.loadSymbol(name: "PyDict_Next")
let PyIter_Next: @convention(c) (
PyObjectPointer) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyIter_Next")
let PyObject_GetIter: @convention(c) (
PyObjectPointer) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyObject_GetIter")
let PyList_New: @convention(c) (Int) -> PyObjectPointer? =
PythonLibrary.loadSymbol(name: "PyList_New")
let PyList_SetItem: @convention(c) (
PyObjectPointer, Int, PyObjectPointer) -> Int32 =
PythonLibrary.loadSymbol(name: "PyList_SetItem")
let PyBool_FromLong: @convention(c) (Int) -> PyObjectPointer =
PythonLibrary.loadSymbol(name: "PyBool_FromLong")
let PyFloat_AsDouble: @convention(c) (PyObjectPointer) -> Double =
PythonLibrary.loadSymbol(name: "PyFloat_AsDouble")
let PyFloat_FromDouble: @convention(c) (Double) -> PyObjectPointer =
PythonLibrary.loadSymbol(name: "PyFloat_FromDouble")
let PyInt_AsLong: @convention(c) (PyObjectPointer) -> Int =
PythonLibrary.loadSymbol(
name: "PyLong_AsLong",
legacyName: "PyInt_AsLong")
let PyInt_FromLong: @convention(c) (Int) -> PyObjectPointer =
PythonLibrary.loadSymbol(
name: "PyLong_FromLong",
legacyName: "PyInt_FromLong")
let PyInt_AsUnsignedLongMask: @convention(c) (PyObjectPointer) -> UInt =
PythonLibrary.loadSymbol(
name: "PyLong_AsUnsignedLongMask",
legacyName: "PyInt_AsUnsignedLongMask")
let PyInt_FromSize_t: @convention(c) (UInt) -> PyObjectPointer =
PythonLibrary.loadSymbol(
name: "PyLong_FromUnsignedLong",
legacyName: "PyInt_FromSize_t")
let PyString_AsString: @convention(c) (PyObjectPointer) -> PyCCharPointer? =
PythonLibrary.loadSymbol(
name: "PyUnicode_AsUTF8",
legacyName: "PyString_AsString")
let PyString_FromStringAndSize: @convention(c) (
PyCCharPointer?, Int) -> (PyObjectPointer?) =
PythonLibrary.loadSymbol(
name: "PyUnicode_DecodeUTF8",
legacyName: "PyString_FromStringAndSize")
let PyBytes_FromStringAndSize: @convention(c) (
PyCCharPointer?, Int) -> (PyObjectPointer?) =
PythonLibrary.loadSymbol(
name: "PyBytes_FromStringAndSize",
legacyName: "PyString_FromStringAndSize")
let PyBytes_AsStringAndSize: @convention(c) (
PyObjectPointer,
UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?,
UnsafeMutablePointer<Int>?) -> CInt =
PythonLibrary.loadSymbol(
name: "PyBytes_AsStringAndSize",
legacyName: "PyString_AsStringAndSize")
let _Py_ZeroStruct: PyObjectPointer =
PythonLibrary.loadSymbol(name: "_Py_ZeroStruct")
let _Py_TrueStruct: PyObjectPointer =
PythonLibrary.loadSymbol(name: "_Py_TrueStruct")
let PyBool_Type: PyObjectPointer =
PythonLibrary.loadSymbol(name: "PyBool_Type")
let PySlice_Type: PyObjectPointer =
PythonLibrary.loadSymbol(name: "PySlice_Type")
let PyNumber_Add: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_Add")
let PyNumber_Subtract: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_Subtract")
let PyNumber_Multiply: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_Multiply")
let PyNumber_TrueDivide: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_TrueDivide")
let PyNumber_InPlaceAdd: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_InPlaceAdd")
let PyNumber_InPlaceSubtract: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_InPlaceSubtract")
let PyNumber_InPlaceMultiply: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_InPlaceMultiply")
let PyNumber_InPlaceTrueDivide: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_InPlaceTrueDivide")
let PyNumber_Negative: PyUnaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_Negative")
let PyNumber_And: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_And")
let PyNumber_Or: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_Or")
let PyNumber_Xor: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_Xor")
let PyNumber_InPlaceAnd: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_InPlaceAnd")
let PyNumber_InPlaceOr: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_InPlaceOr")
let PyNumber_InPlaceXor: PyBinaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_InPlaceXor")
let PyNumber_Invert: PyUnaryOperation =
PythonLibrary.loadSymbol(name: "PyNumber_Invert")