diff options
author | Arystanbek Dyussenov <arystan.d@gmail.com> | 2009-09-15 22:01:18 +0400 |
---|---|---|
committer | Arystanbek Dyussenov <arystan.d@gmail.com> | 2009-09-15 22:01:18 +0400 |
commit | 816377cc02fe5dd4be945c0f3d415861114b4980 (patch) | |
tree | 306e9d1363aa66bc919e43b80b3380fab9f60ea9 /source/gameengine/Expressions | |
parent | c8af263e5d8d9d41a757e8438cdcf3b64d57e0c0 (diff) | |
parent | ee768ada680ce0a8aa184c882005c0ef1c0140fb (diff) |
Undo revision 23130 which was a merge with 2.5, a messy one because I did something wrong (`svn status` output: http://www.pasteall.org/7887).soc-2009-kazanbas
The command: svn merge -r 23130:23129 https://svn.blender.org/svnroot/bf-blender/branches/soc-2009-kazanbas
Diffstat (limited to 'source/gameengine/Expressions')
-rw-r--r-- | source/gameengine/Expressions/CMakeLists.txt | 14 | ||||
-rw-r--r-- | source/gameengine/Expressions/ListValue.cpp | 9 | ||||
-rw-r--r-- | source/gameengine/Expressions/ListValue.h | 1 | ||||
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.cpp | 77 | ||||
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.h | 5 | ||||
-rw-r--r-- | source/gameengine/Expressions/SConscript | 8 | ||||
-rw-r--r-- | source/gameengine/Expressions/Value.cpp | 8 | ||||
-rw-r--r-- | source/gameengine/Expressions/Value.h | 2 |
8 files changed, 72 insertions, 52 deletions
diff --git a/source/gameengine/Expressions/CMakeLists.txt b/source/gameengine/Expressions/CMakeLists.txt index 439a50852a7..dffd13f64ff 100644 --- a/source/gameengine/Expressions/CMakeLists.txt +++ b/source/gameengine/Expressions/CMakeLists.txt @@ -27,13 +27,13 @@ FILE(GLOB SRC *.cpp) SET(INC - . - ../../../source/kernel/gen_system - ../../../intern/string - ../../../intern/moto/include - ../../../source/gameengine/SceneGraph - ../../../source/blender/blenloader - ${PYTHON_INC} + . + ../../../source/kernel/gen_system + ../../../intern/string + ../../../intern/moto/include + ../../../source/gameengine/SceneGraph + ../../../source/blender/blenloader + ${PYTHON_INC} ) BLENDERLIB(bf_expressions "${SRC}" "${INC}") diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 002674450d1..5f45cdc48a2 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -300,6 +300,7 @@ PyMethodDef CListValue::Methods[] = { /* Dict style access */ {"get", (PyCFunction)CListValue::sPyget,METH_VARARGS}, + {"has_key", (PyCFunction)CListValue::sPyhas_key,METH_O}, /* Own cvalue funcs */ {"from_id", (PyCFunction)CListValue::sPyfrom_id,METH_O}, @@ -593,6 +594,14 @@ PyObject* CListValue::Pyget(PyObject *args) return def; } +/* Matches python dict.has_key() */ +PyObject* CListValue::Pyhas_key(PyObject* value) +{ + if (PyUnicode_Check(value) && FindValue((const char *)_PyUnicode_AsString(value))) + Py_RETURN_TRUE; + + Py_RETURN_FALSE; +} PyObject* CListValue::Pyfrom_id(PyObject* value) { diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index 2dc458e0148..98e6f216f11 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/ListValue.h @@ -74,6 +74,7 @@ public: KX_PYMETHOD_O(CListValue,index); KX_PYMETHOD_O(CListValue,count); KX_PYMETHOD_VARARGS(CListValue,get); + KX_PYMETHOD_O(CListValue,has_key); KX_PYMETHOD_O(CListValue,from_id); diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 1d1d9e6103b..5be703f0fa4 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -751,17 +751,16 @@ int PyObjectPlus::py_set_attrdef(PyObject *self_py, PyObject *value, const PyAtt STR_String *var = reinterpret_cast<STR_String*>(ptr); if (PyUnicode_Check(value)) { - Py_ssize_t val_len; - char *val = _PyUnicode_AsStringAndSize(value, &val_len); + char *val = _PyUnicode_AsString(value); if (attrdef->m_clamp) { - if (val_len < attrdef->m_imin) + if (strlen(val) < attrdef->m_imin) { // can't increase the length of the string PyErr_Format(PyExc_ValueError, "string length too short for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } - else if (val_len > attrdef->m_imax) + else if (strlen(val) > attrdef->m_imax) { // trim the string char c = val[attrdef->m_imax]; @@ -770,7 +769,7 @@ int PyObjectPlus::py_set_attrdef(PyObject *self_py, PyObject *value, const PyAtt val[attrdef->m_imax] = c; break; } - } else if (val_len < attrdef->m_imin || val_len > attrdef->m_imax) + } else if (strlen(val) < attrdef->m_imin || strlen(val) > attrdef->m_imax) { PyErr_Format(PyExc_ValueError, "string length out of range for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; @@ -907,47 +906,45 @@ void PyObjectPlus::SetDeprecationWarnings(bool ignoreDeprecationWarnings) m_ignore_deprecation_warnings = ignoreDeprecationWarnings; } -void PyDebugLine() +void PyObjectPlus::ShowDeprecationWarning_func(const char* old_way,const char* new_way) { - // import sys; print '\t%s:%d' % (sys._getframe(0).f_code.co_filename, sys._getframe(0).f_lineno) - - PyObject *getframe, *frame; - PyObject *f_lineno, *f_code, *co_filename; - - getframe = PySys_GetObject((char *)"_getframe"); // borrowed - if (getframe) { - frame = PyObject_CallObject(getframe, NULL); - if (frame) { - f_lineno= PyObject_GetAttrString(frame, "f_lineno"); - f_code= PyObject_GetAttrString(frame, "f_code"); - if (f_lineno && f_code) { - co_filename= PyObject_GetAttrString(f_code, "co_filename"); - if (co_filename) { - - printf("\t%s:%d\n", _PyUnicode_AsString(co_filename), (int)PyLong_AsSsize_t(f_lineno)); - - Py_DECREF(f_lineno); - Py_DECREF(f_code); - Py_DECREF(co_filename); - Py_DECREF(frame); - return; + { + printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way); + + // import sys; print '\t%s:%d' % (sys._getframe(0).f_code.co_filename, sys._getframe(0).f_lineno) + + PyObject *getframe, *frame; + PyObject *f_lineno, *f_code, *co_filename; + + getframe = PySys_GetObject((char *)"_getframe"); // borrowed + if (getframe) { + frame = PyObject_CallObject(getframe, NULL); + if (frame) { + f_lineno= PyObject_GetAttrString(frame, "f_lineno"); + f_code= PyObject_GetAttrString(frame, "f_code"); + if (f_lineno && f_code) { + co_filename= PyObject_GetAttrString(f_code, "co_filename"); + if (co_filename) { + + printf("\t%s:%d\n", _PyUnicode_AsString(co_filename), (int)PyLong_AsSsize_t(f_lineno)); + + Py_DECREF(f_lineno); + Py_DECREF(f_code); + Py_DECREF(co_filename); + Py_DECREF(frame); + return; + } } + + Py_XDECREF(f_lineno); + Py_XDECREF(f_code); + Py_DECREF(frame); } - Py_XDECREF(f_lineno); - Py_XDECREF(f_code); - Py_DECREF(frame); } - + PyErr_Clear(); + printf("\tERROR - Could not access sys._getframe(0).f_lineno or sys._getframe().f_code.co_filename\n"); } - PyErr_Clear(); - printf("\tERROR - Could not access sys._getframe(0).f_lineno or sys._getframe().f_code.co_filename\n"); -} - -void PyObjectPlus::ShowDeprecationWarning_func(const char* old_way,const char* new_way) -{ - printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way); - PyDebugLine(); } void PyObjectPlus::ClearDeprecationWarning() diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index f9edb7877b0..e9e81dddaaa 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -86,7 +86,7 @@ typedef struct { -typedef struct PyObjectPlus_Proxy { +typedef struct { PyObject_HEAD /* required python macro */ class PyObjectPlus *ref; bool py_owns; @@ -99,9 +99,6 @@ typedef struct PyObjectPlus_Proxy { /* Note, sometimes we dont care what BGE type this is as long as its a proxy */ #define BGE_PROXY_CHECK_TYPE(_type) ((_type)->tp_dealloc == PyObjectPlus::py_base_dealloc) -/* Opposite of BGE_PROXY_REF */ -#define BGE_PROXY_FROM_REF(_self) (((PyObjectPlus *)_self)->GetProxy()) - // This must be the first line of each // PyC++ class diff --git a/source/gameengine/Expressions/SConscript b/source/gameengine/Expressions/SConscript index c819bfb0d3e..69f87ffbb90 100644 --- a/source/gameengine/Expressions/SConscript +++ b/source/gameengine/Expressions/SConscript @@ -6,4 +6,10 @@ sources = env.Glob('*.cpp') incs ='. #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/SceneGraph #source/blender/blenloader' incs += ' ' + env['BF_PYTHON_INC'] -env.BlenderLib ( 'bf_expressions', sources, Split(incs), [], libtype=['core','player'], priority = [360,80], cxx_compileflags=env['BGE_CXXFLAGS']) +cxxflags = [] +if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'): + cxxflags.append ('/GR') + cxxflags.append ('/O2') + cxxflags.append ('/EHsc') + +env.BlenderLib ( 'bf_expressions', sources, Split(incs), [], libtype=['core','player'], priority = [360,120], cxx_compileflags=cxxflags) diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 130317d77e2..04bcc3a5561 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -62,9 +62,17 @@ PyTypeObject CValue::Type = { }; PyMethodDef CValue::Methods[] = { + { "getName", (PyCFunction) CValue::sPyGetName, METH_NOARGS}, {NULL,NULL} //Sentinel }; +PyObject* CValue::PyGetName() +{ + ShowDeprecationWarning("getName()", "the name property"); + + return PyUnicode_FromString(this->GetName()); +} + /*#define CVALUE_DEBUG*/ #ifdef CVALUE_DEBUG int gRefCount; diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index 7d4adcdb64f..5f08736afde 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -242,6 +242,8 @@ public: static PyObject * pyattr_get_name(void * self, const KX_PYATTRIBUTE_DEF * attrdef); virtual PyObject* ConvertKeysToPython( void ); + + KX_PYMETHOD_NOARGS(CValue,GetName); #else CValue(); |