MCPcopy Create free account
hub / github.com/apache/cloudberry / plpython_inline_handler

Function plpython_inline_handler

src/pl/plpython/plpy_main.c:341–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339#endif /* PY_MAJOR_VERSION < 3 */
340
341Datum
342plpython_inline_handler(PG_FUNCTION_ARGS)
343{
344 LOCAL_FCINFO(fake_fcinfo, 0);
345 InlineCodeBlock *codeblock = (InlineCodeBlock *) DatumGetPointer(PG_GETARG_DATUM(0));
346 FmgrInfo flinfo;
347 PLyProcedure proc;
348 PLyExecutionContext *exec_ctx;
349 ErrorContextCallback plerrcontext;
350
351 PLy_initialize();
352
353 /* Note: SPI_finish() happens in plpy_exec.c, which is dubious design */
354 if (SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC) != SPI_OK_CONNECT)
355 elog(ERROR, "SPI_connect failed");
356
357 MemSet(fcinfo, 0, SizeForFunctionCallInfo(0));
358 MemSet(&flinfo, 0, sizeof(flinfo));
359 fake_fcinfo->flinfo = &flinfo;
360 flinfo.fn_oid = InvalidOid;
361 flinfo.fn_mcxt = CurrentMemoryContext;
362
363 MemSet(&proc, 0, sizeof(PLyProcedure));
364 proc.mcxt = AllocSetContextCreate(TopMemoryContext,
365 "__plpython_inline_block",
366 ALLOCSET_DEFAULT_SIZES);
367 proc.pyname = MemoryContextStrdup(proc.mcxt, "__plpython_inline_block");
368 proc.langid = codeblock->langOid;
369
370 /*
371 * This is currently sufficient to get PLy_exec_function to work, but
372 * someday we might need to be honest and use PLy_output_setup_func.
373 */
374 proc.result.typoid = VOIDOID;
375
376 /*
377 * Push execution context onto stack. It is important that this get
378 * popped again, so avoid putting anything that could throw error between
379 * here and the PG_TRY.
380 */
381 exec_ctx = PLy_push_execution_context(codeblock->atomic);
382
383 PG_TRY();
384 {
385 /*
386 * Setup error traceback support for ereport().
387 * plpython_inline_error_callback doesn't currently need exec_ctx, but
388 * for consistency with plpython_call_handler we do it the same way.
389 */
390 plerrcontext.callback = plpython_inline_error_callback;
391 plerrcontext.arg = exec_ctx;
392 plerrcontext.previous = error_context_stack;
393 error_context_stack = &plerrcontext;
394
395 PLy_procedure_compile(&proc, codeblock->source_text);
396 exec_ctx->curr_proc = &proc;
397 PLy_exec_function(fake_fcinfo, &proc);
398 }

Callers 1

plpython2_inline_handlerFunction · 0.85

Calls 8

PLy_initializeFunction · 0.85
SPI_connect_extFunction · 0.85
MemoryContextStrdupFunction · 0.85
PLy_procedure_compileFunction · 0.85
PLy_exec_functionFunction · 0.85
PLy_procedure_deleteFunction · 0.85

Tested by

no test coverage detected