|
| 1 | +//----------------------------------------------------------------------------- |
| 2 | +// Copyright 2018, Oracle and/or its affiliates. All rights reserved. |
| 3 | +//----------------------------------------------------------------------------- |
| 4 | + |
| 5 | +//----------------------------------------------------------------------------- |
| 6 | +// cxoFuture.c |
| 7 | +// Defines the object used for managing behavior changes. This object permits |
| 8 | +// setting any attribute to any value but only tracks certain values. |
| 9 | +//----------------------------------------------------------------------------- |
| 10 | + |
| 11 | +#include "cxoModule.h" |
| 12 | + |
| 13 | +//----------------------------------------------------------------------------- |
| 14 | +// functions for the Python type "Object" |
| 15 | +//----------------------------------------------------------------------------- |
| 16 | +static void cxoFuture_free(cxoFuture*); |
| 17 | +static PyObject *cxoFuture_getAttr(cxoFuture*, PyObject*); |
| 18 | +static int cxoFuture_setAttr(cxoFuture*, PyObject*, PyObject*); |
| 19 | + |
| 20 | + |
| 21 | +//----------------------------------------------------------------------------- |
| 22 | +// Python type declaration |
| 23 | +//----------------------------------------------------------------------------- |
| 24 | +PyTypeObject cxoPyTypeFuture = { |
| 25 | + PyVarObject_HEAD_INIT(NULL, 0) |
| 26 | + "cx_Oracle.__future__", // tp_name |
| 27 | + sizeof(cxoFuture), // tp_basicsize |
| 28 | + 0, // tp_itemsize |
| 29 | + (destructor) cxoFuture_free, // tp_dealloc |
| 30 | + 0, // tp_print |
| 31 | + 0, // tp_getattr |
| 32 | + 0, // tp_setattr |
| 33 | + 0, // tp_compare |
| 34 | + 0, // tp_repr |
| 35 | + 0, // tp_as_number |
| 36 | + 0, // tp_as_sequence |
| 37 | + 0, // tp_as_mapping |
| 38 | + 0, // tp_hash |
| 39 | + 0, // tp_call |
| 40 | + 0, // tp_str |
| 41 | + (getattrofunc) cxoFuture_getAttr, // tp_getattro |
| 42 | + (setattrofunc) cxoFuture_setAttr, // tp_setattro |
| 43 | + 0, // tp_as_buffer |
| 44 | + Py_TPFLAGS_DEFAULT // tp_flags |
| 45 | +}; |
| 46 | + |
| 47 | + |
| 48 | +//----------------------------------------------------------------------------- |
| 49 | +// cxoFuture_free() |
| 50 | +// Free the future object and reset global. |
| 51 | +//----------------------------------------------------------------------------- |
| 52 | +static void cxoFuture_free(cxoFuture *obj) |
| 53 | +{ |
| 54 | + Py_TYPE(obj)->tp_free((PyObject*) obj); |
| 55 | + cxoFutureObj = NULL; |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +//----------------------------------------------------------------------------- |
| 60 | +// cxoFuture_getAttr() |
| 61 | +// Retrieve an attribute on an object. |
| 62 | +//----------------------------------------------------------------------------- |
| 63 | +static PyObject *cxoFuture_getAttr(cxoFuture *obj, PyObject *nameObject) |
| 64 | +{ |
| 65 | + cxoBuffer buffer; |
| 66 | + PyObject *result; |
| 67 | + |
| 68 | + if (cxoBuffer_fromObject(&buffer, nameObject, NULL) < 0) |
| 69 | + return NULL; |
| 70 | + if (strncmp(buffer.ptr, "ctx_mgr_close", buffer.size) == 0) |
| 71 | + result = PyBool_FromLong(obj->contextManagerClose); |
| 72 | + else { |
| 73 | + Py_INCREF(Py_None); |
| 74 | + result = Py_None; |
| 75 | + } |
| 76 | + cxoBuffer_clear(&buffer); |
| 77 | + return result; |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +//----------------------------------------------------------------------------- |
| 82 | +// cxoFuture_setAttr() |
| 83 | +// Set an attribute on an object. |
| 84 | +//----------------------------------------------------------------------------- |
| 85 | +static int cxoFuture_setAttr(cxoFuture *obj, PyObject *nameObject, |
| 86 | + PyObject *value) |
| 87 | +{ |
| 88 | + cxoBuffer buffer; |
| 89 | + int result = 0; |
| 90 | + |
| 91 | + if (cxoBuffer_fromObject(&buffer, nameObject, NULL) < 0) |
| 92 | + return -1; |
| 93 | + if (strncmp(buffer.ptr, "ctx_mgr_close", buffer.size) == 0) |
| 94 | + result = cxoUtils_getBooleanValue(value, 0, &obj->contextManagerClose); |
| 95 | + cxoBuffer_clear(&buffer); |
| 96 | + return result; |
| 97 | +} |
| 98 | + |
0 commit comments