3939#include " pythonCmdInputWidget.h"
4040
4141#include < QCoreApplication>
42+ #include < cstddef>
43+ #include < functional>
4244#include < map>
4345#include < memory>
46+ #include < string>
4447
4548#include " gui/gui.h"
4649#include " ord/OpenRoad.hh"
@@ -51,21 +54,21 @@ namespace gui {
5154// https://stackoverflow.com/questions/4307187/how-to-catch-python-stdout-in-c-code/8335297#8335297
5255namespace emb {
5356
54- typedef std::function<void (std::string)> stdout_write_type ;
57+ using stdout_write_type = std::function<void (std::string)>;
5558
5659struct Stdout
5760{
5861 PyObject_HEAD stdout_write_type write;
5962};
6063
61- PyObject* Stdout_write (PyObject* self, PyObject* args)
64+ static PyObject* Stdout_write (PyObject* self, PyObject* args)
6265{
6366 std::size_t written (0 );
6467 Stdout* selfimpl = reinterpret_cast <Stdout*>(self);
6568 if (selfimpl->write ) {
6669 char * data;
6770 if (!PyArg_ParseTuple (args, " s" , &data)) {
68- return 0 ;
71+ return nullptr ;
6972 }
7073
7174 std::string str (data);
@@ -75,56 +78,56 @@ PyObject* Stdout_write(PyObject* self, PyObject* args)
7578 return PyLong_FromSize_t (written);
7679}
7780
78- PyObject* Stdout_flush (PyObject* self, PyObject* args)
81+ static PyObject* Stdout_flush (PyObject* self, PyObject* args)
7982{
8083 // no-op
8184 return Py_BuildValue (" " );
8285}
8386
84- PyMethodDef Stdout_methods[] = {
87+ static PyMethodDef Stdout_methods[] = {
8588 {" write" , Stdout_write, METH_VARARGS, " sys.stdout.write" },
8689 {" flush" , Stdout_flush, METH_VARARGS, " sys.stdout.flush" },
87- {0 , 0 , 0 , 0 } // sentinel
90+ {nullptr , nullptr , 0 , nullptr } // sentinel
8891};
8992
90- PyTypeObject StdoutType = {
93+ static PyTypeObject StdoutType = {
9194 PyVarObject_HEAD_INIT (0 , 0 ) " emb.StdoutType" , /* tp_name */
9295 sizeof (Stdout), /* tp_basicsize */
9396 0 , /* tp_itemsize */
94- 0 , /* tp_dealloc */
97+ nullptr , /* tp_dealloc */
9598 0 , /* tp_print */
96- 0 , /* tp_getattr */
97- 0 , /* tp_setattr */
98- 0 , /* tp_reserved */
99- 0 , /* tp_repr */
100- 0 , /* tp_as_number */
101- 0 , /* tp_as_sequence */
102- 0 , /* tp_as_mapping */
103- 0 , /* tp_hash */
104- 0 , /* tp_call */
105- 0 , /* tp_str */
106- 0 , /* tp_getattro */
107- 0 , /* tp_setattro */
108- 0 , /* tp_as_buffer */
99+ nullptr , /* tp_getattr */
100+ nullptr , /* tp_setattr */
101+ nullptr , /* tp_reserved */
102+ nullptr , /* tp_repr */
103+ nullptr , /* tp_as_number */
104+ nullptr , /* tp_as_sequence */
105+ nullptr , /* tp_as_mapping */
106+ nullptr , /* tp_hash */
107+ nullptr , /* tp_call */
108+ nullptr , /* tp_str */
109+ nullptr , /* tp_getattro */
110+ nullptr , /* tp_setattro */
111+ nullptr , /* tp_as_buffer */
109112 Py_TPFLAGS_DEFAULT, /* tp_flags */
110113 " emb.Stdout objects" , /* tp_doc */
111- 0 , /* tp_traverse */
112- 0 , /* tp_clear */
113- 0 , /* tp_richcompare */
114+ nullptr , /* tp_traverse */
115+ nullptr , /* tp_clear */
116+ nullptr , /* tp_richcompare */
114117 0 , /* tp_weaklistoffset */
115- 0 , /* tp_iter */
116- 0 , /* tp_iternext */
118+ nullptr , /* tp_iter */
119+ nullptr , /* tp_iternext */
117120 Stdout_methods, /* tp_methods */
118- 0 , /* tp_members */
119- 0 , /* tp_getset */
120- 0 , /* tp_base */
121- 0 , /* tp_dict */
122- 0 , /* tp_descr_get */
123- 0 , /* tp_descr_set */
121+ nullptr , /* tp_members */
122+ nullptr , /* tp_getset */
123+ nullptr , /* tp_base */
124+ nullptr , /* tp_dict */
125+ nullptr , /* tp_descr_get */
126+ nullptr , /* tp_descr_set */
124127 0 , /* tp_dictoffset */
125- 0 , /* tp_init */
126- 0 , /* tp_alloc */
127- 0 , /* tp_new */
128+ nullptr , /* tp_init */
129+ nullptr , /* tp_alloc */
130+ nullptr , /* tp_new */
128131};
129132
130133PyModuleDef embmodule = {
@@ -146,8 +149,9 @@ std::map<std::string, StreamPair> streams;
146149PyMODINIT_FUNC PyInit_emb (void )
147150{
148151 StdoutType.tp_new = PyType_GenericNew;
149- if (PyType_Ready (&StdoutType) < 0 )
152+ if (PyType_Ready (&StdoutType) < 0 ) {
150153 return 0 ;
154+ }
151155
152156 PyObject* m = PyModule_Create (&embmodule);
153157 if (m) {
0 commit comments