diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-01-29 13:22:03 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-01-29 13:22:03 +0300 |
commit | b1a001942ac2cb63e02394c5675426c333aa2f2b (patch) | |
tree | 08195c60d9ef893df4d18747a8a84b0e85204014 /source/blender | |
parent | 3701fe8f361f166c0b05fdbd979949b9d439cf5f (diff) |
include Py_CmpToRich for python versions lower then 3
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/intern/bpy_compat.h | 7 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_util.c | 40 |
2 files changed, 47 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_compat.h b/source/blender/python/intern/bpy_compat.h index bc201a3e802..ef363e397fa 100644 --- a/source/blender/python/intern/bpy_compat.h +++ b/source/blender/python/intern/bpy_compat.h @@ -74,4 +74,11 @@ #endif #endif + +/* defined in bpy_util.c */ +#if PY_VERSION_HEX < 0x03000000 +PyObject *Py_CmpToRich(int op, int cmp); +#endif + + #endif /* BPY_COMPAT_H__ */ diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index 28d97f9bdf5..bbf766c23eb 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -110,6 +110,46 @@ int BPY_flag_from_seq(BPY_flag_def *flagdef, PyObject *seq, int *flag) return 0; /* ok */ } + +/* Copied from pythons 3's Object.c */ +#if PY_VERSION_HEX < 0x03000000 +PyObject * +Py_CmpToRich(int op, int cmp) +{ + PyObject *res; + int ok; + + if (PyErr_Occurred()) + return NULL; + switch (op) { + case Py_LT: + ok = cmp < 0; + break; + case Py_LE: + ok = cmp <= 0; + break; + case Py_EQ: + ok = cmp == 0; + break; + case Py_NE: + ok = cmp != 0; + break; + case Py_GT: + ok = cmp > 0; + break; + case Py_GE: + ok = cmp >= 0; + break; + default: + PyErr_BadArgument(); + return NULL; + } + res = ok ? Py_True : Py_False; + Py_INCREF(res); + return res; +} +#endif + /* for debugging */ void PyObSpit(char *name, PyObject *var) { fprintf(stderr, "<%s> : ", name); |