PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
plpy_subxactobject.c File Reference
#include "postgres.h"
#include "access/xact.h"
#include "plpy_elog.h"
#include "plpy_subxactobject.h"
#include "plpython.h"
#include "utils/memutils.h"
Include dependency graph for plpy_subxactobject.c:

Go to the source code of this file.

Functions

static void PLy_subtransaction_dealloc (PyObject *subxact)
 
static PyObject * PLy_subtransaction_enter (PyObject *self, PyObject *unused)
 
static PyObject * PLy_subtransaction_exit (PyObject *self, PyObject *args)
 
void PLy_subtransaction_init_type (void)
 
PyObject * PLy_subtransaction_new (PyObject *self, PyObject *unused)
 

Variables

Listexplicit_subtransactions = NIL
 
static char PLy_subtransaction_doc []
 
static PyMethodDef PLy_subtransaction_methods []
 
static PyTypeObject PLy_SubtransactionType
 

Function Documentation

◆ PLy_subtransaction_dealloc()

static void PLy_subtransaction_dealloc ( PyObject *  subxact)
static

Definition at line 71 of file plpy_subxactobject.c.

72{
73}

◆ PLy_subtransaction_enter()

static PyObject * PLy_subtransaction_enter ( PyObject *  self,
PyObject *  unused 
)
static

Definition at line 84 of file plpy_subxactobject.c.

85{
86 PLySubtransactionData *subxactdata;
87 MemoryContext oldcontext;
89
90 if (subxact->started)
91 {
92 PLy_exception_set(PyExc_ValueError, "this subtransaction has already been entered");
93 return NULL;
94 }
95
96 if (subxact->exited)
97 {
98 PLy_exception_set(PyExc_ValueError, "this subtransaction has already been exited");
99 return NULL;
100 }
101
102 subxact->started = true;
103 oldcontext = CurrentMemoryContext;
104
105 subxactdata = (PLySubtransactionData *)
107 sizeof(PLySubtransactionData));
108
109 subxactdata->oldcontext = oldcontext;
110 subxactdata->oldowner = CurrentResourceOwner;
111
113
114 /* Be sure that cells of explicit_subtransactions list are long-lived */
117
118 /* Caller wants to stay in original memory context */
119 MemoryContextSwitchTo(oldcontext);
120
121 Py_INCREF(self);
122 return self;
123}
List * lcons(void *datum, List *list)
Definition: list.c:495
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
MemoryContext TopTransactionContext
Definition: mcxt.c:154
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
void PLy_exception_set(PyObject *exc, const char *fmt,...)
Definition: plpy_elog.c:472
List * explicit_subtransactions
ResourceOwner CurrentResourceOwner
Definition: resowner.c:165
PyObject_HEAD bool started
void BeginInternalSubTransaction(const char *name)
Definition: xact.c:4686

References BeginInternalSubTransaction(), CurrentMemoryContext, CurrentResourceOwner, PLySubtransactionObject::exited, explicit_subtransactions, lcons(), MemoryContextAlloc(), MemoryContextSwitchTo(), PLySubtransactionData::oldcontext, PLySubtransactionData::oldowner, PLy_exception_set(), PLySubtransactionObject::started, and TopTransactionContext.

◆ PLy_subtransaction_exit()

static PyObject * PLy_subtransaction_exit ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 137 of file plpy_subxactobject.c.

138{
139 PyObject *type;
140 PyObject *value;
141 PyObject *traceback;
142 PLySubtransactionData *subxactdata;
144
145 if (!PyArg_ParseTuple(args, "OOO", &type, &value, &traceback))
146 return NULL;
147
148 if (!subxact->started)
149 {
150 PLy_exception_set(PyExc_ValueError, "this subtransaction has not been entered");
151 return NULL;
152 }
153
154 if (subxact->exited)
155 {
156 PLy_exception_set(PyExc_ValueError, "this subtransaction has already been exited");
157 return NULL;
158 }
159
161 {
162 PLy_exception_set(PyExc_ValueError, "there is no subtransaction to exit from");
163 return NULL;
164 }
165
166 subxact->exited = true;
167
168 if (type != Py_None)
169 {
170 /* Abort the inner transaction */
172 }
173 else
174 {
176 }
177
180
181 MemoryContextSwitchTo(subxactdata->oldcontext);
182 CurrentResourceOwner = subxactdata->oldowner;
183 pfree(subxactdata);
184
185 Py_RETURN_NONE;
186}
static struct @162 value
List * list_delete_first(List *list)
Definition: list.c:943
void pfree(void *pointer)
Definition: mcxt.c:1521
#define NIL
Definition: pg_list.h:68
#define linitial(l)
Definition: pg_list.h:178
const char * type
void RollbackAndReleaseCurrentSubTransaction(void)
Definition: xact.c:4788
void ReleaseCurrentSubTransaction(void)
Definition: xact.c:4760

References generate_unaccent_rules::args, CurrentResourceOwner, PLySubtransactionObject::exited, explicit_subtransactions, linitial, list_delete_first(), MemoryContextSwitchTo(), NIL, PLySubtransactionData::oldcontext, PLySubtransactionData::oldowner, pfree(), PLy_exception_set(), ReleaseCurrentSubTransaction(), RollbackAndReleaseCurrentSubTransaction(), PLySubtransactionObject::started, type, and value.

◆ PLy_subtransaction_init_type()

void PLy_subtransaction_init_type ( void  )

Definition at line 46 of file plpy_subxactobject.c.

47{
48 if (PyType_Ready(&PLy_SubtransactionType) < 0)
49 elog(ERROR, "could not initialize PLy_SubtransactionType");
50}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
static PyTypeObject PLy_SubtransactionType

References elog, ERROR, and PLy_SubtransactionType.

Referenced by PLy_init_plpy().

◆ PLy_subtransaction_new()

PyObject * PLy_subtransaction_new ( PyObject *  self,
PyObject *  unused 
)

Definition at line 54 of file plpy_subxactobject.c.

55{
57
59
60 if (ob == NULL)
61 return NULL;
62
63 ob->started = false;
64 ob->exited = false;
65
66 return (PyObject *) ob;
67}

References PLySubtransactionObject::exited, PLy_SubtransactionType, and PLySubtransactionObject::started.

Variable Documentation

◆ explicit_subtransactions

◆ PLy_subtransaction_doc

char PLy_subtransaction_doc[]
static
Initial value:
=
"PostgreSQL subtransaction context manager"

Definition at line 22 of file plpy_subxactobject.c.

◆ PLy_subtransaction_methods

PyMethodDef PLy_subtransaction_methods[]
static
Initial value:
= {
{"__enter__", PLy_subtransaction_enter, METH_VARARGS, NULL},
{"__exit__", PLy_subtransaction_exit, METH_VARARGS, NULL},
{"enter", PLy_subtransaction_enter, METH_VARARGS, NULL},
{"exit", PLy_subtransaction_exit, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
}
static PyObject * PLy_subtransaction_exit(PyObject *self, PyObject *args)
static PyObject * PLy_subtransaction_enter(PyObject *self, PyObject *unused)

Definition at line 25 of file plpy_subxactobject.c.

◆ PLy_SubtransactionType

PyTypeObject PLy_SubtransactionType
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "PLySubtransaction",
.tp_basicsize = sizeof(PLySubtransactionObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
}
static PyMethodDef PLy_subtransaction_methods[]
static char PLy_subtransaction_doc[]
static void PLy_subtransaction_dealloc(PyObject *subxact)
struct PLySubtransactionObject PLySubtransactionObject

Definition at line 34 of file plpy_subxactobject.c.

Referenced by PLy_subtransaction_init_type(), and PLy_subtransaction_new().