tparse: Enable compilation on gcc 3.x, sacrificing compatibility with gcc 2.x.
* tparse/tparse.h: #include <strstream>, not <strstream.h>, and add "using namespace std;". * tparse/tparsemodule.cpp: Do not #include <stdiostream.h>. If a version of GNU C++ with the stdio_filebuf extension to the STL is detected, then use it to allow the passing of a filehandle from Python to the parser. Otherwise, throw a NotImplementedError when a filehandle is passed. git-svn-id: http://viewvc.tigris.org/svn/viewvc/trunk@1033 8cb11bc2-c004-0410-86c3-e597b4017df7remotes/tags/1.0.0-rc1
parent
fd5acb4930
commit
af6dbf5ecd
|
@ -34,13 +34,15 @@
|
|||
#ifndef __PARSE_H
|
||||
#define __PARSE_H
|
||||
#include <iostream.h>
|
||||
#include <strstream.h>
|
||||
#include <strstream>
|
||||
#include <stdio.h>
|
||||
#include <fstream.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#define delstr(a) if (a != NULL) { delete [] a; a=NULL; };
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* This class represents a exception that occured during the parsing
|
||||
of a file */
|
||||
class RCSParseError
|
||||
|
|
|
@ -31,10 +31,18 @@
|
|||
Version: $Id$
|
||||
*/
|
||||
#include <Python.h>
|
||||
#include <stdiostream.h>
|
||||
#include "tparsemodule.h"
|
||||
#include "tparse.cpp"
|
||||
|
||||
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
|
||||
#include <memory> // for auto_ptr
|
||||
#include <ext/stdio_filebuf.h>
|
||||
typedef __gnu_cxx::stdio_filebuf<char> stdio_filebuf;
|
||||
#define GNUC_STDIO_FILEBUF_AVAILABLE
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
static PyMethodDef tparseMethods[] = {
|
||||
{"parse", tparse, METH_VARARGS, tparse__doc__},
|
||||
{NULL, NULL} /* Sentinel */
|
||||
|
@ -270,17 +278,26 @@ static PyObject * tparse( PyObject *self, PyObject *args)
|
|||
istream *input;
|
||||
PyObject *file = NULL;
|
||||
PyObject *hsink;
|
||||
#ifdef GNUC_STDIO_FILEBUF_AVAILABLE
|
||||
auto_ptr<streambuf> rdbuf;
|
||||
#endif
|
||||
|
||||
if (PyArg_ParseTuple(args, "sO!", &filename, &PyInstance_Type, &hsink))
|
||||
input = new ifstream(filename, ios::nocreate | ios::in);
|
||||
input = new ifstream(filename, ios::in);
|
||||
else if (PyArg_ParseTuple(args, "O!O!", &PyFile_Type, &file,
|
||||
&PyInstance_Type, &hsink))
|
||||
{
|
||||
PyErr_Clear(); // Reset the exception PyArg_ParseTuple has raised.
|
||||
input = new istdiostream(PyFile_AsFile(file));
|
||||
((istdiostream *)input)->buffered(1);
|
||||
// We need buffering as because otherwise, it reads the file 4096
|
||||
// bytes at a time, with no readahead.
|
||||
#ifdef GNUC_STDIO_FILEBUF_AVAILABLE
|
||||
rdbuf.reset(new stdio_filebuf(PyFile_AsFile(file), ios::in | ios::binary));
|
||||
input = new istream(rdbuf.get());
|
||||
#else
|
||||
PyErr_SetString(PyExc_NotImplementedError,
|
||||
"tparse only implements the parsing of filehandles "
|
||||
"when compiled with GNU C++ version 3.1 or later - "
|
||||
"please pass a filename instead");
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in New Issue