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

Function PLy_procedure_compile

src/pl/plpython/plpy_procedure.c:353–402  ·  view source on GitHub ↗

* Insert the procedure into the Python interpreter */

Source from the content-addressed store, hash-verified

351 * Insert the procedure into the Python interpreter
352 */
353void
354PLy_procedure_compile(PLyProcedure *proc, const char *src)
355{
356 PyObject *crv = NULL;
357 char *msrc;
358
359 proc->globals = PyDict_Copy(PLy_interp_globals);
360
361 /*
362 * SD is private preserved data between calls. GD is global data shared by
363 * all functions
364 */
365 proc->statics = PyDict_New();
366 if (!proc->statics)
367 PLy_elog(ERROR, NULL);
368 PyDict_SetItemString(proc->globals, "SD", proc->statics);
369
370 /*
371 * insert the function code into the interpreter
372 */
373 msrc = PLy_procedure_munge_source(proc->pyname, src);
374 /* Save the mangled source for later inclusion in tracebacks */
375 proc->src = MemoryContextStrdup(proc->mcxt, msrc);
376 crv = PyRun_String(msrc, Py_file_input, proc->globals, NULL);
377 pfree(msrc);
378
379 if (crv != NULL)
380 {
381 int clen;
382 char call[NAMEDATALEN + 256];
383
384 Py_DECREF(crv);
385
386 /*
387 * compile a call to the function
388 */
389 clen = snprintf(call, sizeof(call), "%s()", proc->pyname);
390 if (clen < 0 || clen >= sizeof(call))
391 elog(ERROR, "string would overflow buffer");
392 proc->code = Py_CompileString(call, "<string>", Py_eval_input);
393 if (proc->code != NULL)
394 return;
395 }
396
397 if (proc->proname)
398 PLy_elog(ERROR, "could not compile PL/Python function \"%s\"",
399 proc->proname);
400 else
401 PLy_elog(ERROR, "could not compile anonymous PL/Python code block");
402}
403
404void
405PLy_procedure_delete(PLyProcedure *proc)

Callers 2

plpython_inline_handlerFunction · 0.85
PLy_procedure_createFunction · 0.85

Calls 3

MemoryContextStrdupFunction · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected