Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Misc fixes for py3k macosx backend #675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include "numpy/arrayobject.h"
#include "path_cleanup.h"

#if PY_MAJOR_VERSION >= 3
#define PY3K 1
#else
#define PY3K 0
#endif

/* Must define Py_TYPE for Python 2.5 or older */
#ifndef Py_TYPE
# define Py_TYPE(o) ((o)->ob_type)
Expand Down Expand Up @@ -714,7 +720,11 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
if (offset!=Py_None)
{
if (PyFloat_Check(offset)) phase = PyFloat_AsDouble(offset);
#if PY3K
else if (PyLong_Check(offset)) phase = PyLong_AsLong(offset);
#else
else if (PyInt_Check(offset)) phase = PyInt_AsLong(offset);
#endif
else
{
PyErr_SetString(PyExc_TypeError,
Expand Down Expand Up @@ -747,8 +757,13 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
PyObject* value = PyTuple_GET_ITEM(dashes, i);
if (PyFloat_Check(value))
lengths[i] = (CGFloat) PyFloat_AS_DOUBLE(value);
#if PY3K
else if (PyLong_Check(value))
lengths[i] = (CGFloat) PyLong_AsLong(value);
#else
else if (PyInt_Check(value))
lengths[i] = (CGFloat) PyInt_AS_LONG(value);
#endif
else break;
}
Py_DECREF(dashes);
Expand Down Expand Up @@ -5847,4 +5862,8 @@ void init_macosx(void)
PyModule_AddObject(module, "Timer", (PyObject*) &TimerType);

PyOS_InputHook = wait_for_stdin;

#if PY3K
return module;
#endif
}