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. ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins