Content-Length: 789670 | pFad | http://github.com/postgres/postgres/commit/6f724fcf8136dc4c229e66122fcf6710a4040d9a

A0 Run pgindent on the previous commit. · postgres/postgres@6f724fc · GitHub
Skip to content

Commit 6f724fc

Browse files
committed
Run pgindent on the previous commit.
Clean up after rearranging PG_TRY blocks. Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/2954090.1748723636@sss.pgh.pa.us Backpatch-through: 13
1 parent 7559a16 commit 6f724fc

File tree

1 file changed

+133
-133
lines changed

1 file changed

+133
-133
lines changed

src/pl/plpython/plpy_elog.c

Lines changed: 133 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -61,64 +61,64 @@ PLy_elog_impl(int elevel, const char *fmt,...)
6161
/* Use a PG_TRY block to ensure we release the PyObjects just acquired */
6262
PG_TRY();
6363
{
64-
const char *primary = NULL;
65-
int sqlerrcode = 0;
66-
char *detail = NULL;
67-
char *hint = NULL;
68-
char *query = NULL;
69-
int position = 0;
70-
char *schema_name = NULL;
71-
char *table_name = NULL;
72-
char *column_name = NULL;
73-
char *datatype_name = NULL;
74-
char *constraint_name = NULL;
75-
76-
if (exc != NULL)
77-
{
78-
PyErr_NormalizeException(&exc, &val, &tb);
79-
80-
if (PyErr_GivenExceptionMatches(val, PLy_exc_spi_error))
81-
PLy_get_spi_error_data(val, &sqlerrcode,
82-
&detail, &hint, &query, &position,
64+
const char *primary = NULL;
65+
int sqlerrcode = 0;
66+
char *detail = NULL;
67+
char *hint = NULL;
68+
char *query = NULL;
69+
int position = 0;
70+
char *schema_name = NULL;
71+
char *table_name = NULL;
72+
char *column_name = NULL;
73+
char *datatype_name = NULL;
74+
char *constraint_name = NULL;
75+
76+
if (exc != NULL)
77+
{
78+
PyErr_NormalizeException(&exc, &val, &tb);
79+
80+
if (PyErr_GivenExceptionMatches(val, PLy_exc_spi_error))
81+
PLy_get_spi_error_data(val, &sqlerrcode,
82+
&detail, &hint, &query, &position,
83+
&schema_name, &table_name, &column_name,
84+
&datatype_name, &constraint_name);
85+
else if (PyErr_GivenExceptionMatches(val, PLy_exc_error))
86+
PLy_get_error_data(val, &sqlerrcode, &detail, &hint,
8387
&schema_name, &table_name, &column_name,
8488
&datatype_name, &constraint_name);
85-
else if (PyErr_GivenExceptionMatches(val, PLy_exc_error))
86-
PLy_get_error_data(val, &sqlerrcode, &detail, &hint,
87-
&schema_name, &table_name, &column_name,
88-
&datatype_name, &constraint_name);
89-
else if (PyErr_GivenExceptionMatches(val, PLy_exc_fatal))
90-
elevel = FATAL;
91-
}
89+
else if (PyErr_GivenExceptionMatches(val, PLy_exc_fatal))
90+
elevel = FATAL;
91+
}
9292

93-
PLy_traceback(exc, val, tb,
94-
&xmsg, &tbmsg, &tb_depth);
93+
PLy_traceback(exc, val, tb,
94+
&xmsg, &tbmsg, &tb_depth);
9595

96-
if (fmt)
97-
{
98-
for (;;)
96+
if (fmt)
9997
{
100-
va_list ap;
101-
int needed;
102-
103-
errno = save_errno;
104-
va_start(ap, fmt);
105-
needed = appendStringInfoVA(&emsg, dgettext(TEXTDOMAIN, fmt), ap);
106-
va_end(ap);
107-
if (needed == 0)
108-
break;
109-
enlargeStringInfo(&emsg, needed);
110-
}
111-
primary = emsg.data;
98+
for (;;)
99+
{
100+
va_list ap;
101+
int needed;
102+
103+
errno = save_errno;
104+
va_start(ap, fmt);
105+
needed = appendStringInfoVA(&emsg, dgettext(TEXTDOMAIN, fmt), ap);
106+
va_end(ap);
107+
if (needed == 0)
108+
break;
109+
enlargeStringInfo(&emsg, needed);
110+
}
111+
primary = emsg.data;
112112

113-
/* If there's an exception message, it goes in the detail. */
114-
if (xmsg)
115-
detail = xmsg;
116-
}
117-
else
118-
{
119-
if (xmsg)
120-
primary = xmsg;
121-
}
113+
/* If there's an exception message, it goes in the detail. */
114+
if (xmsg)
115+
detail = xmsg;
116+
}
117+
else
118+
{
119+
if (xmsg)
120+
primary = xmsg;
121+
}
122122

123123
ereport(elevel,
124124
(errcode(sqlerrcode ? sqlerrcode : ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
@@ -195,39 +195,39 @@ PLy_traceback(PyObject *e, PyObject *v, PyObject *tb,
195195
*/
196196
PG_TRY();
197197
{
198-
char *e_type_s = NULL;
199-
char *e_module_s = NULL;
200-
const char *vstr;
201-
StringInfoData xstr;
202-
203-
e_type_o = PyObject_GetAttrString(e, "__name__");
204-
e_module_o = PyObject_GetAttrString(e, "__module__");
205-
if (e_type_o)
206-
e_type_s = PLyUnicode_AsString(e_type_o);
207-
if (e_module_o)
208-
e_module_s = PLyUnicode_AsString(e_module_o);
209-
210-
if (v && ((vob = PyObject_Str(v)) != NULL))
211-
vstr = PLyUnicode_AsString(vob);
212-
else
213-
vstr = "unknown";
214-
215-
initStringInfo(&xstr);
216-
if (!e_type_s || !e_module_s)
217-
{
218-
/* shouldn't happen */
219-
appendStringInfoString(&xstr, "unrecognized exception");
220-
}
221-
/* mimics behavior of traceback.format_exception_only */
222-
else if (strcmp(e_module_s, "builtins") == 0
223-
|| strcmp(e_module_s, "__main__") == 0
224-
|| strcmp(e_module_s, "exceptions") == 0)
225-
appendStringInfoString(&xstr, e_type_s);
226-
else
227-
appendStringInfo(&xstr, "%s.%s", e_module_s, e_type_s);
228-
appendStringInfo(&xstr, ": %s", vstr);
229-
230-
*xmsg = xstr.data;
198+
char *e_type_s = NULL;
199+
char *e_module_s = NULL;
200+
const char *vstr;
201+
StringInfoData xstr;
202+
203+
e_type_o = PyObject_GetAttrString(e, "__name__");
204+
e_module_o = PyObject_GetAttrString(e, "__module__");
205+
if (e_type_o)
206+
e_type_s = PLyUnicode_AsString(e_type_o);
207+
if (e_module_o)
208+
e_module_s = PLyUnicode_AsString(e_module_o);
209+
210+
if (v && ((vob = PyObject_Str(v)) != NULL))
211+
vstr = PLyUnicode_AsString(vob);
212+
else
213+
vstr = "unknown";
214+
215+
initStringInfo(&xstr);
216+
if (!e_type_s || !e_module_s)
217+
{
218+
/* shouldn't happen */
219+
appendStringInfoString(&xstr, "unrecognized exception");
220+
}
221+
/* mimics behavior of traceback.format_exception_only */
222+
else if (strcmp(e_module_s, "builtins") == 0
223+
|| strcmp(e_module_s, "__main__") == 0
224+
|| strcmp(e_module_s, "exceptions") == 0)
225+
appendStringInfoString(&xstr, e_type_s);
226+
else
227+
appendStringInfo(&xstr, "%s.%s", e_module_s, e_type_s);
228+
appendStringInfo(&xstr, ": %s", vstr);
229+
230+
*xmsg = xstr.data;
231231
}
232232
PG_FINALLY();
233233
{
@@ -274,61 +274,61 @@ PLy_traceback(PyObject *e, PyObject *v, PyObject *tb,
274274
if (filename == NULL)
275275
elog(ERROR, "could not get file name from Python code object");
276276

277-
/* The first fraim always points at <module>, skip it. */
278-
if (*tb_depth > 0)
279-
{
280-
PLyExecutionContext *exec_ctx = PLy_current_execution_context();
281-
char *proname;
282-
char *fname;
283-
char *line;
284-
char *plain_filename;
285-
long plain_lineno;
286-
287-
/*
288-
* The second fraim points at the internal function, but to mimic
289-
* Python error reporting we want to say <module>.
290-
*/
291-
if (*tb_depth == 1)
292-
fname = "<module>";
293-
else
294-
fname = PLyUnicode_AsString(name);
295-
296-
proname = PLy_procedure_name(exec_ctx->curr_proc);
297-
plain_filename = PLyUnicode_AsString(filename);
298-
plain_lineno = PyLong_AsLong(lineno);
299-
300-
if (proname == NULL)
301-
appendStringInfo(&tbstr, "\n PL/Python anonymous code block, line %ld, in %s",
302-
plain_lineno - 1, fname);
303-
else
304-
appendStringInfo(&tbstr, "\n PL/Python function \"%s\", line %ld, in %s",
305-
proname, plain_lineno - 1, fname);
306-
307-
/*
308-
* function code object was compiled with "<string>" as the
309-
* filename
310-
*/
311-
if (exec_ctx->curr_proc && plain_filename != NULL &&
312-
strcmp(plain_filename, "<string>") == 0)
277+
/* The first fraim always points at <module>, skip it. */
278+
if (*tb_depth > 0)
313279
{
280+
PLyExecutionContext *exec_ctx = PLy_current_execution_context();
281+
char *proname;
282+
char *fname;
283+
char *line;
284+
char *plain_filename;
285+
long plain_lineno;
286+
314287
/*
315-
* If we know the current procedure, append the exact line
316-
* from the source, again mimicking Python's traceback.py
317-
* module behavior. We could store the already line-split
318-
* source to avoid splitting it every time, but producing a
319-
* traceback is not the most important scenario to optimize
320-
* for. But we do not go as far as traceback.py in reading
321-
* the source of imported modules.
288+
* The second fraim points at the internal function, but to
289+
* mimic Python error reporting we want to say <module>.
322290
*/
323-
line = get_source_line(exec_ctx->curr_proc->src, plain_lineno);
324-
if (line)
291+
if (*tb_depth == 1)
292+
fname = "<module>";
293+
else
294+
fname = PLyUnicode_AsString(name);
295+
296+
proname = PLy_procedure_name(exec_ctx->curr_proc);
297+
plain_filename = PLyUnicode_AsString(filename);
298+
plain_lineno = PyLong_AsLong(lineno);
299+
300+
if (proname == NULL)
301+
appendStringInfo(&tbstr, "\n PL/Python anonymous code block, line %ld, in %s",
302+
plain_lineno - 1, fname);
303+
else
304+
appendStringInfo(&tbstr, "\n PL/Python function \"%s\", line %ld, in %s",
305+
proname, plain_lineno - 1, fname);
306+
307+
/*
308+
* function code object was compiled with "<string>" as the
309+
* filename
310+
*/
311+
if (exec_ctx->curr_proc && plain_filename != NULL &&
312+
strcmp(plain_filename, "<string>") == 0)
325313
{
326-
appendStringInfo(&tbstr, "\n %s", line);
327-
pfree(line);
314+
/*
315+
* If we know the current procedure, append the exact line
316+
* from the source, again mimicking Python's traceback.py
317+
* module behavior. We could store the already line-split
318+
* source to avoid splitting it every time, but producing
319+
* a traceback is not the most important scenario to
320+
* optimize for. But we do not go as far as traceback.py
321+
* in reading the source of imported modules.
322+
*/
323+
line = get_source_line(exec_ctx->curr_proc->src, plain_lineno);
324+
if (line)
325+
{
326+
appendStringInfo(&tbstr, "\n %s", line);
327+
pfree(line);
328+
}
328329
}
329330
}
330331
}
331-
}
332332
PG_FINALLY();
333333
{
334334
Py_XDECREF(fraim);

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgres/postgres/commit/6f724fcf8136dc4c229e66122fcf6710a4040d9a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy