|
From: <md...@us...> - 2010-07-14 13:51:21
|
Revision: 8548
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8548&view=rev
Author: mdboom
Date: 2010-07-14 13:51:15 +0000 (Wed, 14 Jul 2010)
Log Message:
-----------
Merged revisions 8547 via svnmerge from
https://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib
........
r8547 | mdboom | 2010-07-14 09:50:41 -0400 (Wed, 14 Jul 2010) | 1 line
Testing merging
........
Modified Paths:
--------------
branches/py3k/README.txt
Property Changed:
----------------
branches/py3k/
Property changes on: branches/py3k
___________________________________________________________________
Modified: svnmerge-integrated
- /branches/mathtex:1-7263 /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7253 /branches/v1_0_maint:1-8541,8543 /trunk/matplotlib:1-8544
+ /branches/mathtex:1-7263 /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7253 /branches/v1_0_maint:1-8541,8543 /trunk/matplotlib:1-8547
Modified: branches/py3k/README.txt
===================================================================
--- branches/py3k/README.txt 2010-07-14 13:50:41 UTC (rev 8547)
+++ branches/py3k/README.txt 2010-07-14 13:51:15 UTC (rev 8548)
@@ -43,3 +43,4 @@
See also
<http://matplotlib.sourceforge.net/users/customizing.html>
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2010-07-14 20:02:32
|
Revision: 8551
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8551&view=rev
Author: mdboom
Date: 2010-07-14 20:02:25 +0000 (Wed, 14 Jul 2010)
Log Message:
-----------
C/C++ compiling (not necessarily working) with Py3K
Modified Paths:
--------------
branches/py3k/lib/matplotlib/__init__.py
branches/py3k/lib/matplotlib/backends/backend_ps.py
branches/py3k/lib/matplotlib/cbook.py
branches/py3k/lib/matplotlib/delaunay/_delaunay.cpp
branches/py3k/lib/matplotlib/texmanager.py
branches/py3k/lib/matplotlib/tri/_tri.cpp
branches/py3k/setup.py
branches/py3k/setupext.py
branches/py3k/src/_backend_agg.cpp
branches/py3k/src/_image.cpp
branches/py3k/src/_path.cpp
branches/py3k/src/_png.cpp
branches/py3k/src/_ttconv.cpp
branches/py3k/src/cntr.c
branches/py3k/src/ft2font.cpp
branches/py3k/src/nxutils.c
Modified: branches/py3k/lib/matplotlib/__init__.py
===================================================================
--- branches/py3k/lib/matplotlib/__init__.py 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/lib/matplotlib/__init__.py 2010-07-14 20:02:25 UTC (rev 8551)
@@ -132,13 +132,18 @@
import sys, os, tempfile
+if sys.hexversion >= 0x03000000:
+ def ascii(s): return bytes(s, 'ascii')
+else:
+ ascii = str
+
from matplotlib.rcsetup import (defaultParams,
validate_backend,
validate_toolbar,
validate_cairo_format)
major, minor1, minor2, s, tmp = sys.version_info
-_python24 = major>=2 and minor1>=4
+_python24 = (major == 2 and minor1 >= 4) or major >= 3
# the havedate check was a legacy from old matplotlib which preceeded
# datetime support
@@ -174,7 +179,7 @@
except TypeError: return False
try:
t = tempfile.TemporaryFile(dir=p)
- t.write('1')
+ t.write(ascii('1'))
t.close()
except OSError: return False
else: return True
Modified: branches/py3k/lib/matplotlib/backends/backend_ps.py
===================================================================
--- branches/py3k/lib/matplotlib/backends/backend_ps.py 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/lib/matplotlib/backends/backend_ps.py 2010-07-14 20:02:25 UTC (rev 8551)
@@ -1331,7 +1331,7 @@
else: angle = 0
if rcParams['text.latex.unicode']:
- unicode_preamble = """\usepackage{ucs}
+ unicode_preamble = r"""\usepackage{ucs}
\usepackage[utf8x]{inputenc}"""
else:
unicode_preamble = ''
Modified: branches/py3k/lib/matplotlib/cbook.py
===================================================================
--- branches/py3k/lib/matplotlib/cbook.py 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/lib/matplotlib/cbook.py 2010-07-14 20:02:25 UTC (rev 8551)
@@ -13,7 +13,10 @@
import os.path
import random
import urllib2
-import new
+if sys.hexversion > 0x03000000:
+ import types
+else:
+ import new
import matplotlib
@@ -180,7 +183,10 @@
raise ReferenceError
elif self.inst is not None:
# build a new instance method with a strong reference to the instance
- mtd = new.instancemethod(self.func, self.inst(), self.klass)
+ if sys.hexversion >= 0x03000000:
+ mtd = types.MethodType(self.func, self.inst(), self.klass)
+ else:
+ mtd = new.instancemethod(self.func, self.inst(), self.klass)
else:
# not a bound method, just return the func
mtd = self.func
Modified: branches/py3k/lib/matplotlib/delaunay/_delaunay.cpp
===================================================================
--- branches/py3k/lib/matplotlib/delaunay/_delaunay.cpp 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/lib/matplotlib/delaunay/_delaunay.cpp 2010-07-14 20:02:25 UTC (rev 8551)
@@ -726,16 +726,40 @@
{NULL, NULL, 0, NULL}
};
+#if PY_MAJOR_VERSION >= 3
+static PyModuleDef delaunay_module = {
+ PyModuleDef_HEAD_INIT,
+ "_delaunay",
+ "Tools for computing the Delaunay triangulation and some operations on it.\n",
+ -1,
+ delaunay_methods,
+ NULL, NULL, NULL, NULL
+};
+PyMODINIT_FUNC
+PyInit__delaunay(void)
+{
+ PyObject* m;
+ // import_array():
+
+ m = PyModule_Create(&delaunay_module);
+ if (m == NULL)
+ return NULL;
+
+ return m;
+}
+#else
PyMODINIT_FUNC init_delaunay(void)
{
PyObject* m;
+ import_array();
+
m = Py_InitModule3("_delaunay", delaunay_methods,
"Tools for computing the Delaunay triangulation and some operations on it.\n"
);
if (m == NULL)
return;
- import_array();
}
+#endif
} // extern "C"
Modified: branches/py3k/lib/matplotlib/texmanager.py
===================================================================
--- branches/py3k/lib/matplotlib/texmanager.py 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/lib/matplotlib/texmanager.py 2010-07-14 20:02:25 UTC (rev 8551)
@@ -236,7 +236,7 @@
tex = fontcmd % tex
if rcParams['text.latex.unicode']:
- unicode_preamble = """\usepackage{ucs}
+ unicode_preamble = r"""\usepackage{ucs}
\usepackage[utf8x]{inputenc}"""
else:
unicode_preamble = ''
@@ -288,7 +288,7 @@
tex = fontcmd % tex
if rcParams['text.latex.unicode']:
- unicode_preamble = """\usepackage{ucs}
+ unicode_preamble = r"""\usepackage{ucs}
\usepackage[utf8x]{inputenc}"""
else:
unicode_preamble = ''
Modified: branches/py3k/lib/matplotlib/tri/_tri.cpp
===================================================================
--- branches/py3k/lib/matplotlib/tri/_tri.cpp 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/lib/matplotlib/tri/_tri.cpp 2010-07-14 20:02:25 UTC (rev 8551)
@@ -980,19 +980,21 @@
-
-#if defined(_MSC_VER)
-DL_EXPORT(void)
-#elif defined(__cplusplus)
-extern "C" void
+#if PY_MAJOR_VERSION >= 3
+PyMODINIT_FUNC
+PyInit__tri(void)
#else
-void
+PyMODINIT_FUNC
+init_tri(void)
#endif
-init_tri()
{
static TriModule* triModule = NULL;
triModule = new TriModule();
import_array();
+
+ #if PY_MAJOR_VERSION >= 3
+ return triModule->module().ptr();
+ #endif
}
TriModule::TriModule()
Modified: branches/py3k/setup.py
===================================================================
--- branches/py3k/setup.py 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/setup.py 2010-07-14 20:02:25 UTC (rev 8551)
@@ -33,6 +33,10 @@
import glob
from distutils.core import setup
+try:
+ from distutils.command.build_py import build_py_2to3 as build_py
+except ImportError:
+ from distutils.command.build_py import build_py
from setupext import build_agg, build_gtkagg, build_tkagg, build_wxagg,\
build_macosx, build_ft2font, build_image, build_windowing, build_path, \
build_contour, build_delaunay, build_nxutils, build_gdk, \
@@ -288,5 +292,6 @@
ext_modules = ext_modules,
package_dir = {'': 'lib'},
package_data = package_data,
+ cmdclass = {'build_py': build_py},
**additional_params
)
Modified: branches/py3k/setupext.py
===================================================================
--- branches/py3k/setupext.py 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/setupext.py 2010-07-14 20:02:25 UTC (rev 8551)
@@ -136,7 +136,8 @@
defines = [
('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API'),
- ('PYCXX_ISO_CPP_LIB', '1')]
+ ('PYCXX_ISO_CPP_LIB', '1'),
+ ('PYCXX_PYTHON_2TO3', '1')]
# Based on the contents of setup.cfg, determine the build options
if os.path.exists("setup.cfg"):
Modified: branches/py3k/src/_backend_agg.cpp
===================================================================
--- branches/py3k/src/_backend_agg.cpp 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/src/_backend_agg.cpp 2010-07-14 20:02:25 UTC (rev 8551)
@@ -103,7 +103,11 @@
BufferRegion::to_string(const Py::Tuple &args)
{
// owned=true to prevent memory leak
+ #if PY_MAJOR_VERSION >= 3
+ return Py::Bytes(PyBytes_FromStringAndSize((const char*)data, height*stride), true);
+ #else
return Py::String(PyString_FromStringAndSize((const char*)data, height*stride), true);
+ #endif
}
@@ -153,13 +157,21 @@
unsigned char tmp;
size_t i, j;
- PyObject* str = PyString_FromStringAndSize(
- (const char*)data, height * stride);
+ #if PY_MAJOR_VERSION >= 3
+ PyObject* str = PyBytes_FromStringAndSize((const char*)data, height * stride);
+ if (PyBytes_AsStringAndSize(str, (char**)&begin, &length))
+ {
+ throw Py::TypeError("Could not create memory for blit");
+ }
+ #else
+ PyObject* str = PyString_FromStringAndSize((const char*)data, height * stride);
if (PyString_AsStringAndSize(str, (char**)&begin, &length))
{
throw Py::TypeError("Could not create memory for blit");
}
+ #endif
+
pix = begin;
end = begin + (height * stride);
for (i = 0; i < (size_t)height; ++i)
@@ -201,7 +213,7 @@
GCAgg::_set_antialiased(const Py::Object& gc)
{
_VERBOSE("GCAgg::antialiased");
- isaa = Py::Int(gc.getAttr("_antialiased"));
+ isaa = gc.getAttr("_antialiased").as_bool();
}
@@ -1506,7 +1518,7 @@
if (check_snap)
{
- gc.isaa = bool(Py::Int(antialiaseds[i % Naa]));
+ gc.isaa = antialiaseds[i % Naa].as_bool();
transformed_path_t tpath(path, trans);
nan_removed_t nan_removed(tpath, true, has_curves);
@@ -1525,7 +1537,7 @@
}
else
{
- gc.isaa = bool(Py::Int(antialiaseds[i % Naa]));
+ gc.isaa = antialiaseds[i % Naa].as_bool();
transformed_path_t tpath(path, trans);
nan_removed_t nan_removed(tpath, true, has_curves);
@@ -1738,8 +1750,8 @@
Py::Object offsets_obj = args[5];
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[6].ptr());
Py::Object facecolors_obj = args[7];
- bool antialiased = (bool)Py::Int(args[8]);
- bool showedges = (bool)Py::Int(args[9]);
+ bool antialiased = args[8].as_bool();
+ bool showedges = args[9].as_bool();
bool free_edgecolors = false;
QuadMeshGenerator path_generator(mesh_width, mesh_height, coordinates.ptr());
@@ -1965,6 +1977,12 @@
FILE *fp = NULL;
bool close_file = false;
Py::Object py_fileobj = Py::Object(args[0]);
+
+ #if PY_MAJOR_VERSION >= 3
+ int fd = PyObject_AsFileDescriptor(py_fileobj.ptr());
+ PyErr_Clear();
+ #endif
+
if (py_fileobj.isString())
{
std::string fileName = Py::String(py_fileobj);
@@ -1980,6 +1998,15 @@
}
close_file = true;
}
+ #if PY_MAJOR_VERSION >= 3
+ else if (fd != -1)
+ {
+ if (write(fd, pixBuffer, NUMBYTES) != (ssize_t)NUMBYTES)
+ {
+ throw Py::RuntimeError("Error writing to file");
+ }
+ }
+ #else
else if (PyFile_CheckExact(py_fileobj.ptr()))
{
fp = PyFile_AsFile(py_fileobj.ptr());
@@ -1988,6 +2015,7 @@
throw Py::RuntimeError("Error writing to file");
}
}
+ #endif
else
{
PyObject* write_method = PyObject_GetAttrString(py_fileobj.ptr(),
@@ -2138,7 +2166,14 @@
int starth = Py::Int(args[1]);
int row_len = width * 4;
int start = row_len * starth + startw * 4;
+ /* PY3KTODO: Buffers are different */
+ #if PY_MAJOR_VERSION >= 3
+ return Py::asObject(PyByteArray_FromStringAndSize(
+ (const char *)pixBuffer + start,
+ row_len*height - start));
+ #else
return Py::asObject(PyBuffer_FromMemory(pixBuffer + start, row_len*height - start));
+ #endif
}
@@ -2294,8 +2329,8 @@
debug = 0;
}
- unsigned int width = (unsigned int)Py::Int(args[0]);
- unsigned int height = (unsigned int)Py::Int(args[1]);
+ unsigned int width = (int)Py::Int(args[0]);
+ unsigned int height = (int)Py::Int(args[1]);
double dpi = Py::Float(args[2]);
if (width > 1 << 15 || height > 1 << 15)
@@ -2388,8 +2423,13 @@
}
extern "C"
- DL_EXPORT(void)
- init_backend_agg(void)
+#if PY_MAJOR_VERSION >= 3
+PyMODINIT_FUNC
+PyInit__backend_agg(void)
+#else
+PyMODINIT_FUNC
+init_backend_agg(void)
+#endif
{
//static _backend_agg_module* _backend_agg = new _backend_agg_module;
@@ -2399,4 +2439,8 @@
static _backend_agg_module* _backend_agg = NULL;
_backend_agg = new _backend_agg_module;
+
+ #if PY_MAJOR_VERSION >= 3
+ return _backend_agg->module().ptr();
+ #endif
}
Modified: branches/py3k/src/_image.cpp
===================================================================
--- branches/py3k/src/_image.cpp 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/src/_image.cpp 2010-07-14 20:02:25 UTC (rev 8551)
@@ -223,9 +223,14 @@
args.verify_length(1);
int format = Py::Int(args[0]);
-
+ PyObject* py_buffer = NULL;
int row_len = colsOut * 4;
- PyObject* py_buffer = PyBuffer_New(row_len * rowsOut);
+#if PY_MAJOR_VERSION >= 3
+ unsigned char* buf = (unsigned char *)malloc(row_len * rowsOut);
+ if (buf == NULL)
+ throw Py::MemoryError("Image::color_conv could not allocate memory");
+#else
+ py_buffer = PyBuffer_New(row_len * rowsOut);
if (py_buffer == NULL)
throw Py::MemoryError("Image::color_conv could not allocate memory");
@@ -233,7 +238,11 @@
Py_ssize_t buffer_len;
int ret = PyObject_AsWriteBuffer(py_buffer, &buf, &buffer_len);
if (ret != 0)
+ {
+ Py_XDECREF(py_buffer);
throw Py::MemoryError("Image::color_conv could not allocate memory");
+ }
+#endif
agg::rendering_buffer rtmp;
rtmp.attach(reinterpret_cast<unsigned char*>(buf), colsOut, rowsOut,
@@ -248,9 +257,17 @@
agg::color_conv(&rtmp, rbufOut, agg::color_conv_rgba32_to_argb32());
break;
default:
+ Py_XDECREF(py_buffer);
throw Py::ValueError("Image::color_conv unknown format");
}
+#if PY_MAJOR_VERSION >= 3
+ py_buffer = PyByteArray_FromStringAndSize((char *)buf, row_len * rowsOut);
+ if (py_buffer == NULL) {
+ free(buf);
+ }
+#endif
+
PyObject* o = Py_BuildValue("llN", rowsOut, colsOut, py_buffer);
return Py::asObject(o);
}
@@ -1484,10 +1501,10 @@
Py::Object xp = args[0];
Py::Object yp = args[1];
Py::Object dp = args[2];
- unsigned int rows = Py::Int(args[3]);
- unsigned int cols = Py::Int(args[4]);
+ unsigned int rows = (unsigned long)Py::Int(args[3]);
+ unsigned int cols = (unsigned long)Py::Int(args[4]);
Py::Tuple bounds = args[5];
- unsigned int interpolation = Py::Int(args[6]);
+ unsigned int interpolation = (unsigned long)Py::Int(args[6]);
if (rows >= 32768 || cols >= 32768)
{
@@ -1881,17 +1898,13 @@
return Py::asObject(imo);
}
-
-
-#if defined(_MSC_VER)
-DL_EXPORT(void)
-#elif defined(__cplusplus)
-extern "C" void
+#if PY_MAJOR_VERSION >= 3
+PyMODINIT_FUNC
+PyInit__image(void)
#else
-void
+PyMODINIT_FUNC
+init_image(void)
#endif
-
-init_image(void)
{
_VERBOSE("init_image");
@@ -1920,6 +1933,10 @@
d["ASPECT_FREE"] = Py::Int(Image::ASPECT_FREE);
d["ASPECT_PRESERVE"] = Py::Int(Image::ASPECT_PRESERVE);
+
+#if PY_MAJOR_VERSION >= 3
+ return _image->module().ptr();
+#endif
}
Modified: branches/py3k/src/_path.cpp
===================================================================
--- branches/py3k/src/_path.cpp 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/src/_path.cpp 2010-07-14 20:02:25 UTC (rev 8551)
@@ -379,7 +379,7 @@
"Must pass Bbox object as arg 3 of update_path_extents");
}
Py::Object minpos_obj = args[3];
- bool ignore = bool(Py::Int(args[4]));
+ bool ignore = args[4].as_bool();
double xm, ym;
PyArrayObject* input_minpos = NULL;
@@ -599,7 +599,7 @@
Py::SeqBase<Py::Object> transforms_obj = args[5];
Py::SeqBase<Py::Object> offsets_obj = args[6];
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[7].ptr());
- bool filled = Py::Int(args[8]);
+ bool filled = args[8].as_bool();
PyArrayObject* offsets = (PyArrayObject*)PyArray_FromObject(
offsets_obj.ptr(), PyArray_DOUBLE, 0, 2);
@@ -926,7 +926,7 @@
PathIterator path(args[0]);
Py::Object bbox_obj = args[1];
- bool inside = Py::Int(args[2]);
+ bool inside = args[2].as_bool();
double x0, y0, x1, y1;
if (!py_convert_bbox(bbox_obj.ptr(), x0, y0, x1, y1))
@@ -1468,12 +1468,22 @@
return result;
}
+#if PY_MAJOR_VERSION >= 3
extern "C"
- DL_EXPORT(void)
- init_path(void)
+PyMODINIT_FUNC
+PyInit__path(void)
+#else
+extern "C"
+PyMODINIT_FUNC
+init_path(void)
+#endif
{
static _path_module* _path = NULL;
_path = new _path_module;
import_array();
+
+ #if PY_MAJOR_VERSION >= 3
+ return _path->module().ptr();
+ #endif
}
Modified: branches/py3k/src/_png.cpp
===================================================================
--- branches/py3k/src/_png.cpp 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/src/_png.cpp 2010-07-14 20:02:25 UTC (rev 8551)
@@ -91,6 +91,10 @@
}
Py::Object py_fileobj = Py::Object(args[3]);
+#if PY_MAJOR_VERSION >= 3
+ int fd = PyObject_AsFileDescriptor(py_fileobj.ptr());
+ PyErr_Clear();
+#endif
if (py_fileobj.isString())
{
std::string fileName = Py::String(py_fileobj);
@@ -102,10 +106,17 @@
}
close_file = true;
}
+#if PY_MAJOR_VERSION >= 3
+ else if (fd != -1)
+ {
+ fp = fdopen(fd, "w");
+ }
+#else
else if (PyFile_CheckExact(py_fileobj.ptr()))
{
fp = PyFile_AsFile(py_fileobj.ptr());
}
+#endif
else
{
PyObject* write_method = PyObject_GetAttrString(
@@ -224,7 +235,12 @@
{
result = PyObject_CallFunction(read_method, (char *)"i", length);
}
+#if PY_MAJOR_VERSION >= 3
+ PyObject* utf8_result = PyUnicode_AsUTF8String(result);
+ if (PyBytes_AsStringAndSize(utf8_result, &buffer, &bufflen) == 0)
+#else
if (PyString_AsStringAndSize(result, &buffer, &bufflen) == 0)
+#endif
{
if (bufflen == (Py_ssize_t)length)
{
@@ -251,6 +267,11 @@
bool close_file = false;
Py::Object py_fileobj = Py::Object(args[0]);
+#if PY_MAJOR_VERSION >= 3
+ int fd = PyObject_AsFileDescriptor(py_fileobj.ptr());
+ PyErr_Clear();
+#endif
+
if (py_fileobj.isString())
{
std::string fileName = Py::String(py_fileobj);
@@ -262,10 +283,16 @@
}
close_file = true;
}
+#if PY_MAJOR_VERSION >= 3
+ else if (fd != -1) {
+ fp = fdopen(fd, "r");
+ }
+#else
else if (PyFile_CheckExact(py_fileobj.ptr()))
{
fp = PyFile_AsFile(py_fileobj.ptr());
}
+#endif
else
{
PyObject* read_method = PyObject_GetAttrString(py_fileobj.ptr(), "read");
@@ -455,11 +482,20 @@
}
extern "C"
- DL_EXPORT(void)
- init_png(void)
+#if PY_MAJOR_VERSION >= 3
+PyMODINIT_FUNC
+PyInit__png(void)
+#else
+PyMODINIT_FUNC
+init_png(void)
+#endif
{
import_array();
static _png_module* _png = NULL;
_png = new _png_module;
+
+#if PY_MAJOR_VERSION >= 3
+ return _png->module().ptr();
+#endif
}
Modified: branches/py3k/src/_ttconv.cpp
===================================================================
--- branches/py3k/src/_ttconv.cpp 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/src/_ttconv.cpp 2010-07-14 20:02:25 UTC (rev 8551)
@@ -84,7 +84,11 @@
PyObject* item;
while ((item = PyIter_Next(iterator)))
{
+ #if PY_MAJOR_VERSION >= 3
+ long value = PyLong_AsLong(item);
+ #else
long value = PyInt_AsLong(item);
+ #endif
Py_DECREF(item);
if (value == -1 && PyErr_Occurred())
{
@@ -167,7 +171,11 @@
virtual void add_pair(const char* a, const char* b)
{
+ #if PY_MAJOR_VERSION >= 3
+ PyObject* value = PyUnicode_FromString(b);
+ #else
PyObject* value = PyString_FromString(b);
+ #endif
if (value)
{
if (PyDict_SetItemString(_dict, a, value))
@@ -269,17 +277,36 @@
{0, 0, 0, 0} /* Sentinel */
};
-#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
-#define PyMODINIT_FUNC void
-#endif
+static const char* module_docstring =
+ "Module to handle converting and subsetting TrueType "
+ "fonts to Postscript Type 3, Postscript Type 42 and "
+ "Pdf Type 3 fonts.";
+
+#if PY_MAJOR_VERSION >= 3
+static PyModuleDef ttconv_module = {
+ PyModuleDef_HEAD_INIT,
+ "ttconv",
+ module_docstring,
+ -1,
+ ttconv_methods,
+ NULL, NULL, NULL, NULL
+};
+
PyMODINIT_FUNC
+PyInit_ttconv(void)
+{
+ PyObject* m;
+
+ m = PyModule_Create(&ttconv_module);
+
+ return m;
+}
+#else
+PyMODINIT_FUNC
initttconv(void)
{
PyObject* m;
- m = Py_InitModule3("ttconv", ttconv_methods,
- "Module to handle converting and subsetting TrueType "
- "fonts to Postscript Type 3, Postscript Type 42 and "
- "Pdf Type 3 fonts.");
+ m = Py_InitModule3("ttconv", ttconv_methods, module_docstring);
}
-
+#endif
Modified: branches/py3k/src/cntr.c
===================================================================
--- branches/py3k/src/cntr.c 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/src/cntr.c 2010-07-14 20:02:25 UTC (rev 8551)
@@ -1743,7 +1743,11 @@
Cntr_dealloc(Cntr* self)
{
Cntr_clear(self);
- self->ob_type->tp_free((PyObject*)self);
+ #if PY_MAJOR_VERSION >= 3
+ Py_TYPE(self)->tp_free((PyObject*)self);
+ #else
+ self->ob_type->tp_free((PyObject*)self);
+ #endif
}
static PyObject *
@@ -1913,8 +1917,12 @@
};
static PyTypeObject CntrType = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ #if PY_MAJOR_VERSION >= 3
+ PyVarObject_HEAD_INIT(NULL, 0)
+ #else
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ #endif
"cntr.Cntr", /*tp_name*/
sizeof(Cntr), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -1958,24 +1966,54 @@
{NULL} /* Sentinel */
};
+#if PY_MAJOR_VERSION >= 3
+static PyModuleDef cntr_module = {
+ PyModuleDef_HEAD_INIT,
+ "_cntr",
+ "Contouring engine as an extension type (numpy).",
+ -1,
+ module_methods,
+ NULL, NULL, NULL, NULL
+};
+
+#define ERROR_RETURN return NULL
+
PyMODINIT_FUNC
+PyInit__cntr(void)
+#else
+#define ERROR_RETURN return
+
+PyMODINIT_FUNC
init_cntr(void)
+#endif
{
PyObject* m;
- if (PyType_Ready(&CntrType) < 0)
- return;
+ if (PyType_Ready(&CntrType) < 0) {
+ ERROR_RETURN;
+ }
- m = Py_InitModule3("_cntr", module_methods,
- "Contouring engine as an extension type (numpy).");
+ #if PY_MAJOR_VERSION >= 3
+ m = PyModule_Create(&cntr_module);
+ #else
+ m = Py_InitModule3("_cntr", module_methods,
+ "Contouring engine as an extension type (numpy).");
+ #endif
- if (m == NULL)
- return;
+ if (m == NULL) {
+ ERROR_RETURN;
+ }
+
PyModule_AddIntConstant(m, "_slitkind", (long)kind_slit_up );
/* We can add all the point_kinds values later if we need them. */
import_array();
+
Py_INCREF(&CntrType);
PyModule_AddObject(m, "Cntr", (PyObject *)&CntrType);
+
+ #if PY_MAJOR_VERSION >= 3
+ return m;
+ #endif
}
Modified: branches/py3k/src/ft2font.cpp
===================================================================
--- branches/py3k/src/ft2font.cpp 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/src/ft2font.cpp 2010-07-14 20:02:25 UTC (rev 8551)
@@ -283,9 +283,11 @@
args.verify_length(0);
return Py::asObject
- (PyString_FromStringAndSize((const char *)_buffer,
- _width*_height)
- );
+#if PY_MAJOR_VERSION >= 3
+ (PyBytes_FromStringAndSize((const char *)_buffer, _width*_height));
+#else
+ (PyString_FromStringAndSize((const char *)_buffer, _width*_height));
+#endif
}
char FT2Image::as_array__doc__[] =
@@ -1513,7 +1515,7 @@
}
char buffer[128];
- if (FT_Get_Glyph_Name(face, (FT_UInt) Py::Int(args[0]), buffer, 128))
+ if (FT_Get_Glyph_Name(face, (FT_UInt) (unsigned long)Py::Int(args[0]), buffer, 128))
{
throw Py::RuntimeError("Could not get glyph names.");
}
@@ -2120,11 +2122,18 @@
#if defined(_MSC_VER)
DL_EXPORT(void)
#elif defined(__cplusplus)
-extern "C" void
+extern "C"
#else
void
#endif
+
+#if PY_MAJOR_VERSION >= 3
+PyMODINIT_FUNC
+PyInit_ft2font(void)
+#else
+PyMODINIT_FUNC
initft2font(void)
+#endif
{
static ft2font_module* ft2font = new ft2font_module;
import_array();
@@ -2178,6 +2187,10 @@
{
throw Py::RuntimeError("Could not find initialize the freetype2 library");
}
+
+ #if PY_MAJOR_VERSION >= 3
+ return ft2font->module().ptr();
+ #endif
}
ft2font_module::~ft2font_module()
Modified: branches/py3k/src/nxutils.c
===================================================================
--- branches/py3k/src/nxutils.c 2010-07-14 17:41:21 UTC (rev 8550)
+++ branches/py3k/src/nxutils.c 2010-07-14 20:02:25 UTC (rev 8551)
@@ -24,8 +24,8 @@
int i, j, c = 0;
for (i = 0, j = npol-1; i < npol; j = i++) {
if ((((yp[i]<=y) && (y<yp[j])) ||
- ((yp[j]<=y) && (y<yp[i]))) &&
- (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
+ ((yp[j]<=y) && (y<yp[i]))) &&
+ (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
c = !c;
}
@@ -50,7 +50,7 @@
if (verts == NULL)
{
PyErr_SetString(PyExc_ValueError,
- "Arguments verts must be a Nx2 array.");
+ "Arguments verts must be a Nx2 array.");
Py_XDECREF(verts);
return NULL;
@@ -61,7 +61,7 @@
if (verts->dimensions[1]!=2)
{
PyErr_SetString(PyExc_ValueError,
- "Arguments verts must be a Nx2 array.");
+ "Arguments verts must be a Nx2 array.");
Py_XDECREF(verts);
return NULL;
@@ -118,7 +118,7 @@
if (verts == NULL)
{
PyErr_SetString(PyExc_ValueError,
- "Argument verts must be a Nx2 array.");
+ "Argument verts must be a Nx2 array.");
Py_XDECREF(verts);
return NULL;
@@ -129,7 +129,7 @@
if (verts->dimensions[1]!=2)
{
PyErr_SetString(PyExc_ValueError,
- "Arguments verts must be a Nx2 array.");
+ "Arguments verts must be a Nx2 array.");
Py_XDECREF(verts);
return NULL;
@@ -163,7 +163,7 @@
if (xypoints == NULL)
{
PyErr_SetString(PyExc_ValueError,
- "Arguments xypoints must an Nx2 array.");
+ "Arguments xypoints must an Nx2 array.");
Py_XDECREF(verts);
Py_XDECREF(xypoints);
PyMem_Free(xv);
@@ -175,7 +175,7 @@
if (xypoints->dimensions[1]!=2)
{
PyErr_SetString(PyExc_ValueError,
- "Arguments xypoints must be a Nx2 array.");
+ "Arguments xypoints must be a Nx2 array.");
Py_XDECREF(verts);
Py_XDECREF(xypoints);
@@ -236,7 +236,7 @@
};
PyMODINIT_FUNC
- initnxutils(void)
+initnxutils(void)
{
PyObject* m;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2010-07-15 18:35:00
|
Revision: 8556
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8556&view=rev
Author: mdboom
Date: 2010-07-15 18:34:54 +0000 (Thu, 15 Jul 2010)
Log Message:
-----------
Fix compilation in Python 2.x
Modified Paths:
--------------
branches/py3k/setupext.py
branches/py3k/src/_backend_agg.cpp
branches/py3k/src/_path.cpp
Modified: branches/py3k/setupext.py
===================================================================
--- branches/py3k/setupext.py 2010-07-15 17:37:19 UTC (rev 8555)
+++ branches/py3k/setupext.py 2010-07-15 18:34:54 UTC (rev 8556)
@@ -136,9 +136,11 @@
defines = [
('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API'),
- ('PYCXX_ISO_CPP_LIB', '1'),
- ('PYCXX_PYTHON_2TO3', '1')]
+ ('PYCXX_ISO_CPP_LIB', '1')]
+if sys.hexversion >= 0x03000000:
+ defines.append(('PYCXX_PYTHON_2TO3', '1'))
+
# Based on the contents of setup.cfg, determine the build options
if os.path.exists("setup.cfg"):
config = configparser.SafeConfigParser()
Modified: branches/py3k/src/_backend_agg.cpp
===================================================================
--- branches/py3k/src/_backend_agg.cpp 2010-07-15 17:37:19 UTC (rev 8555)
+++ branches/py3k/src/_backend_agg.cpp 2010-07-15 18:34:54 UTC (rev 8556)
@@ -213,7 +213,7 @@
GCAgg::_set_antialiased(const Py::Object& gc)
{
_VERBOSE("GCAgg::antialiased");
- isaa = gc.getAttr("_antialiased").as_bool();
+ isaa = Py::Boolean(gc.getAttr("_antialiased"));
}
@@ -1518,7 +1518,7 @@
if (check_snap)
{
- gc.isaa = antialiaseds[i % Naa].as_bool();
+ gc.isaa = Py::Boolean(antialiaseds[i % Naa]);
transformed_path_t tpath(path, trans);
nan_removed_t nan_removed(tpath, true, has_curves);
@@ -1537,7 +1537,7 @@
}
else
{
- gc.isaa = antialiaseds[i % Naa].as_bool();
+ gc.isaa = Py::Boolean(antialiaseds[i % Naa]);
transformed_path_t tpath(path, trans);
nan_removed_t nan_removed(tpath, true, has_curves);
@@ -1750,8 +1750,8 @@
Py::Object offsets_obj = args[5];
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[6].ptr());
Py::Object facecolors_obj = args[7];
- bool antialiased = args[8].as_bool();
- bool showedges = args[9].as_bool();
+ bool antialiased = Py::Boolean(args[8]);
+ bool showedges = Py::Boolean(args[9]);
bool free_edgecolors = false;
QuadMeshGenerator path_generator(mesh_width, mesh_height, coordinates.ptr());
Modified: branches/py3k/src/_path.cpp
===================================================================
--- branches/py3k/src/_path.cpp 2010-07-15 17:37:19 UTC (rev 8555)
+++ branches/py3k/src/_path.cpp 2010-07-15 18:34:54 UTC (rev 8556)
@@ -379,7 +379,7 @@
"Must pass Bbox object as arg 3 of update_path_extents");
}
Py::Object minpos_obj = args[3];
- bool ignore = args[4].as_bool();
+ bool ignore = Py::Boolean(args[4]);
double xm, ym;
PyArrayObject* input_minpos = NULL;
@@ -599,7 +599,7 @@
Py::SeqBase<Py::Object> transforms_obj = args[5];
Py::SeqBase<Py::Object> offsets_obj = args[6];
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[7].ptr());
- bool filled = args[8].as_bool();
+ bool filled = Py::Boolean(args[8]);
PyArrayObject* offsets = (PyArrayObject*)PyArray_FromObject(
offsets_obj.ptr(), PyArray_DOUBLE, 0, 2);
@@ -926,7 +926,7 @@
PathIterator path(args[0]);
Py::Object bbox_obj = args[1];
- bool inside = args[2].as_bool();
+ bool inside = Py::Boolean(args[2]);
double x0, y0, x1, y1;
if (!py_convert_bbox(bbox_obj.ptr(), x0, y0, x1, y1))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2010-07-16 18:45:55
|
Revision: 8561
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8561&view=rev
Author: mdboom
Date: 2010-07-16 18:45:49 +0000 (Fri, 16 Jul 2010)
Log Message:
-----------
Able to produce simple_plot.py!!!
Modified Paths:
--------------
branches/py3k/examples/pylab_examples/simple_plot.py
branches/py3k/lib/matplotlib/artist.py
branches/py3k/lib/matplotlib/axes.py
branches/py3k/lib/matplotlib/backends/backend_agg.py
branches/py3k/lib/matplotlib/backends/tkagg.py
branches/py3k/lib/matplotlib/docstring.py
branches/py3k/lib/matplotlib/figure.py
branches/py3k/lib/matplotlib/font_manager.py
branches/py3k/lib/matplotlib/lines.py
branches/py3k/lib/matplotlib/mlab.py
branches/py3k/lib/matplotlib/patches.py
branches/py3k/lib/matplotlib/text.py
branches/py3k/setup.py
branches/py3k/setupext.py
branches/py3k/src/_backend_agg.cpp
branches/py3k/src/_png.cpp
Removed Paths:
-------------
branches/py3k/src/nxutils.c
Modified: branches/py3k/examples/pylab_examples/simple_plot.py
===================================================================
--- branches/py3k/examples/pylab_examples/simple_plot.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/examples/pylab_examples/simple_plot.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -8,4 +8,5 @@
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
+savefig("test.png")
show()
Modified: branches/py3k/lib/matplotlib/artist.py
===================================================================
--- branches/py3k/lib/matplotlib/artist.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/artist.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -481,7 +481,7 @@
:class:`~matplotlib.transforms.Transform`) |
:class:`~matplotlib.patches.Patch` | None ]
"""
- from patches import Patch, Rectangle
+ from matplotlib.patches import Patch, Rectangle
success = False
if transform is None:
Modified: branches/py3k/lib/matplotlib/axes.py
===================================================================
--- branches/py3k/lib/matplotlib/axes.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/axes.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -1,5 +1,5 @@
from __future__ import division, generators
-import math, sys, warnings, datetime, new
+import math, sys, warnings, datetime
from operator import itemgetter
import itertools
@@ -8400,9 +8400,15 @@
new_class = _subplot_classes.get(axes_class)
if new_class is None:
- new_class = new.classobj("%sSubplot" % (axes_class.__name__),
- (SubplotBase, axes_class),
- {'_axes_class': axes_class})
+ if sys.hexversion >= 0x03000000:
+ new_class = type("%sSubplot" % (axes_class.__name__),
+ (SubplotBase, axes_class),
+ {'_axes_class': axes_class})
+ else:
+ import new
+ new_class = new.classobj("%sSubplot" % (axes_class.__name__),
+ (SubplotBase, axes_class),
+ {'_axes_class': axes_class})
_subplot_classes[axes_class] = new_class
return new_class
Modified: branches/py3k/lib/matplotlib/backends/backend_agg.py
===================================================================
--- branches/py3k/lib/matplotlib/backends/backend_agg.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/backends/backend_agg.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -35,7 +35,7 @@
from matplotlib.path import Path
from matplotlib.transforms import Bbox, BboxBase
-from _backend_agg import RendererAgg as _RendererAgg
+from matplotlib.backends._backend_agg import RendererAgg as _RendererAgg
from matplotlib import _png
backend_version = 'v2.2'
@@ -429,7 +429,7 @@
original_dpi = renderer.dpi
renderer.dpi = self.figure.dpi
if is_string_like(filename_or_obj):
- filename_or_obj = file(filename_or_obj, 'wb')
+ filename_or_obj = open(filename_or_obj, 'wb')
renderer._renderer.write_rgba(filename_or_obj)
renderer.dpi = original_dpi
print_rgba = print_raw
@@ -440,7 +440,7 @@
original_dpi = renderer.dpi
renderer.dpi = self.figure.dpi
if is_string_like(filename_or_obj):
- filename_or_obj = file(filename_or_obj, 'wb')
+ filename_or_obj = open(filename_or_obj, 'wb')
_png.write_png(renderer._renderer.buffer_rgba(0, 0),
renderer.width, renderer.height,
filename_or_obj, self.figure.dpi)
Modified: branches/py3k/lib/matplotlib/backends/tkagg.py
===================================================================
--- branches/py3k/lib/matplotlib/backends/tkagg.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/backends/tkagg.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -1,4 +1,4 @@
-import _tkagg
+from matplotlib import _tkagg
import Tkinter as Tk
def blit(photoimage, aggimage, bbox=None, colormode=1):
Modified: branches/py3k/lib/matplotlib/docstring.py
===================================================================
--- branches/py3k/lib/matplotlib/docstring.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/docstring.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -1,29 +1,31 @@
from matplotlib import cbook
+import sys
+import types
class Substitution(object):
"""
A decorator to take a function's docstring and perform string
substitution on it.
-
+
This decorator should be robust even if func.__doc__ is None
(for example, if -OO was passed to the interpreter)
-
+
Usage: construct a docstring.Substitution with a sequence or
dictionary suitable for performing substitution; then
decorate a suitable function with the constructed object. e.g.
-
+
sub_author_name = Substitution(author='Jason')
-
+
@sub_author_name
def some_function(x):
"%(author)s wrote this function"
-
+
# note that some_function.__doc__ is now "Jason wrote this function"
-
+
One can also use positional arguments.
-
+
sub_first_last_names = Substitution('Edgar Allen', 'Poe')
-
+
@sub_first_last_names
def some_function(x):
"%s %s wrote the Raven"
@@ -56,16 +58,16 @@
"""
A function decorator that will append an addendum to the docstring
of the target function.
-
+
This decorator should be robust even if func.__doc__ is None
(for example, if -OO was passed to the interpreter).
-
+
Usage: construct a docstring.Appender with a string to be joined to
the original docstring. An optional 'join' parameter may be supplied
which will be used to join the docstring and addendum. e.g.
-
+
add_copyright = Appender("Copyright (c) 2009", join='\n')
-
+
@add_copyright
def my_dog(has='fleas'):
"This docstring will have a copyright below"
@@ -100,6 +102,8 @@
def dedent_interpd(func):
"""A special case of the interpd that first performs a dedent on
the incoming docstring"""
+ if isinstance(func, types.MethodType) and sys.hexversion <= 0x03000000:
+ func = func.im_func
return interpd(dedent(func))
def copy_dedent(source):
Modified: branches/py3k/lib/matplotlib/figure.py
===================================================================
--- branches/py3k/lib/matplotlib/figure.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/figure.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -17,7 +17,7 @@
from artist import Artist, allow_rasterization
from axes import Axes, SubplotBase, subplot_class_factory
from cbook import flatten, allequal, Stack, iterable, is_string_like
-import _image
+from matplotlib import _image
import colorbar as cbar
from image import FigureImage
from matplotlib import rcParams
Modified: branches/py3k/lib/matplotlib/font_manager.py
===================================================================
--- branches/py3k/lib/matplotlib/font_manager.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/font_manager.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -235,13 +235,12 @@
within them.
"""
fontpaths = []
- def add(arg,directory,files):
- fontpaths.append(directory)
for fontdir in OSXFontDirectories:
try:
if os.path.isdir(fontdir):
- os.path.walk(fontdir, add, None)
+ for root, dirs, files in os.walk(fontdir):
+ fontpaths.append(root)
except (IOError, OSError, TypeError, ValueError):
pass
return fontpaths
@@ -274,13 +273,12 @@
within them.
"""
fontpaths = []
- def add(arg,directory,files):
- fontpaths.append(directory)
for fontdir in X11FontDirectories:
try:
if os.path.isdir(fontdir):
- os.path.walk(fontdir, add, None)
+ for root, dirs, files in os.walk(fontdir):
+ fontpaths.append(root)
except (IOError, OSError, TypeError, ValueError):
pass
return fontpaths
@@ -304,6 +302,7 @@
return fontfiles
if pipe.returncode == 0:
+ output = str(output)
for line in output.split('\n'):
fname = line.split(':')[0]
if (os.path.splitext(fname)[1][1:] in fontext and
@@ -945,7 +944,8 @@
Equivalent to pickle.dump(data, open(filename, 'w'))
but closes the file to prevent filehandle leakage.
"""
- fh = open(filename, 'w')
+ fh = open(filename, 'wb')
+ print data
try:
pickle.dump(data, fh)
finally:
@@ -956,7 +956,7 @@
Equivalent to pickle.load(open(filename, 'r'))
but closes the file to prevent filehandle leakage.
"""
- fh = open(filename, 'r')
+ fh = open(filename, 'rb')
try:
data = pickle.load(fh)
finally:
@@ -975,7 +975,7 @@
# Increment this version number whenever the font cache data
# format or behavior has changed and requires a existing font
# cache files to be rebuilt.
- __version__ = 7
+ __version__ = 8
def __init__(self, size=None, weight='normal'):
self._version = self.__version__
@@ -1317,7 +1317,10 @@
return result
else:
- _fmcache = os.path.join(get_configdir(), 'fontList.cache')
+ if sys.hexversion >= 0x03000000:
+ _fmcache = os.path.join(get_configdir(), 'fontList.py3k.cache')
+ else:
+ _fmcache = os.path.join(get_configdir(), 'fontList.py3k.cache')
fontManager = None
Modified: branches/py3k/lib/matplotlib/lines.py
===================================================================
--- branches/py3k/lib/matplotlib/lines.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/lines.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -1811,4 +1811,4 @@
# You can not set the docstring of an instancemethod,
# but you can on the underlying function. Go figure.
-docstring.dedent_interpd(Line2D.__init__.im_func)
+docstring.dedent_interpd(Line2D.__init__)
Modified: branches/py3k/lib/matplotlib/mlab.py
===================================================================
--- branches/py3k/lib/matplotlib/mlab.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/mlab.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -148,7 +148,6 @@
ma = np.ma
from matplotlib import verbose
-import matplotlib.nxutils as nxutils
import matplotlib.cbook as cbook
from matplotlib import docstring
@@ -2965,6 +2964,7 @@
Return value is a sequence of indices into points for the points
that are inside the polygon.
"""
+ # PY3KTODO: Reimplement in terms of _path module
res, = np.nonzero(nxutils.points_inside_poly(points, verts))
return res
Modified: branches/py3k/lib/matplotlib/patches.py
===================================================================
--- branches/py3k/lib/matplotlib/patches.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/patches.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -401,7 +401,7 @@
docstring.interpd.update({k:patchdoc})
# define Patch.__init__ docstring after the class has been added to interpd
-docstring.dedent_interpd(Patch.__init__.im_func)
+docstring.dedent_interpd(Patch.__init__)
class Shadow(Patch):
def __str__(self):
Modified: branches/py3k/lib/matplotlib/text.py
===================================================================
--- branches/py3k/lib/matplotlib/text.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/text.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -22,8 +22,6 @@
from matplotlib.artist import allow_rasterization
-import matplotlib.nxutils as nxutils
-
from matplotlib.path import Path
import matplotlib.font_manager as font_manager
from matplotlib.ft2font import FT2Font
@@ -210,12 +208,9 @@
r = l+w
t = b+h
- xyverts = (l,b), (l, t), (r, t), (r, b)
x, y = mouseevent.x, mouseevent.y
- inside = nxutils.pnpoly(x, y, xyverts)
+ return x >= l and x <= r and y >= t and y <= b
- return inside,{}
-
def _get_xy_display(self):
'get the (possibly unit converted) transformed x, y in display coords'
x, y = self.get_position()
@@ -997,7 +992,7 @@
self.set_fontproperties(fp)
docstring.interpd.update(Text = artist.kwdoc(Text))
-docstring.dedent_interpd(Text.__init__.im_func)
+docstring.dedent_interpd(Text.__init__)
class TextWithDash(Text):
Modified: branches/py3k/setup.py
===================================================================
--- branches/py3k/setup.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/setup.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -39,7 +39,7 @@
from distutils.command.build_py import build_py
from setupext import build_agg, build_gtkagg, build_tkagg, build_wxagg,\
build_macosx, build_ft2font, build_image, build_windowing, build_path, \
- build_contour, build_delaunay, build_nxutils, build_gdk, \
+ build_contour, build_delaunay, build_gdk, \
build_ttconv, print_line, print_status, print_message, \
print_raw, check_for_freetype, check_for_libpng, check_for_gtk, \
check_for_tk, check_for_wx, check_for_macosx, check_for_numpy, \
@@ -136,7 +136,6 @@
build_ttconv(ext_modules, packages)
build_contour(ext_modules, packages)
build_delaunay(ext_modules, packages)
-build_nxutils(ext_modules, packages)
build_path(ext_modules, packages)
build_tri(ext_modules, packages)
Modified: branches/py3k/setupext.py
===================================================================
--- branches/py3k/setupext.py 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/setupext.py 2010-07-16 18:45:49 UTC (rev 8561)
@@ -106,7 +106,6 @@
BUILT_WINDOWING = False
BUILT_CONTOUR = False
BUILT_DELAUNAY = False
-BUILT_NXUTILS = False
BUILT_CONTOUR = False
BUILT_GDK = False
BUILT_PATH = False
@@ -1394,22 +1393,6 @@
BUILT_CONTOUR = True
-def build_nxutils(ext_modules, packages):
- global BUILT_NXUTILS
- if BUILT_NXUTILS: return # only build it if you you haven't already
- module = Extension(
- 'matplotlib.nxutils',
- [ 'src/nxutils.c'],
- include_dirs=numpy_inc_dirs,
- define_macros=defines
- )
- add_numpy_flags(module)
- add_base_flags(module)
- ext_modules.append(module)
-
- BUILT_NXUTILS = True
-
-
def build_gdk(ext_modules, packages):
global BUILT_GDK
if BUILT_GDK: return # only build it if you you haven't already
Modified: branches/py3k/src/_backend_agg.cpp
===================================================================
--- branches/py3k/src/_backend_agg.cpp 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/src/_backend_agg.cpp 2010-07-16 18:45:49 UTC (rev 8561)
@@ -1743,16 +1743,16 @@
//segments, trans, clipbox, colors, linewidths, antialiaseds
GCAgg gc(args[0], dpi);
- agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[1].ptr());
- size_t mesh_width = Py::Int(args[2]);
- size_t mesh_height = Py::Int(args[3]);
- Py::Object coordinates = args[4];
- Py::Object offsets_obj = args[5];
- agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[6].ptr());
- Py::Object facecolors_obj = args[7];
- bool antialiased = Py::Boolean(args[8]);
- bool showedges = Py::Boolean(args[9]);
- bool free_edgecolors = false;
+ agg::trans_affine master_transform = py_to_agg_transformation_matrix(args[1].ptr());
+ size_t mesh_width = Py::Int(args[2]);
+ size_t mesh_height = Py::Int(args[3]);
+ Py::Object coordinates = args[4];
+ Py::Object offsets_obj = args[5];
+ agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[6].ptr());
+ Py::Object facecolors_obj = args[7];
+ bool antialiased = Py::Boolean(args[8]);
+ bool showedges = Py::Boolean(args[9]);
+ bool free_edgecolors = false;
QuadMeshGenerator path_generator(mesh_width, mesh_height, coordinates.ptr());
Modified: branches/py3k/src/_png.cpp
===================================================================
--- branches/py3k/src/_png.cpp 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/src/_png.cpp 2010-07-16 18:45:49 UTC (rev 8561)
@@ -199,24 +199,30 @@
}
catch (...)
{
+ if (png_ptr && info_ptr)
+ {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ }
+ delete [] row_pointers;
if (fp && close_file)
{
fclose(fp);
}
- delete [] row_pointers;
/* Changed calls to png_destroy_write_struct to follow
http://www.libpng.org/pub/png/libpng-manual.txt.
This ensures the info_ptr memory is released.
*/
- if (png_ptr && info_ptr)
- {
- png_destroy_write_struct(&png_ptr, &info_ptr);
- }
throw;
}
png_destroy_write_struct(&png_ptr, &info_ptr);
delete [] row_pointers;
+#if PY_MAJOR_VERSION >= 3
+ if (fp)
+ {
+ fflush(fp);
+ }
+#endif
if (fp && close_file)
{
fclose(fp);
Deleted: branches/py3k/src/nxutils.c
===================================================================
--- branches/py3k/src/nxutils.c 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/src/nxutils.c 2010-07-16 18:45:49 UTC (rev 8561)
@@ -1,252 +0,0 @@
-#include <Python.h>
-#include "structmember.h"
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "numpy/arrayobject.h"
-
-
-/*
- pnpoly license
- Copyright (c) 1970-2003, Wm. Randolph Franklin
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
- 2. Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution.
- 3. The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-int pnpoly_api(int npol, double *xp, double *yp, double x, double y)
-{
- int i, j, c = 0;
- for (i = 0, j = npol-1; i < npol; j = i++) {
- if ((((yp[i]<=y) && (y<yp[j])) ||
- ((yp[j]<=y) && (y<yp[i]))) &&
- (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
-
- c = !c;
- }
- return c;
-}
-
-
-static PyObject *
-pnpoly(PyObject *self, PyObject *args)
-{
- int npol, i;
- double x, y;
- double *xv, *yv;
- int b;
- PyObject *vertsarg;
- PyArrayObject *verts;
- if (! PyArg_ParseTuple(args, "ddO", &x, &y, &vertsarg))
- return NULL;
-
- verts = (PyArrayObject *) PyArray_FromObject(vertsarg,NPY_DOUBLE, 2, 2);
-
- if (verts == NULL)
- {
- PyErr_SetString(PyExc_ValueError,
- "Arguments verts must be a Nx2 array.");
- Py_XDECREF(verts);
- return NULL;
-
- }
-
- npol = verts->dimensions[0];
- //printf ("found %d verts\n", npol);
- if (verts->dimensions[1]!=2)
- {
- PyErr_SetString(PyExc_ValueError,
- "Arguments verts must be a Nx2 array.");
- Py_XDECREF(verts);
- return NULL;
-
- }
-
-
- xv = (double *) PyMem_Malloc(sizeof(double) * npol);
- if (xv == NULL)
- {
- Py_XDECREF(verts);
- return NULL;
- }
-
- yv = (double *) PyMem_Malloc(sizeof(double) * npol);
- if (yv == NULL)
- {
- Py_XDECREF(verts);
- PyMem_Free(xv);
- return NULL;
- }
-
- for (i=0; i<npol; ++i) {
- xv[i] = *(double *)(verts->data + i*verts->strides[0]);
- yv[i] = *(double *)(verts->data + i*verts->strides[0] + verts->strides[1]);
- //printf("adding vert: %1.3f, %1.3f\n", xv[i], yv[i]);
- }
-
- b = pnpoly_api(npol, xv, yv, x, y);
- //printf("in poly %d\n", b);
-
- Py_XDECREF(verts);
- PyMem_Free(xv);
- PyMem_Free(yv);
- return Py_BuildValue("i", b);
-
-}
-
-static PyObject *
-points_inside_poly(PyObject *self, PyObject *args)
-{
- int npol, npoints, i;
- double *xv, *yv, x, y;
- int b;
- PyObject *xypointsarg, *vertsarg, *ret;
- PyArrayObject *xypoints, *verts;
- PyArrayObject *mask;
- npy_intp dimensions[1];
-
- if (! PyArg_ParseTuple(args, "OO", &xypointsarg, &vertsarg))
- return NULL;
-
- verts = (PyArrayObject *) PyArray_FromObject(vertsarg, NPY_DOUBLE, 2, 2);
-
- if (verts == NULL)
- {
- PyErr_SetString(PyExc_ValueError,
- "Argument verts must be a Nx2 array.");
- Py_XDECREF(verts);
- return NULL;
-
- }
-
- npol = verts->dimensions[0];
- //printf ("found %d verts\n", npol);
- if (verts->dimensions[1]!=2)
- {
- PyErr_SetString(PyExc_ValueError,
- "Arguments verts must be a Nx2 array.");
- Py_XDECREF(verts);
- return NULL;
-
- }
-
-
- xv = (double *) PyMem_Malloc(sizeof(double) * npol);
- if (xv == NULL)
- {
- Py_XDECREF(verts);
- return NULL;
- }
-
- yv = (double *) PyMem_Malloc(sizeof(double) * npol);
- if (yv == NULL)
- {
- Py_XDECREF(verts);
- PyMem_Free(xv);
- return NULL;
- }
-
- // fill the verts arrays
- for (i=0; i<npol; ++i) {
- xv[i] = *(double *)(verts->data + i*verts->strides[0]);
- yv[i] = *(double *)(verts->data + i*verts->strides[0] + verts->strides[1]);
- //printf("adding vert: %1.3f, %1.3f\n", xv[i], yv[i]);
- }
-
- xypoints = (PyArrayObject *) PyArray_FromObject(xypointsarg, NPY_DOUBLE, 2, 2);
-
- if (xypoints == NULL)
- {
- PyErr_SetString(PyExc_ValueError,
- "Arguments xypoints must an Nx2 array.");
- Py_XDECREF(verts);
- Py_XDECREF(xypoints);
- PyMem_Free(xv);
- PyMem_Free(yv);
- return NULL;
-
- }
-
- if (xypoints->dimensions[1]!=2)
- {
- PyErr_SetString(PyExc_ValueError,
- "Arguments xypoints must be a Nx2 array.");
-
- Py_XDECREF(verts);
- Py_XDECREF(xypoints);
- PyMem_Free(xv);
- PyMem_Free(yv);
- return NULL;
- }
-
- npoints = xypoints->dimensions[0];
- dimensions[0] = npoints;
-
- mask = (PyArrayObject *)PyArray_SimpleNew(1,dimensions, NPY_BOOL);
- if (mask==NULL) {
- Py_XDECREF(verts);
- Py_XDECREF(xypoints);
- PyMem_Free(xv);
- PyMem_Free(yv);
- return NULL; }
-
- for (i=0; i<npoints; ++i) {
- x = *(double *)(xypoints->data + i*xypoints->strides[0]);
- y = *(double *)(xypoints->data + i*xypoints->strides[0] + xypoints->strides[1]);
- b = pnpoly_api(npol, xv, yv, x, y);
- //printf("checking %d, %d, %1.3f, %1.3f, %d\n", npol, npoints, x, y, b);
- *(char *)(mask->data + i*mask->strides[0]) = b;
-
- }
-
-
- Py_XDECREF(verts);
- Py_XDECREF(xypoints);
-
- PyMem_Free(xv);
- PyMem_Free(yv);
- ret = Py_BuildValue("O", mask);
- Py_XDECREF(mask);
- return ret;
-
-
-}
-
-static PyMethodDef module_methods[] = {
- {"pnpoly", pnpoly, METH_VARARGS,
- "inside = pnpoly(x, y, xyverts)\n\n"
- "Return 1 if x,y is inside the polygon, 0 otherwise.\n\n"
- "*xyverts*\n a sequence of x,y vertices.\n\n"
- "A point on the boundary may be treated as inside or outside.\n"
- "See `pnpoly <http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html>`_"},
- {"points_inside_poly", points_inside_poly, METH_VARARGS,
- "mask = points_inside_poly(xypoints, xyverts)\n\n"
- "Return a boolean ndarray, True for points inside the polygon.\n\n"
- "*xypoints*\n a sequence of N x,y pairs.\n"
- "*xyverts*\n sequence of x,y vertices of the polygon.\n"
- "*mask* an ndarray of length N.\n\n"
- "A point on the boundary may be treated as inside or outside.\n"
- "See `pnpoly <http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html>`_\n"},
- {NULL} /* Sentinel */
-};
-
-PyMODINIT_FUNC
-initnxutils(void)
-{
- PyObject* m;
-
- m = Py_InitModule3("nxutils", module_methods,
- "general purpose numerical utilities, eg for computational geometry, that are not available in `numpy <http://numpy.scipy.org>`_");
-
- if (m == NULL)
- return;
-
- import_array();
-}
-
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|