#ifndef Py_BUILD_CORE_BUILTIN
#define Py_BUILD_CORE_MODULE …
#endif
#include "Python.h"
#ifdef MS_WIN32
# include <windows.h>
#endif
#include "pycore_bitutils.h"
#include "pycore_call.h"
#include <ffi.h>
#include "ctypes.h"
#if defined(Py_HAVE_C_COMPLEX) && defined(Py_FFI_SUPPORT_C_COMPLEX)
# include "../_complex.h"
#endif
#define CTYPES_CFIELD_CAPSULE_NAME_PYMEM …
#include "clinic/cfield.c.h"
static void pymem_destructor(PyObject *ptr)
{ … }
static inline
Py_ssize_t NUM_BITS(Py_ssize_t bitsize);
static inline
Py_ssize_t LOW_BIT(Py_ssize_t offset);
static PyObject *
PyCField_new_impl(PyTypeObject *type, PyObject *name, PyObject *proto,
Py_ssize_t size, Py_ssize_t offset, Py_ssize_t index,
PyObject *bit_size_obj)
{ … }
static int
PyCField_set(CFieldObject *self, PyObject *inst, PyObject *value)
{ … }
static PyObject *
PyCField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type)
{ … }
static PyObject *
PyCField_get_offset(PyObject *self, void *data)
{ … }
static PyObject *
PyCField_get_size(PyObject *self, void *data)
{ … }
static PyGetSetDef PyCField_getset[] = …;
static int
PyCField_traverse(CFieldObject *self, visitproc visit, void *arg)
{ … }
static int
PyCField_clear(CFieldObject *self)
{ … }
static void
PyCField_dealloc(PyObject *self)
{ … }
static PyObject *
PyCField_repr(CFieldObject *self)
{ … }
static PyType_Slot cfield_slots[] = …;
PyType_Spec cfield_spec = …;
static int
get_long(PyObject *v, long *p)
{ … }
static int
get_ulong(PyObject *v, unsigned long *p)
{ … }
static int
get_longlong(PyObject *v, long long *p)
{ … }
static int
get_ulonglong(PyObject *v, unsigned long long *p)
{ … }
static inline
Py_ssize_t LOW_BIT(Py_ssize_t offset) { … }
static inline
Py_ssize_t NUM_BITS(Py_ssize_t bitsize) { … }
#define BIT_MASK(type, size) …
#define GET_BITFIELD(v, size) …
#define SET(type, x, v, size) …
#if SIZEOF_SHORT == 2
#define SWAP_SHORT …
#else
# error "unsupported short size"
#endif
#if SIZEOF_INT == 4
#define SWAP_INT …
#else
# error "unsupported int size"
#endif
#if SIZEOF_LONG == 4
#define SWAP_LONG …
#elif SIZEOF_LONG == 8
#define SWAP_LONG …
#else
# error "unsupported long size"
#endif
#if SIZEOF_LONG_LONG == 8
#define SWAP_LONG_LONG …
#else
# error "unsupported long long size"
#endif
#ifdef _CTYPES_DEBUG_KEEP
#define _RET …
#else
#define _RET(X) …
#endif
static PyObject *
b_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
b_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
B_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
B_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
h_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
h_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
h_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
h_get_sw(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
H_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
H_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
H_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
H_get_sw(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
i_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
i_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
i_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
i_get_sw(void *ptr, Py_ssize_t size)
{ … }
#ifndef MS_WIN32
#define VARIANT_FALSE …
#define VARIANT_TRUE …
#endif
static PyObject *
vBOOL_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
vBOOL_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
bool_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
bool_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
I_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
I_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
I_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
I_get_sw(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
l_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
l_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
l_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
l_get_sw(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
L_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
L_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
L_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
L_get_sw(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
q_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
q_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
q_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
q_get_sw(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
Q_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
Q_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
Q_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
Q_get_sw(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
g_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
g_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
d_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
d_get(void *ptr, Py_ssize_t size)
{ … }
#if defined(Py_HAVE_C_COMPLEX) && defined(Py_FFI_SUPPORT_C_COMPLEX)
static PyObject *
C_set(void *ptr, PyObject *value, Py_ssize_t size)
{
Py_complex c = PyComplex_AsCComplex(value);
if (c.real == -1 && PyErr_Occurred()) {
return NULL;
}
double complex x = CMPLX(c.real, c.imag);
memcpy(ptr, &x, sizeof(x));
_RET(value);
}
static PyObject *
C_get(void *ptr, Py_ssize_t size)
{
double complex x;
memcpy(&x, ptr, sizeof(x));
return PyComplex_FromDoubles(creal(x), cimag(x));
}
static PyObject *
E_set(void *ptr, PyObject *value, Py_ssize_t size)
{
Py_complex c = PyComplex_AsCComplex(value);
if (c.real == -1 && PyErr_Occurred()) {
return NULL;
}
float complex x = CMPLXF((float)c.real, (float)c.imag);
memcpy(ptr, &x, sizeof(x));
_RET(value);
}
static PyObject *
E_get(void *ptr, Py_ssize_t size)
{
float complex x;
memcpy(&x, ptr, sizeof(x));
return PyComplex_FromDoubles(crealf(x), cimagf(x));
}
static PyObject *
F_set(void *ptr, PyObject *value, Py_ssize_t size)
{
Py_complex c = PyComplex_AsCComplex(value);
if (c.real == -1 && PyErr_Occurred()) {
return NULL;
}
long double complex x = CMPLXL(c.real, c.imag);
memcpy(ptr, &x, sizeof(x));
_RET(value);
}
static PyObject *
F_get(void *ptr, Py_ssize_t size)
{
long double complex x;
memcpy(&x, ptr, sizeof(x));
return PyComplex_FromDoubles((double)creall(x), (double)cimagl(x));
}
#endif
static PyObject *
d_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
d_get_sw(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
f_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
f_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
f_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
f_get_sw(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
O_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
O_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
c_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
c_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
u_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
u_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
U_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
U_set(void *ptr, PyObject *value, Py_ssize_t length)
{ … }
static PyObject *
s_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
s_set(void *ptr, PyObject *value, Py_ssize_t length)
{ … }
static PyObject *
z_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
z_get(void *ptr, Py_ssize_t size)
{ … }
static PyObject *
Z_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
Z_get(void *ptr, Py_ssize_t size)
{ … }
#ifdef MS_WIN32
static PyObject *
BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
{
BSTR bstr;
if (Py_None == value) {
value = NULL;
} else if (!PyUnicode_Check(value)) {
PyErr_Format(PyExc_TypeError,
"unicode string expected instead of %s instance",
Py_TYPE(value)->tp_name);
return NULL;
}
if (value) {
Py_ssize_t wsize;
wchar_t *wvalue = PyUnicode_AsWideCharString(value, &wsize);
if (wvalue == NULL) {
return NULL;
}
if ((unsigned) wsize != wsize) {
PyErr_SetString(PyExc_ValueError, "String too long for BSTR");
PyMem_Free(wvalue);
return NULL;
}
bstr = SysAllocStringLen(wvalue, (unsigned)wsize);
PyMem_Free(wvalue);
} else
bstr = NULL;
if (*(BSTR *)ptr)
SysFreeString(*(BSTR *)ptr);
*(BSTR *)ptr = bstr;
_RET(value);
}
static PyObject *
BSTR_get(void *ptr, Py_ssize_t size)
{
BSTR p;
p = *(BSTR *)ptr;
if (p)
return PyUnicode_FromWideChar(p, SysStringLen(p));
else {
Py_RETURN_NONE;
}
}
#endif
static PyObject *
P_set(void *ptr, PyObject *value, Py_ssize_t size)
{ … }
static PyObject *
P_get(void *ptr, Py_ssize_t size)
{ … }
static struct fielddesc formattable[] = …;
void
_ctypes_init_fielddesc(void)
{ … }
struct fielddesc *
_ctypes_get_fielddesc(const char *fmt)
{ … }