forked from oracle/python-cx_Oracle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcxoApiType.c
89 lines (75 loc) · 3.14 KB
/
cxoApiType.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
//-----------------------------------------------------------------------------
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// cxoApiType.c
// Defines the objects used for identifying types defined by the Python
// Database API.
//-----------------------------------------------------------------------------
#include "cxoModule.h"
//-----------------------------------------------------------------------------
// cxoApiType_free()
// Free the API type object.
//-----------------------------------------------------------------------------
static void cxoApiType_free(cxoApiType *apiType)
{
Py_CLEAR(apiType->dbTypes);
Py_TYPE(apiType)->tp_free((PyObject*) apiType);
}
//-----------------------------------------------------------------------------
// cxoApiType_repr()
// Return a string representation of a queue.
//-----------------------------------------------------------------------------
static PyObject *cxoApiType_repr(cxoApiType *apiType)
{
PyObject *module, *name, *apiTypeName, *result;
apiTypeName = PyUnicode_DecodeASCII(apiType->name, strlen(apiType->name),
NULL);
if (!apiTypeName)
return NULL;
if (cxoUtils_getModuleAndName(Py_TYPE(apiType), &module, &name) < 0) {
Py_DECREF(apiTypeName);
return NULL;
}
result = cxoUtils_formatString("<%s.%s %s>",
PyTuple_Pack(3, module, name, apiTypeName));
Py_DECREF(module);
Py_DECREF(name);
Py_DECREF(apiTypeName);
return result;
}
//-----------------------------------------------------------------------------
// cxoApiType_reduce()
// Method provided for pickling/unpickling of API types.
//-----------------------------------------------------------------------------
static PyObject *cxoApiType_reduce(cxoApiType *apiType)
{
return PyUnicode_DecodeASCII(apiType->name, strlen(apiType->name), NULL);
}
//-----------------------------------------------------------------------------
// declaration of methods
//-----------------------------------------------------------------------------
static PyMethodDef cxoMethods[] = {
{ "__reduce__", (PyCFunction) cxoApiType_reduce, METH_NOARGS },
{ NULL, NULL }
};
//-----------------------------------------------------------------------------
// declaration of members
//-----------------------------------------------------------------------------
static PyMemberDef cxoMembers[] = {
{ "name", T_STRING, offsetof(cxoApiType, name), READONLY },
{ NULL }
};
//-----------------------------------------------------------------------------
// Python type declaration
//-----------------------------------------------------------------------------
PyTypeObject cxoPyTypeApiType = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "cx_Oracle.ApiType",
.tp_basicsize = sizeof(cxoApiType),
.tp_dealloc = (destructor) cxoApiType_free,
.tp_repr = (reprfunc) cxoApiType_repr,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_members = cxoMembers,
.tp_methods = cxoMethods
};