MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / compileCommand

Method compileCommand

src/Gui/PythonConsole.cpp:212–237  ·  view source on GitHub ↗

* Compile a command and determine whether it is incomplete. * * The source string may contain line feeds and/or carriage returns. \n * Return value: * - Return 1 if the command is incomplete * - Return 0 if the command is complete and valid * - Return -1 if the command is a syntax error * . * (OverflowError and ValueError can be produced by malformed literals). */

Source from the content-addressed store, hash-verified

210 * (OverflowError and ValueError can be produced by malformed literals).
211 */
212int InteractiveInterpreter::compileCommand(const char* source) const
213{
214 Base::PyGILStateLocker lock;
215 PyObject* func = PyObject_GetAttrString(d->interpreter, "compile");
216 PyObject* args = Py_BuildValue("(s)", source);
217 PyObject* eval = PyObject_CallObject(func, args); // must decref later
218
219 Py_DECREF(args);
220 Py_DECREF(func);
221
222 int ret = 0;
223 if (eval) {
224 if (PyObject_TypeCheck(Py_None, eval->ob_type)) {
225 ret = 1; // incomplete
226 }
227 else {
228 ret = 0; // complete
229 }
230 Py_DECREF(eval);
231 }
232 else {
233 ret = -1; // invalid
234 }
235
236 return ret;
237}
238
239/**
240 * Compile and run some source in the interpreter.

Callers 1

runSourceFromMimeDataMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected