| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 78ed16a commit 81219db
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,7 +102,7 @@ Py::Object | |||
| 102 | 102 | BufferRegion::to_string(const Py::Tuple &args) | |
| 103 | 103 | { | |
| 104 | 104 | // owned=true to prevent memory leak | |
| 105 | - #if PY_MAJOR_VERSION >= 3 | ||
| 105 | + #if PY3K | ||
| 106 | 106 | return Py::Bytes(PyBytes_FromStringAndSize((const char*)data, height*stride), true); | |
| 107 | 107 | #else | |
| 108 | 108 | return Py::String(PyString_FromStringAndSize((const char*)data, height*stride), true); | |
@@ -156,7 +156,7 @@ BufferRegion::to_string_argb(const Py::Tuple &args) | |||
| 156 | 156 | unsigned char tmp; | |
| 157 | 157 | size_t i, j; | |
| 158 | 158 | ||
| 159 | - #if PY_MAJOR_VERSION >= 3 | ||
| 159 | + #if PY3K | ||
| 160 | 160 | PyObject* str = PyBytes_FromStringAndSize((const char*)data, height * stride); | |
| 161 | 161 | if (PyBytes_AsStringAndSize(str, (char**)&begin, &length)) | |
| 162 | 162 | { | |
@@ -1994,7 +1994,7 @@ RendererAgg::write_rgba(const Py::Tuple& args) | |||
| 1994 | 1994 | bool close_file = false; | |
| 1995 | 1995 | Py::Object py_fileobj = Py::Object(args[0]); | |
| 1996 | 1996 | ||
| 1997 | - #if PY_MAJOR_VERSION >= 3 | ||
| 1997 | + #if PY3K | ||
| 1998 | 1998 | int fd = PyObject_AsFileDescriptor(py_fileobj.ptr()); | |
| 1999 | 1999 | PyErr_Clear(); | |
| 2000 | 2000 | #endif | |
@@ -2014,7 +2014,7 @@ RendererAgg::write_rgba(const Py::Tuple& args) | |||
| 2014 | 2014 | } | |
| 2015 | 2015 | close_file = true; | |
| 2016 | 2016 | } | |
| 2017 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2017 | + #if PY3K | ||
| 2018 | 2018 | else if (fd != -1) | |
| 2019 | 2019 | { | |
| 2020 | 2020 | if (write(fd, pixBuffer, NUMBYTES) != (ssize_t)NUMBYTES) | |
@@ -2087,7 +2087,11 @@ RendererAgg::tostring_rgb(const Py::Tuple& args) | |||
| 2087 | 2087 | } | |
| 2088 | 2088 | ||
| 2089 | 2089 | //todo: how to do this with native CXX | |
| 2090 | + #if PY3K | ||
| 2091 | + PyObject* o = Py_BuildValue("y#", buf_tmp, row_len * height); | ||
| 2092 | + #else | ||
| 2090 | 2093 | PyObject* o = Py_BuildValue("s#", buf_tmp, row_len * height); | |
| 2094 | + #endif | ||
| 2091 | 2095 | ||
| 2092 | 2096 | delete [] buf_tmp; | |
| 2093 | 2097 | return Py::asObject(o); | |
@@ -2123,7 +2127,12 @@ RendererAgg::tostring_argb(const Py::Tuple& args) | |||
| 2123 | 2127 | } | |
| 2124 | 2128 | ||
| 2125 | 2129 | //todo: how to do this with native CXX | |
| 2130 | + | ||
| 2131 | + #if PY3K | ||
| 2132 | + PyObject* o = Py_BuildValue("y#", buf_tmp, row_len * height); | ||
| 2133 | + #else | ||
| 2126 | 2134 | PyObject* o = Py_BuildValue("s#", buf_tmp, row_len * height); | |
| 2135 | + #endif | ||
| 2127 | 2136 | delete [] buf_tmp; | |
| 2128 | 2137 | return Py::asObject(o); | |
| 2129 | 2138 | } | |
@@ -2162,9 +2171,11 @@ RendererAgg::tostring_bgra(const Py::Tuple& args) | |||
| 2162 | 2171 | } | |
| 2163 | 2172 | ||
| 2164 | 2173 | //todo: how to do this with native CXX | |
| 2165 | - PyObject* o = Py_BuildValue("s#", | ||
| 2166 | - buf_tmp, | ||
| 2167 | - row_len * height); | ||
| 2174 | + #if PY3K | ||
| 2175 | + PyObject* o = Py_BuildValue("y#", buf_tmp, row_len * height); | ||
| 2176 | + #else | ||
| 2177 | + PyObject* o = Py_BuildValue("s#", buf_tmp, row_len * height); | ||
| 2178 | + #endif | ||
| 2168 | 2179 | delete [] buf_tmp; | |
| 2169 | 2180 | return Py::asObject(o); | |
| 2170 | 2181 | } | |
@@ -2183,10 +2194,10 @@ RendererAgg::buffer_rgba(const Py::Tuple& args) | |||
| 2183 | 2194 | int row_len = width * 4; | |
| 2184 | 2195 | int start = row_len * starth + startw * 4; | |
| 2185 | 2196 | /* PY3KTODO: Buffers are different */ | |
| 2186 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2197 | + #if PY3K | ||
| 2187 | 2198 | return Py::asObject(PyByteArray_FromStringAndSize( | |
| 2188 | - (const char *)pixBuffer + start, | ||
| 2189 | - row_len*height - start)); | ||
| 2199 | + (const char *)pixBuffer + start, | ||
| 2200 | + row_len*height - start)); | ||
| 2190 | 2201 | #else | |
| 2191 | 2202 | return Py::asObject(PyBuffer_FromMemory(pixBuffer + start, row_len*height - start)); | |
| 2192 | 2203 | #endif | |
@@ -2427,7 +2438,7 @@ void RendererAgg::init_type() | |||
| 2427 | 2438 | } | |
| 2428 | 2439 | ||
| 2429 | 2440 | extern "C" | |
| 2430 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2441 | + #if PY3K | ||
| 2431 | 2442 | PyMODINIT_FUNC | |
| 2432 | 2443 | PyInit__backend_agg(void) | |
| 2433 | 2444 | #else | |
@@ -2444,7 +2455,7 @@ init_backend_agg(void) | |||
| 2444 | 2455 | static _backend_agg_module* _backend_agg = NULL; | |
| 2445 | 2456 | _backend_agg = new _backend_agg_module; | |
| 2446 | 2457 | ||
| 2447 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2458 | + #if PY3K | ||
| 2448 | 2459 | return _backend_agg->module().ptr(); | |
| 2449 | 2460 | #endif | |
| 2450 | 2461 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -223,7 +223,7 @@ Image::color_conv(const Py::Tuple& args) | |||
| 223 | 223 | int format = Py::Int(args[0]); | |
| 224 | 224 | PyObject* py_buffer = NULL; | |
| 225 | 225 | int row_len = colsOut * 4; | |
| 226 | - #if PY_MAJOR_VERSION >= 3 | ||
| 226 | + #if PY3K | ||
| 227 | 227 | unsigned char* buf = (unsigned char *)malloc(row_len * rowsOut); | |
| 228 | 228 | if (buf == NULL) | |
| 229 | 229 | throw Py::MemoryError("Image::color_conv could not allocate memory"); | |
@@ -259,7 +259,7 @@ Image::color_conv(const Py::Tuple& args) | |||
| 259 | 259 | throw Py::ValueError("Image::color_conv unknown format"); | |
| 260 | 260 | } | |
| 261 | 261 | ||
| 262 | - #if PY_MAJOR_VERSION >= 3 | ||
| 262 | + #if PY3K | ||
| 263 | 263 | py_buffer = PyByteArray_FromStringAndSize((char *)buf, row_len * rowsOut); | |
| 264 | 264 | if (py_buffer == NULL) { | |
| 265 | 265 | free(buf); | |
@@ -1944,7 +1944,7 @@ _image_module::pcolor2(const Py::Tuple& args) | |||
| 1944 | 1944 | return Py::asObject(imo); | |
| 1945 | 1945 | } | |
| 1946 | 1946 | ||
| 1947 | - #if PY_MAJOR_VERSION >= 3 | ||
| 1947 | + #if PY3K | ||
| 1948 | 1948 | PyMODINIT_FUNC | |
| 1949 | 1949 | PyInit__image(void) | |
| 1950 | 1950 | #else | |
@@ -1980,7 +1980,7 @@ init_image(void) | |||
| 1980 | 1980 | d["ASPECT_FREE"] = Py::Int(Image::ASPECT_FREE); | |
| 1981 | 1981 | d["ASPECT_PRESERVE"] = Py::Int(Image::ASPECT_PRESERVE); | |
| 1982 | 1982 | ||
| 1983 | - #if PY_MAJOR_VERSION >= 3 | ||
| 1983 | + #if PY3K | ||
| 1984 | 1984 | return _image->module().ptr(); | |
| 1985 | 1985 | #endif | |
| 1986 | 1986 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -506,7 +506,7 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode) | |||
| 506 | 506 | static PyObject* | |
| 507 | 507 | GraphicsContext_repr(GraphicsContext* self) | |
| 508 | 508 | { | |
| 509 | - #if PY_MAJOR_VERSION >= 3 | ||
| 509 | + #if PY3K | ||
| 510 | 510 | return PyUnicode_FromFormat("GraphicsContext object %p wrapping the Quartz 2D graphics context %p", (void*)self, (void*)(self->cr)); | |
| 511 | 511 | #else | |
| 512 | 512 | return PyString_FromFormat("GraphicsContext object %p wrapping the Quartz 2D graphics context %p", (void*)self, (void*)(self->cr)); | |
@@ -2251,7 +2251,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3]) | |||
| 2251 | 2251 | #else | |
| 2252 | 2252 | ATSFontRef font = 0; | |
| 2253 | 2253 | #endif | |
| 2254 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2254 | + #if PY3K | ||
| 2255 | 2255 | PyObject* ascii = NULL; | |
| 2256 | 2256 | #endif | |
| 2257 | 2257 | ||
@@ -2434,41 +2434,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3]) | |||
| 2434 | 2434 | for (i = 0; i < n; i++) | |
| 2435 | 2435 | { | |
| 2436 | 2436 | PyObject* item = PyList_GET_ITEM(family, i); | |
| 2437 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2438 | - ascii = PyUnicode_AsASCIIString(item); | ||
| 2439 | - if(!ascii) return 0; | ||
| 2440 | - temp = PyBytes_AS_STRING(ascii); | ||
| 2441 | - #else | ||
| 2442 | - if(!PyString_Check(item)) return 0; | ||
| 2443 | - temp = PyString_AS_STRING(item); | ||
| 2444 | - #endif | ||
| 2445 | - for (j = 0; j < NMAP; j++) | ||
| 2446 | - { if (!strcmp(map[j].name, temp)) | ||
| 2447 | - { temp = psnames[map[j].index][k]; | ||
| 2448 | - break; | ||
| 2449 | - } | ||
| 2450 | - } | ||
| 2451 | - /* If the font name is not found in mapping, we assume */ | ||
| 2452 | - /* that the user specified the Postscript name directly */ | ||
| 2453 | - | ||
| 2454 | - /* Check if this font can be found on the system */ | ||
| 2455 | - string = CFStringCreateWithCString(kCFAllocatorDefault, | ||
| 2456 | - temp, | ||
| 2457 | - kCFStringEncodingMacRoman); | ||
| 2458 | - #ifdef COMPILING_FOR_10_5 | ||
| 2459 | - font = CTFontCreateWithName(string, size, NULL); | ||
| 2460 | - #else | ||
| 2461 | - font = ATSFontFindFromPostScriptName(string, kATSOptionFlagsDefault); | ||
| 2462 | - #endif | ||
| 2463 | - | ||
| 2464 | - CFRelease(string); | ||
| 2465 | - | ||
| 2466 | - if(font) | ||
| 2467 | - { | ||
| 2468 | - name = temp; | ||
| 2469 | - break; | ||
| 2470 | - } | ||
| 2471 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2437 | + #if PY3K | ||
| 2472 | 2438 | Py_DECREF(ascii); | |
| 2473 | 2439 | ascii = NULL; | |
| 2474 | 2440 | #endif | |
@@ -2487,7 +2453,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3]) | |||
| 2487 | 2453 | #ifndef COMPILING_FOR_10_5 | |
| 2488 | 2454 | CGContextSelectFont(cr, name, size, kCGEncodingMacRoman); | |
| 2489 | 2455 | #endif | |
| 2490 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2456 | + #if PY3K | ||
| 2491 | 2457 | Py_XDECREF(ascii); | |
| 2492 | 2458 | #endif | |
| 2493 | 2459 | return font; | |
@@ -2989,7 +2955,7 @@ static void _data_provider_release(void* info, const void* data, size_t size) | |||
| 2989 | 2955 | CGDataProviderRef provider; | |
| 2990 | 2956 | double rect[4] = {0.0, 0.0, self->size.width, self->size.height}; | |
| 2991 | 2957 | ||
| 2992 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2958 | + #if PY3K | ||
| 2993 | 2959 | if (!PyBytes_Check(image)) | |
| 2994 | 2960 | { | |
| 2995 | 2961 | PyErr_SetString(PyExc_RuntimeError, "image is not a byte array"); | |
@@ -3017,7 +2983,7 @@ static void _data_provider_release(void* info, const void* data, size_t size) | |||
| 3017 | 2983 | } | |
| 3018 | 2984 | ||
| 3019 | 2985 | Py_INCREF(image); | |
| 3020 | - #if PY_MAJOR_VERSION >= 3 | ||
| 2986 | + #if PY3K | ||
| 3021 | 2987 | n = PyByteArray_GET_SIZE(image); | |
| 3022 | 2988 | data = PyByteArray_AS_STRING(image); | |
| 3023 | 2989 | #else | |
@@ -3296,7 +3262,7 @@ static void _data_provider_release(void* info, const void* data, size_t size) | |||
| 3296 | 3262 | static PyObject* | |
| 3297 | 3263 | FigureCanvas_repr(FigureCanvas* self) | |
| 3298 | 3264 | { | |
| 3299 | - #if PY_MAJOR_VERSION >= 3 | ||
| 3265 | + #if PY3K | ||
| 3300 | 3266 | return PyUnicode_FromFormat("FigureCanvas object %p wrapping NSView %p", | |
| 3301 | 3267 | (void*)self, (void*)(self->view)); | |
| 3302 | 3268 | #else | |
@@ -3766,7 +3732,7 @@ static void _data_provider_release(void* info, const void* data, size_t size) | |||
| 3766 | 3732 | static PyObject* | |
| 3767 | 3733 | FigureManager_repr(FigureManager* self) | |
| 3768 | 3734 | { | |
| 3769 | - #if PY_MAJOR_VERSION >= 3 | ||
| 3735 | + #if PY3K | ||
| 3770 | 3736 | return PyUnicode_FromFormat("FigureManager object %p wrapping NSWindow %p", | |
| 3771 | 3737 | (void*) self, (void*)(self->window)); | |
| 3772 | 3738 | #else | |
@@ -4157,7 +4123,7 @@ -(void)save_figure:(id)sender | |||
| 4157 | 4123 | static PyObject* | |
| 4158 | 4124 | NavigationToolbar_repr(NavigationToolbar* self) | |
| 4159 | 4125 | { | |
| 4160 | - #if PY_MAJOR_VERSION >= 3 | ||
| 4126 | + #if PY3K | ||
| 4161 | 4127 | return PyUnicode_FromFormat("NavigationToolbar object %p", (void*)self); | |
| 4162 | 4128 | #else | |
| 4163 | 4129 | return PyString_FromFormat("NavigationToolbar object %p", (void*)self); | |
@@ -4268,7 +4234,7 @@ -(void)save_figure:(id)sender | |||
| 4268 | 4234 | { | |
| 4269 | 4235 | if(states[i]==1) | |
| 4270 | 4236 | { | |
| 4271 | - #if PY_MAJOR_VERSION >= 3 | ||
| 4237 | + #if PY3K | ||
| 4272 | 4238 | PyList_SET_ITEM(list, j, PyLong_FromLong(i)); | |
| 4273 | 4239 | #else | |
| 4274 | 4240 | PyList_SET_ITEM(list, j, PyInt_FromLong(i)); | |
@@ -4686,7 +4652,7 @@ -(void)save_figure:(id)sender | |||
| 4686 | 4652 | static PyObject* | |
| 4687 | 4653 | NavigationToolbar2_repr(NavigationToolbar2* self) | |
| 4688 | 4654 | { | |
| 4689 | - #if PY_MAJOR_VERSION >= 3 | ||
| 4655 | + #if PY3K | ||
| 4690 | 4656 | return PyUnicode_FromFormat("NavigationToolbar2 object %p", (void*)self); | |
| 4691 | 4657 | #else | |
| 4692 | 4658 | return PyString_FromFormat("NavigationToolbar2 object %p", (void*)self); | |
@@ -5611,7 +5577,7 @@ - (int)index | |||
| 5611 | 5577 | static PyObject* | |
| 5612 | 5578 | Timer_repr(Timer* self) | |
| 5613 | 5579 | { | |
| 5614 | - #if PY_MAJOR_VERSION >= 3 | ||
| 5580 | + #if PY3K | ||
| 5615 | 5581 | return PyUnicode_FromFormat("Timer object %p wrapping CFRunLoopTimerRef %p", | |
| 5616 | 5582 | (void*) self, (void*)(self->timer)); | |
| 5617 | 5583 | #else | |
@@ -5792,7 +5758,7 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info) | |||
| 5792 | 5758 | {NULL, NULL, 0, NULL}/* sentinel */ | |
| 5793 | 5759 | }; | |
| 5794 | 5760 | ||
| 5795 | - #if PY_MAJOR_VERSION >= 3 | ||
| 5761 | + #if PY3K | ||
| 5796 | 5762 | ||
| 5797 | 5763 | static struct PyModuleDef moduledef = { | |
| 5798 | 5764 | PyModuleDef_HEAD_INIT, | |
@@ -5822,13 +5788,13 @@ void init_macosx(void) | |||
| 5822 | 5788 | || PyType_Ready(&NavigationToolbarType) < 0 | |
| 5823 | 5789 | || PyType_Ready(&NavigationToolbar2Type) < 0 | |
| 5824 | 5790 | || PyType_Ready(&TimerType) < 0) | |
| 5825 | - #if PY_MAJOR_VERSION >= 3 | ||
| 5791 | + #if PY3K | ||
| 5826 | 5792 | return NULL; | |
| 5827 | 5793 | #else | |
| 5828 | 5794 | return; | |
| 5829 | 5795 | #endif | |
| 5830 | 5796 | ||
| 5831 | - #if PY_MAJOR_VERSION >= 3 | ||
| 5797 | + #if PY3K | ||
| 5832 | 5798 | module = PyModule_Create(&moduledef); | |
| 5833 | 5799 | if (module==NULL) return NULL; | |
| 5834 | 5800 | #else | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1481,7 +1481,7 @@ _path_module::cleanup_path(const Py::Tuple& args) | |||
| 1481 | 1481 | return result; | |
| 1482 | 1482 | } | |
| 1483 | 1483 | ||
| 1484 | - #if PY_MAJOR_VERSION >= 3 | ||
| 1484 | + #if PY3K | ||
| 1485 | 1485 | extern "C" | |
| 1486 | 1486 | PyMODINIT_FUNC | |
| 1487 | 1487 | PyInit__path(void) | |
@@ -1496,7 +1496,7 @@ init_path(void) | |||
| 1496 | 1496 | ||
| 1497 | 1497 | import_array(); | |
| 1498 | 1498 | ||
| 1499 | - #if PY_MAJOR_VERSION >= 3 | ||
| 1499 | + #if PY3K | ||
| 1500 | 1500 | return _path->module().ptr(); | |
| 1501 | 1501 | #endif | |
| 1502 | 1502 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments