@@ -2176,15 +2176,14 @@ char pypdffit2_redirect_stdout__name__[] = "redirect_stdout";
21762176PyObject * pypdffit2_redirect_stdout (PyObject *, PyObject *args)
21772177{
21782178 // instance of PyFileStreambuf which takes care of redirection
2179- PyObject *py_file = 0 ;
2180- int ok = PyArg_ParseTuple (args, " O" , &py_file);
2181- if (!ok) return 0 ;
2179+ PyObject *py_file = nullptr ;
2180+ if (!PyArg_ParseTuple (args, " O" , &py_file)) return nullptr ;
21822181 // check if py_file has write and flush attributes
21832182 if ( !PyObject_HasAttrString (py_file, " write" ) ||
21842183 !PyObject_HasAttrString (py_file, " flush" ) )
21852184 {
21862185 PyErr_SetString (PyExc_TypeError, " expected file-like argument" );
2187- return 0 ;
2186+ return nullptr ;
21882187 }
21892188 // create py_stdout_streambuf if necessary
21902189 if (!py_stdout_streambuf)
@@ -2195,38 +2194,8 @@ PyObject * pypdffit2_redirect_stdout(PyObject *, PyObject *args)
21952194 // on first redirection we need to assign new ostream to NS_PDFFIT2::pout
21962195 if (NS_PDFFIT2::pout == &std::cout)
21972196 {
2198- NS_PDFFIT2::pout = new ostream (py_stdout_streambuf);
2199- }
2200- Py_INCREF (Py_None);
2201- return Py_None;
2202- }
2203-
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;
2197+ NS_PDFFIT2::pout = new std::ostream (py_stdout_streambuf);
22212198 }
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-
22302199 Py_INCREF (Py_None);
22312200 return Py_None;
22322201}
0 commit comments