Base: apply clang format

This commit is contained in:
wmayer
2023-11-10 18:27:44 +01:00
committed by WandererFan
parent bb333d9a74
commit 985def3416
154 changed files with 11874 additions and 9872 deletions

View File

@@ -1,9 +1,10 @@
// clang-format off
/*
PPEMBED, VERSION 2.0
AN ENHANCED PYTHON EMBEDDED-CALL INTERFACE
Copyright 1996-2000, by Mark Lutz, and O'Reilly and Associates.
Permission to use, copy, modify, and distribute this software
Permission to use, copy, modify, and distribute this software
for any purpose and without fee is hereby granted. This software
is provided on an as is basis, without warranties of any kind.
*/
@@ -22,8 +23,8 @@ is provided on an as is basis, without warranties of any kind.
//NOLINTBEGIN
/*****************************************************************************
* RUN EMBEDDED OBJECT METHODS, ACCESS OBJECT ATTRIBUTES
* handles attribute fetch, debugging, input/output conversions;
* RUN EMBEDDED OBJECT METHODS, ACCESS OBJECT ATTRIBUTES
* handles attribute fetch, debugging, input/output conversions;
* there is no module to reload here: assumes a known object;
*****************************************************************************/
@@ -37,7 +38,7 @@ PP_Run_Method(PyObject *pobject, const char *method,
va_start(argslist, argfmt);
Py_Initialize(); /* init if first time */
pmeth = PyObject_GetAttrString(pobject, method);
pmeth = PyObject_GetAttrString(pobject, method);
if (pmeth == NULL) { /* get callable object */
va_end(argslist);
return -1; /* bound method? has self */
@@ -50,9 +51,9 @@ PP_Run_Method(PyObject *pobject, const char *method,
Py_DECREF(pmeth);
return -1;
}
if (PP_DEBUG) /* debug it too? */
presult = PP_Debug_Function(pmeth, pargs);
else
if (PP_DEBUG) /* debug it too? */
presult = PP_Debug_Function(pmeth, pargs);
else
#if PY_VERSION_HEX < 0x03090000
presult = PyEval_CallObject(pmeth, pargs); /* run interpreter */
#else
@@ -64,18 +65,18 @@ PP_Run_Method(PyObject *pobject, const char *method,
return PP_Convert_Result(presult, resfmt, cresult); /* to C format */
}
int
PP_Get_Member(PyObject *pobject, const char *attrname,
const char *resfmt, void *cresult) /* convert to c/c++ */
{
PyObject *pmemb = NULL; /* "pobject.attrname" */
Py_Initialize();
Py_Initialize();
pmemb = PyObject_GetAttrString(pobject, attrname); /* incref'd */
return PP_Convert_Result(pmemb, resfmt, cresult); /* to C form, decrefs */
}
int
PP_Set_Member(PyObject *pobject, const char *attrname,
@@ -91,15 +92,15 @@ PP_Set_Member(PyObject *pobject, const char *attrname,
if (pval == NULL)
return -1;
result = PyObject_SetAttrString(pobject, attrname, pval); /* setattr */
Py_DECREF(pval);
Py_DECREF(pval);
return result;
}
/*****************************************************************************
* RUN EMBEDDED MODULE FUNCTIONS
* handles module (re)import, debugging, input/output conversions;
* note: also useful for calling classes (and C type constructors) at the
* RUN EMBEDDED MODULE FUNCTIONS
* handles module (re)import, debugging, input/output conversions;
* note: also useful for calling classes (and C type constructors) at the
* top-level of a module to make Python instances: use class-name (or type
* constructor function name) and 'O' result convert-code to get raw object;
* use argfmt="()" for no args, cresult='NULL' for no result (procedure);
@@ -151,9 +152,9 @@ PP_Debug_Function(PyObject *func, PyObject *args)
/* expand tuple at front */
// it seems that some versions of python want just 2 arguments; in that
// case, remove trailing 1
oops = _PyTuple_Resize(&args, (1 + PyTuple_Size(args)));
oops |= PyTuple_SetItem(args, 0, func);
if (oops)
oops = _PyTuple_Resize(&args, (1 + PyTuple_Size(args)));
oops |= PyTuple_SetItem(args, 0, func);
if (oops)
return NULL; /* "args = (funcobj,) + (arg,..)" */
res = PP_Run_Function( /* "pdb.runcall(funcobj, arg,..)" */
@@ -174,7 +175,7 @@ PP_Run_Known_Callable(PyObject *object, /* func|class|method */
va_list argslist;
va_start(argslist, argfmt); /* "return object(args)" */
Py_Initialize();
Py_Initialize();
args = Py_VaBuildValue(argfmt, argslist); /* convert args to python */
va_end(argslist);
if (args == NULL) /* args incref'd */
@@ -195,14 +196,14 @@ PP_Run_Known_Callable(PyObject *object, /* func|class|method */
/*****************************************************************************
* PYTHON EXCEPTION INFORMATION ACCESS
* fetch Python-related error info (type, value);
* after an API call returns an exception indicator, call
* after an API call returns an exception indicator, call
* PP_Fetch_Error_Text, then get text from the 3 char[]'s;
* note: calling PyErr_Fetch() clears/erases the current
* exception in the Python system, as does PyErr_Print(),
* note: calling PyErr_Fetch() clears/erases the current
* exception in the Python system, as does PyErr_Print(),
* so you should call one of these, one time, per exception:
* caveats: not thread-specific since saves data in globals,
* and only exports traceback object (the exception type and
* data are converted to text strings and discarded); the
* and only exports traceback object (the exception type and
* data are converted to text strings and discarded); the
* PyErr_Print() built-in also does a bit more on syntax errors,
* and sends its text to sys.stderr: in principle, we could
* assign stderr to a StringIO object and call PyErr_Print, but
@@ -251,7 +252,7 @@ void PP_Fetch_Error_Text()
{
PP_last_error_type[0] = '\0';
}
Py_XDECREF(pystring);
pystring = NULL;
@@ -262,7 +263,7 @@ void PP_Fetch_Error_Text()
// PyDict_GetItemString returns a borrowed reference
// so we must make sure not to decrement the reference
PyObject* value = PyDict_GetItemString(errdata,"swhat");
if (value!=NULL) {
strncpy(PP_last_error_info, PyUnicode_AsUTF8(value), MAX);
PP_last_error_info[MAX-1] = '\0';
@@ -278,12 +279,12 @@ void PP_Fetch_Error_Text()
strncpy(PP_last_error_info, PyUnicode_AsUTF8(pystring), MAX); /*Py->C*/
PP_last_error_info[MAX-1] = '\0';
}
else
else
strcpy(PP_last_error_info, "<unknown exception data>");
Py_XDECREF(pystring);
/* convert traceback to string */
/* convert traceback to string */
/* print text to a StringIO.StringIO() internal file object, then */
/* fetch by calling object's .getvalue() method (see lib manual); */
@@ -294,13 +295,13 @@ void PP_Fetch_Error_Text()
(PyTraceBack_Print(errtraceback, pystring) == 0) &&
(PP_Run_Method(pystring, "getvalue", "s", &tempstr, "()") == 0) )
{
strncpy(PP_last_error_trace, tempstr, MAX);
strncpy(PP_last_error_trace, tempstr, MAX);
PP_last_error_trace[MAX-1] = '\0';
free(tempstr); /* it's a strdup */
}
else {
PyFrameObject* frame = PyEval_GetFrame();
if(!frame)
if(!frame)
return;
int line = PyFrame_GetLineNumber(frame);
#if PY_VERSION_HEX < 0x030b0000
@@ -327,7 +328,7 @@ void PP_Fetch_Error_Text()
PP_last_exception_type = 0;
Py_XDECREF(errobj);
Py_XDECREF(errdata); /* this function owns all 3 objects */
Py_XDECREF(PP_last_traceback); /* they've been NULL'd out in Python */
Py_XDECREF(PP_last_traceback); /* they've been NULL'd out in Python */
Py_XDECREF(PP_PyDict_Object);
PP_last_traceback = errtraceback; /* save/export raw traceback object */
PP_PyDict_Object = pydict;
@@ -337,9 +338,9 @@ void PP_Fetch_Error_Text()
/*****************************************************************************
* GET/SET MODULE-LEVEL (GLOBAL) PYTHON VARIABLES BY NAME
* handles module (re)loading, input/output conversions;
* useful for passing data to/from codestrings (no args or return
* useful for passing data to/from codestrings (no args or return
* val)--load module, set inputs, run codestring, get outputs;
* subtle thing: Python "s" output conversion code sets a C char* to
* subtle thing: Python "s" output conversion code sets a C char* to
* the text in the middle of a Python string object, which may be
* returned to the heap if decref'd--this api copies the text to a new
* char array (with strdup) that the caller must free() when possible,
@@ -390,7 +391,7 @@ PP_Get_Global(const char *modname, const char *varname, const char *resfmt, void
int
PP_Set_Global(const char *modname, const char *varname, const char *valfmt, ... /* cval(s) */)
PP_Set_Global(const char *modname, const char *varname, const char *valfmt, ... /* cval(s) */)
{
int result = 0;
PyObject *module = NULL, *val = NULL; /* "modname.varname = val" */
@@ -404,20 +405,20 @@ PP_Set_Global(const char *modname, const char *varname, const char *valfmt, ...
}
val = Py_VaBuildValue(valfmt, cvals); /* convert input to Python */
va_end(cvals);
if (val == NULL)
if (val == NULL)
return -1;
result = PyObject_SetAttrString(module, varname, val);
result = PyObject_SetAttrString(module, varname, val);
Py_DECREF(val); /* set global module var */
return result; /* decref val: var owns it */
} /* 0=success, varname set */
/*****************************************************************************
* MODULE INTERFACE
* MODULE INTERFACE
* make/import/reload a python module by name
* Note that Make_Dummy_Module could be implemented to keep a table
* of generated dictionaries to be used as namespaces, rather than
* using low level tools to create and mark real modules; this
* of generated dictionaries to be used as namespaces, rather than
* using low level tools to create and mark real modules; this
* approach would require extra logic to manage and use the table;
* see basic example of using dictionaries for string namespaces;
*****************************************************************************/
@@ -443,10 +444,10 @@ PP_Make_Dummy_Module(const char *modname) /* namespace for strings, if no file
Py_Initialize();
module = PyImport_AddModule(modname); /* fetch or make, no load */
if (module == NULL) /* module not incref'd */
return -1;
return -1;
else { /* module.__dict__ */
dict = PyModule_GetDict(module); /* ['__dummy__'] = None */
PyDict_SetItemString(dict, "__dummy__", Py_None);
PyDict_SetItemString(dict, "__dummy__", Py_None);
PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins());
return 0;
}
@@ -456,15 +457,15 @@ PP_Make_Dummy_Module(const char *modname) /* namespace for strings, if no file
PyObject * /* returns module object named modname */
PP_Load_Module(const char *modname) /* modname can be "package.module" form */
{ /* reload just resets C extension mods */
/*
/*
* 4 cases:
* - module "__main__" has no file, and not prebuilt: fetch or make
* - dummy modules have no files: don't try to reload them
* - reload=on and already loaded (on sys.modules): "reload()" before use
* - not loaded yet, or loaded but reload=off: "import" to fetch or load
* - not loaded yet, or loaded but reload=off: "import" to fetch or load
*/
PyObject *module = NULL, *sysmods = NULL;
PyObject *module = NULL, *sysmods = NULL;
modname = PP_Init(modname); /* default to __main__ */
if (strcmp(modname, "__main__") == 0) /* main: no file */
@@ -472,9 +473,9 @@ PP_Load_Module(const char *modname) /* modname can be "package.module" for
sysmods = PyImport_GetModuleDict(); /* get sys.modules dict */
module = PyDict_GetItemString(sysmods, modname); /* mod in sys.modules? */
if (module != NULL && /* dummy: no file */
PyModule_Check(module) &&
PyModule_Check(module) &&
PyDict_GetItemString(PyModule_GetDict(module), "__dummy__")) {
return module; /* not increfd */
}
@@ -484,7 +485,7 @@ PP_Load_Module(const char *modname) /* modname can be "package.module" for
Py_XDECREF(module); /* still on sys.modules */
return module; /* not increfd */
}
else {
else {
module = PyImport_ImportModule(modname); /* fetch or load module */
Py_XDECREF(module); /* still on sys.modules */
return module; /* not increfd */
@@ -521,11 +522,11 @@ PP_Run_Command_Line(const char *prompt)
}
/*****************************************************************************
* RUN EMBEDDED CODE-STRINGS
* RUN EMBEDDED CODE-STRINGS
* handles debugging, module (re)loading, namespaces, output conversions;
* pbd.runeval returns a value: "eval(expr + '\n', globals, locals)";
* pdb.run is just a statement: "exec cmd + '\n' in globals, locals"
* New tools: precompiling strings to bytecode, running bytecode;
* New tools: precompiling strings to bytecode, running bytecode;
*****************************************************************************/
@@ -547,9 +548,9 @@ PP_Run_Codestr(PPStringModes mode, const char *code, /* expr or stmt string */
return -1;
parse_mode = (mode == PP_EXPRESSION ? Py_eval_input : Py_file_input);
if (PP_DEBUG)
if (PP_DEBUG)
presult = PP_Debug_Codestr(mode, code, dict); /* run in pdb */
else
else
presult = PyRun_String(code, parse_mode, dict, dict); /* eval direct */
/* increfs res */
if (mode == PP_STATEMENT) {
@@ -605,11 +606,11 @@ PP_Run_Bytecode(PyObject *codeobj, /* run compiled bytecode object */
/**************************************************************************
* subtle things:
* 1) pdb.run and pdb.runeval both accept either a string or a
* compiled code object, just because they call the built in exec and
* compiled code object, just because they call the built in exec and
* eval(), which allow either form; further, eval() works on code
* objects compiled as either expressions or statements, but returns
* None as the result of statements, so we don't need to distinguish
* between expressions and statements here again for bytecode (we
* None as the result of statements, so we don't need to distinguish
* between expressions and statements here again for bytecode (we
* did when compiling); the equivalents in Python code:
* >>> a = 1
* >>> s = compile('x = 1', '', 'exec')
@@ -618,7 +619,7 @@ PP_Run_Bytecode(PyObject *codeobj, /* run compiled bytecode object */
* 2
* >>> print eval(s)
* None
* on the other hand, we can't blindly use pdb.runeval when dealing
* on the other hand, we can't blindly use pdb.runeval when dealing
* with uncompiled strings, because eval() fails on statement strings;
*
* 2) in 1.5, if you debug a string or bytecode object in a module's
@@ -631,7 +632,7 @@ PP_Run_Bytecode(PyObject *codeobj, /* run compiled bytecode object */
**************************************************************************/
static void fixPdbRetval(PyObject *moddict)
static void fixPdbRetval(PyObject *moddict)
{ if (PyDict_DelItemString(moddict, "__return__")) PyErr_Clear(); }
@@ -646,7 +647,7 @@ PP_Debug_Codestr(PPStringModes mode, const char *codestring, PyObject *moddict)
res = PP_Run_Function( /* "pdb.run(stmt, gdict, ldict)" */
"pdb", pdbname, /* "pdb.runeval(expr, gdict, ldict)" */
"O", &presult,
"(sOO)", codestring, moddict, moddict);
"(sOO)", codestring, moddict, moddict);
return (res != 0) ? NULL : presult; /* return null or increfd object */
}
@@ -660,8 +661,8 @@ PP_Debug_Bytecode(PyObject *codeobject, PyObject *moddict)
res = PP_Run_Function( /* "pdb.runeval(codeobj, gdict, ldict)" */
"pdb", "runeval", /* accepts string|code, code=stmt|expr */
"O", &presult,
"(OOO)", codeobject, moddict, moddict);
"(OOO)", codeobject, moddict, moddict);
return (res != 0) ? NULL : presult; /* null if error in run_function */
}
// NOLINTEND
// clang-format on