File tree Expand file tree Collapse file tree
src/extensions/pdffit2module Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -330,6 +330,10 @@ struct PyMethodDef pypdffit2_methods[] = {
330330 {pypdffit2_redirect_stdout__name__, pypdffit2_redirect_stdout,
331331 METH_VARARGS, pypdffit2_redirect_stdout__doc__},
332332
333+ // restore_stdout
334+ {pypdffit2_restore_stdout__name__, pypdffit2_restore_stdout,
335+ METH_VARARGS, pypdffit2_restore_stdout__doc__},
336+
333337 // is_element
334338 {pypdffit2_is_element__name__, pypdffit2_is_element,
335339 METH_VARARGS, pypdffit2_is_element__doc__},
Original file line number Diff line number Diff line change @@ -2201,6 +2201,36 @@ PyObject * pypdffit2_redirect_stdout(PyObject *, PyObject *args)
22012201 return Py_None;
22022202}
22032203
2204+ // restore_stdout
2205+ char pypdffit2_restore_stdout__doc__[] =
2206+ " Restore engine output to the default stream (std::cout)." ;
2207+ char pypdffit2_restore_stdout__name__[] =
2208+ " restore_stdout" ;
2209+
2210+ PyObject * pypdffit2_restore_stdout (PyObject *, PyObject *args)
2211+ {
2212+ // no arguments.
2213+ if (!PyArg_ParseTuple (args, " " ))
2214+ return 0 ;
2215+
2216+ // If the global output stream pointer is not std::cout, then delete the custom stream.
2217+ if (NS_PDFFIT2::pout != &std::cout)
2218+ {
2219+ delete NS_PDFFIT2::pout;
2220+ NS_PDFFIT2::pout = &std::cout;
2221+ }
2222+
2223+ // Clean up the custom stream buffer
2224+ if (py_stdout_streambuf)
2225+ {
2226+ delete py_stdout_streambuf;
2227+ py_stdout_streambuf = nullptr ;
2228+ }
2229+
2230+ Py_INCREF (Py_None);
2231+ return Py_None;
2232+ }
2233+
22042234// is_element
22052235char pypdffit2_is_element__doc__[] = " Check if element or isotope is defined in the built-in periodic table." ;
22062236char pypdffit2_is_element__name__[] = " is_element" ;
Original file line number Diff line number Diff line change @@ -477,6 +477,12 @@ extern char pypdffit2_redirect_stdout__name__[];
477477extern "C"
478478PyObject * pypdffit2_redirect_stdout (PyObject * , PyObject * );
479479
480+ // restore_stdout
481+ extern char pypdffit2_restore_stdout__doc__ [];
482+ extern char pypdffit2_restore_stdout__name__ [];
483+ extern "C"
484+ PyObject * pypdffit2_restore_stdout (PyObject * , PyObject * );
485+
480486// is_element
481487extern char pypdffit2_is_element__doc__ [];
482488extern char pypdffit2_is_element__name__ [];
You can’t perform that action at this time.
0 commit comments