| 1 |
use crate::object::*; |
| 2 |
use crate::pyport::Py_ssize_t; |
| 3 |
|
| 4 |
#[cfg(not(GraalPy))] |
| 5 |
use crate::PyCodeObject; |
| 6 |
#[cfg(not(GraalPy))] |
| 7 |
use std::ffi::c_char; |
| 8 |
use std::ffi::{c_int, c_void}; |
| 9 |
#[cfg(not(PyPy))] |
| 10 |
use std::ptr::addr_of_mut; |
| 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 |
pub const CO_OPTIMIZED: c_int = 0x0001; |
| 39 |
pub const CO_NEWLOCALS: c_int = 0x0002; |
| 40 |
pub const CO_VARARGS: c_int = 0x0004; |
| 41 |
pub const CO_VARKEYWORDS: c_int = 0x0008; |
| 42 |
pub const CO_NESTED: c_int = 0x0010; |
| 43 |
pub const CO_GENERATOR: c_int = 0x0020; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
pub const CO_NOFREE: c_int = 0x0040; |
| 50 |
|
| 51 |
|
| 52 |
pub const CO_COROUTINE: c_int = 0x0080; |
| 53 |
pub const CO_ITERABLE_COROUTINE: c_int = 0x0100; |
| 54 |
pub const CO_ASYNC_GENERATOR: c_int = 0x0200; |
| 55 |
|
| 56 |
pub const CO_FUTURE_DIVISION: c_int = 0x2000; |
| 57 |
pub const CO_FUTURE_ABSOLUTE_IMPORT: c_int = 0x4000; |
| 58 |
pub const CO_FUTURE_WITH_STATEMENT: c_int = 0x8000; |
| 59 |
pub const CO_FUTURE_PRINT_FUNCTION: c_int = 0x1_0000; |
| 60 |
pub const CO_FUTURE_UNICODE_LITERALS: c_int = 0x2_0000; |
| 61 |
|
| 62 |
pub const CO_FUTURE_BARRY_AS_BDFL: c_int = 0x4_0000; |
| 63 |
pub const CO_FUTURE_GENERATOR_STOP: c_int = 0x8_0000; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
pub const CO_MAXBLOCKS: usize = 20; |
| 68 |
|
| 69 |
#[cfg(not(PyPy))] |
| 70 |
#[cfg_attr(windows, link(name = "pythonXY"))] |
| 71 |
extern "C" { |
| 72 |
pub static mut PyCode_Type: PyTypeObject; |
| 73 |
} |
| 74 |
|
| 75 |
#[inline] |
| 76 |
#[cfg(not(PyPy))] |
| 77 |
pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { |
| 78 |
(Py_TYPE(op) == addr_of_mut!(PyCode_Type)) as c_int |
| 79 |
} |
| 80 |
|
| 81 |
extern "C" { |
| 82 |
#[cfg(PyPy)] |
| 83 |
#[link_name = "PyPyCode_Check"] |
| 84 |
pub fn PyCode_Check(op: *mut PyObject) -> c_int; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
extern "C" { |
| 90 |
#[cfg(not(GraalPy))] |
| 91 |
#[cfg_attr(PyPy, link_name = "PyPyCode_New")] |
| 92 |
pub fn PyCode_New( |
| 93 |
argcount: c_int, |
| 94 |
kwonlyargcount: c_int, |
| 95 |
nlocals: c_int, |
| 96 |
stacksize: c_int, |
| 97 |
flags: c_int, |
| 98 |
code: *mut PyObject, |
| 99 |
consts: *mut PyObject, |
| 100 |
names: *mut PyObject, |
| 101 |
varnames: *mut PyObject, |
| 102 |
freevars: *mut PyObject, |
| 103 |
cellvars: *mut PyObject, |
| 104 |
filename: *mut PyObject, |
| 105 |
name: *mut PyObject, |
| 106 |
firstlineno: c_int, |
| 107 |
lnotab: *mut PyObject, |
| 108 |
) -> *mut PyCodeObject; |
| 109 |
#[cfg(not(GraalPy))] |
| 110 |
#[cfg(Py_3_8)] |
| 111 |
pub fn PyCode_NewWithPosOnlyArgs( |
| 112 |
argcount: c_int, |
| 113 |
posonlyargcount: c_int, |
| 114 |
kwonlyargcount: c_int, |
| 115 |
nlocals: c_int, |
| 116 |
stacksize: c_int, |
| 117 |
flags: c_int, |
| 118 |
code: *mut PyObject, |
| 119 |
consts: *mut PyObject, |
| 120 |
names: *mut PyObject, |
| 121 |
varnames: *mut PyObject, |
| 122 |
freevars: *mut PyObject, |
| 123 |
cellvars: *mut PyObject, |
| 124 |
filename: *mut PyObject, |
| 125 |
name: *mut PyObject, |
| 126 |
firstlineno: c_int, |
| 127 |
lnotab: *mut PyObject, |
| 128 |
) -> *mut PyCodeObject; |
| 129 |
#[cfg(not(GraalPy))] |
| 130 |
#[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")] |
| 131 |
pub fn PyCode_NewEmpty( |
| 132 |
filename: *const c_char, |
| 133 |
funcname: *const c_char, |
| 134 |
firstlineno: c_int, |
| 135 |
) -> *mut PyCodeObject; |
| 136 |
#[cfg(not(GraalPy))] |
| 137 |
pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) -> c_int; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
pub fn PyCode_Optimize( |
| 142 |
code: *mut PyObject, |
| 143 |
consts: *mut PyObject, |
| 144 |
names: *mut PyObject, |
| 145 |
lnotab: *mut PyObject, |
| 146 |
) -> *mut PyObject; |
| 147 |
pub fn _PyCode_GetExtra( |
| 148 |
code: *mut PyObject, |
| 149 |
index: Py_ssize_t, |
| 150 |
extra: *const *mut c_void, |
| 151 |
) -> c_int; |
| 152 |
pub fn _PyCode_SetExtra(code: *mut PyObject, index: Py_ssize_t, extra: *mut c_void) -> c_int; |
| 153 |
} |