Skip to content

Commit cf665fd

Browse files
committed
added cxx and rewrote agg - fixed leak
svn path=/trunk/matplotlib/; revision=267
1 parent b53a129 commit cf665fd

21 files changed

+6566
-1022
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
New entries should be added at the top
22
------------------------------------------------------------
3+
2004-04-29 Added CXX and rewrote backend_agg using it; tracked down
4+
and fixed agg memory leak - JDH
5+
6+
2004-04-29 Added stem plot command - JDH
7+
38
2004-04-28 Fixed PS scaling and centering bug - JDH
49

510
2004-04-26 Fixed errorbar autoscale problem - JDH

CXX/Config.hxx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#ifndef __PyCXX_config_hh__
2+
#define __PyCXX_config_hh__
3+
4+
//
5+
// Microsoft VC++ 6.0 has no traits
6+
//
7+
#if defined( _MSC_VER )
8+
9+
# if _MSC_VER <= 1200
10+
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 0
11+
# else
12+
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
13+
# endif
14+
15+
#elif defined( __GNUC__ )
16+
# if __GNUC__ >= 3
17+
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 0
18+
# else
19+
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
20+
#endif
21+
22+
//
23+
// Assume all other compilers do
24+
//
25+
#else
26+
27+
// Macros to deal with deficiencies in compilers
28+
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
29+
#endif
30+
31+
#if STANDARD_LIBRARY_HAS_ITERATOR_TRAITS
32+
# define random_access_iterator_parent(itemtype) std::random_access_iterator<itemtype, int>
33+
#else
34+
# define random_access_iterator_parent(itemtype) std::iterator<std::random_access_iterator_tag,itemtype,int>
35+
#endif
36+
37+
//
38+
// Which C++ standard is in use?
39+
//
40+
#if defined( _MSC_VER )
41+
# if _MSC_VER <= 1200
42+
// MSVC++ 6.0
43+
# define PYCXX_ISO_CPP_LIB 0
44+
# define STR_STREAM <strstream>
45+
# define TEMPLATE_TYPENAME class
46+
# else
47+
# define PYCXX_ISO_CPP_LIB 1
48+
# define STR_STREAM <sstream>
49+
# define TEMPLATE_TYPENAME typename
50+
# endif
51+
#elif defined( __GNUC__ )
52+
# if __GNUC__ >= 3
53+
# define PYCXX_ISO_CPP_LIB 1
54+
# define STR_STREAM <sstream>
55+
# define TEMPLATE_TYPENAME typename
56+
# else
57+
# define PYCXX_ISO_CPP_LIB 0
58+
# define STR_STREAM <strstream>
59+
# define TEMPLATE_TYPENAME class
60+
# endif
61+
#endif
62+
63+
#if PYCXX_ISO_CPP_LIB
64+
# define STR_STREAM <sstream>
65+
# define OSTRSTREAM ostringstream
66+
# define EXPLICIT_TYPENAME typename
67+
# define EXPLICIT_CLASS class
68+
# define TEMPLATE_TYPENAME typename
69+
#else
70+
# define STR_STREAM <strstream>
71+
# define OSTRSTREAM ostrstream
72+
# define EXPLICIT_TYPENAME
73+
# define EXPLICIT_CLASS
74+
# define TEMPLATE_TYPENAME class
75+
#endif
76+
77+
78+
#endif // __PyCXX_config_hh__

CXX/Exception.hxx

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
//----------------------------------*-C++-*----------------------------------//
2+
// Copyright 1998 The Regents of the University of California.
3+
// All rights reserved. See LEGAL.LLNL for full text and disclaimer.
4+
//---------------------------------------------------------------------------//
5+
6+
#ifndef __CXX_Exception_h
7+
#define __CXX_Exception_h
8+
9+
#include "Python.h"
10+
#include "CXX/Config.hxx"
11+
#include "CXX/IndirectPythonInterface.hxx"
12+
13+
#include <string>
14+
#include <iostream>
15+
16+
// This mimics the Python structure, in order to minimize confusion
17+
namespace Py
18+
{
19+
class ExtensionExceptionType;
20+
21+
class Exception
22+
{
23+
public:
24+
Exception( ExtensionExceptionType &exception, const std::string& reason );
25+
26+
explicit Exception ()
27+
{}
28+
29+
Exception (const std::string& reason)
30+
{
31+
PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str());
32+
}
33+
34+
Exception (PyObject* exception, const std::string& reason)
35+
{
36+
PyErr_SetString (exception, reason.c_str());
37+
}
38+
39+
40+
void clear() // clear the error
41+
// technically but not philosophically const
42+
{
43+
PyErr_Clear();
44+
}
45+
};
46+
47+
48+
// Abstract
49+
class StandardError: public Exception
50+
{
51+
protected:
52+
explicit StandardError()
53+
{}
54+
};
55+
56+
class LookupError: public StandardError
57+
{
58+
protected:
59+
explicit LookupError()
60+
{}
61+
};
62+
63+
class ArithmeticError: public StandardError
64+
{
65+
protected:
66+
explicit ArithmeticError()
67+
{}
68+
};
69+
70+
class EnvironmentError: public StandardError
71+
{
72+
protected:
73+
explicit EnvironmentError()
74+
{}
75+
};
76+
77+
// Concrete
78+
79+
class TypeError: public StandardError
80+
{
81+
public:
82+
TypeError (const std::string& reason)
83+
: StandardError()
84+
{
85+
PyErr_SetString (Py::_Exc_TypeError(),reason.c_str());
86+
}
87+
};
88+
89+
class IndexError: public LookupError
90+
{
91+
public:
92+
IndexError (const std::string& reason)
93+
: LookupError()
94+
{
95+
PyErr_SetString (Py::_Exc_IndexError(), reason.c_str());
96+
}
97+
};
98+
99+
class AttributeError: public StandardError
100+
{
101+
public:
102+
AttributeError (const std::string& reason)
103+
: StandardError()
104+
{
105+
PyErr_SetString (Py::_Exc_AttributeError(), reason.c_str());
106+
}
107+
};
108+
109+
class NameError: public StandardError
110+
{
111+
public:
112+
NameError (const std::string& reason)
113+
: StandardError()
114+
{
115+
PyErr_SetString (Py::_Exc_NameError(), reason.c_str());
116+
}
117+
};
118+
119+
class RuntimeError: public StandardError
120+
{
121+
public:
122+
RuntimeError (const std::string& reason)
123+
: StandardError()
124+
{
125+
PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str());
126+
}
127+
};
128+
129+
class SystemError: public StandardError
130+
{
131+
public:
132+
SystemError (const std::string& reason)
133+
: StandardError()
134+
{
135+
PyErr_SetString (Py::_Exc_SystemError(),reason.c_str());
136+
}
137+
};
138+
139+
class KeyError: public LookupError
140+
{
141+
public:
142+
KeyError (const std::string& reason)
143+
: LookupError()
144+
{
145+
PyErr_SetString (Py::_Exc_KeyError(),reason.c_str());
146+
}
147+
};
148+
149+
150+
class ValueError: public StandardError
151+
{
152+
public:
153+
ValueError (const std::string& reason)
154+
: StandardError()
155+
{
156+
PyErr_SetString (Py::_Exc_ValueError(), reason.c_str());
157+
}
158+
};
159+
160+
class OverflowError: public ArithmeticError
161+
{
162+
public:
163+
OverflowError (const std::string& reason)
164+
: ArithmeticError()
165+
{
166+
PyErr_SetString (Py::_Exc_OverflowError(), reason.c_str());
167+
}
168+
};
169+
170+
class ZeroDivisionError: public ArithmeticError
171+
{
172+
public:
173+
ZeroDivisionError (const std::string& reason)
174+
: ArithmeticError()
175+
{
176+
PyErr_SetString (Py::_Exc_ZeroDivisionError(), reason.c_str());
177+
}
178+
};
179+
180+
class FloatingPointError: public ArithmeticError
181+
{
182+
public:
183+
FloatingPointError (const std::string& reason)
184+
: ArithmeticError()
185+
{
186+
PyErr_SetString (Py::_Exc_FloatingPointError(), reason.c_str());
187+
}
188+
};
189+
190+
class MemoryError: public StandardError
191+
{
192+
public:
193+
MemoryError (const std::string& reason)
194+
: StandardError()
195+
{
196+
PyErr_SetString (Py::_Exc_MemoryError(), reason.c_str());
197+
}
198+
};
199+
200+
class SystemExit: public StandardError
201+
{
202+
public:
203+
SystemExit (const std::string& reason)
204+
: StandardError()
205+
{
206+
PyErr_SetString (Py::_Exc_SystemExit(),reason.c_str());
207+
}
208+
};
209+
210+
}// Py
211+
212+
#endif

0 commit comments

Comments
 (0)