Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-11-03 18:09:18 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-11-03 18:09:18 +0400
commit665f602f152984f5a6f4ea05a2a90382acbf700a (patch)
treea7fa9484a60ac20878e2687995d2fd955958a7f6 /source/gameengine
parentd210703bcaf89014495f761797ae50f362394697 (diff)
python string conversion
- use _PyUnicode_AsStringAndSize where possible - use %R for PyErr_Format(...) rather then running repr on the object explicitly - use const char
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Converter/BL_ActionActuator.cpp5
-rw-r--r--source/gameengine/Expressions/ListValue.cpp7
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.cpp10
-rw-r--r--source/gameengine/Expressions/StringValue.h5
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.cpp13
-rw-r--r--source/gameengine/Ketsji/KX_Camera.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_PythonSeq.cpp4
8 files changed, 24 insertions, 26 deletions
diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp
index 6f2ca28c135..a6d02db8cea 100644
--- a/source/gameengine/Converter/BL_ActionActuator.cpp
+++ b/source/gameengine/Converter/BL_ActionActuator.cpp
@@ -344,8 +344,9 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
/* Python functions */
/* ------------------------------------------------------------------------- */
-PyObject* BL_ActionActuator::PyGetChannel(PyObject* value) {
- char *string= _PyUnicode_AsString(value);
+PyObject* BL_ActionActuator::PyGetChannel(PyObject* value)
+{
+ const char *string= _PyUnicode_AsString(value);
if (!string) {
PyErr_SetString(PyExc_TypeError, "expected a single string");
diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp
index ade54f6d924..cdd87235fd2 100644
--- a/source/gameengine/Expressions/ListValue.cpp
+++ b/source/gameengine/Expressions/ListValue.cpp
@@ -339,10 +339,9 @@ PyObject* listvalue_mapping_subscript(PyObject* self, PyObject* pyindex)
int index = PyLong_AsSsize_t(pyindex);
return listvalue_buffer_item(self, index); /* wont add a ref */
}
-
- PyObject *pyindex_str = PyObject_Repr(pyindex); /* new ref */
- PyErr_Format(PyExc_KeyError, "CList[key]: '%s' key not in list", _PyUnicode_AsString(pyindex_str));
- Py_DECREF(pyindex_str);
+
+ PyErr_Format(PyExc_KeyError,
+ "CList[key]: '%R' key not in list", pyindex);
return NULL;
}
diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp
index 33aa6b8d177..b05b7be0877 100644
--- a/source/gameengine/Expressions/PyObjectPlus.cpp
+++ b/source/gameengine/Expressions/PyObjectPlus.cpp
@@ -1012,8 +1012,8 @@ int PyObjectPlus::py_set_attrdef(PyObject *self_py, PyObject *value, const PyAtt
{
if (PyUnicode_Check(value))
{
- Py_ssize_t val_len;
- char *val = _PyUnicode_AsStringAndSize(value, &val_len);
+ Py_ssize_t val_size;
+ const char *val = _PyUnicode_AsStringAndSize(value, &val_size);
strncpy(ptr, val, attrdef->m_size);
ptr[attrdef->m_size-1] = 0;
}
@@ -1030,7 +1030,7 @@ int PyObjectPlus::py_set_attrdef(PyObject *self_py, PyObject *value, const PyAtt
if (PyUnicode_Check(value))
{
Py_ssize_t val_len;
- char *val = _PyUnicode_AsStringAndSize(value, &val_len);
+ const char *val = _PyUnicode_AsStringAndSize(value, &val_len); /* XXX, should be 'const' but we do a silly trick to have a shorter string */
if (attrdef->m_clamp)
{
if (val_len < attrdef->m_imin)
@@ -1042,10 +1042,8 @@ int PyObjectPlus::py_set_attrdef(PyObject *self_py, PyObject *value, const PyAtt
else if (val_len > attrdef->m_imax)
{
// trim the string
- char c = val[attrdef->m_imax];
- val[attrdef->m_imax] = 0;
*var = val;
- val[attrdef->m_imax] = c;
+ var->SetLength(attrdef->m_imax);
break;
}
} else if (val_len < attrdef->m_imin || val_len > attrdef->m_imax)
diff --git a/source/gameengine/Expressions/StringValue.h b/source/gameengine/Expressions/StringValue.h
index d0f74a6eed8..e5a892ff82d 100644
--- a/source/gameengine/Expressions/StringValue.h
+++ b/source/gameengine/Expressions/StringValue.h
@@ -31,8 +31,7 @@ public:
CStringValue();
CStringValue (const char *txt, const char *name , AllocationTYPE alloctype = CValue::HEAPVALUE);
- virtual ~CStringValue() {
- };
+ virtual ~CStringValue() {}
/// CValue implementation
virtual bool IsEqual(const STR_String & other);
virtual const STR_String & GetText();
@@ -40,7 +39,7 @@ public:
virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
- virtual void SetValue(CValue* newval) { m_strString = newval->GetText(); SetModified(true); };
+ virtual void SetValue(CValue* newval) { m_strString = newval->GetText(); SetModified(true); }
virtual CValue* GetReplica();
#ifdef WITH_PYTHON
virtual PyObject* ConvertValueToPython() {
diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp
index 303b3e9529e..d69358928e6 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonController.cpp
@@ -199,7 +199,7 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
if (PyUnicode_Check(value)) {
/* get the actuator from the name */
- char *name= _PyUnicode_AsString(value);
+ const char *name= _PyUnicode_AsString(value);
for(it = lacts.begin(); it!= lacts.end(); ++it) {
if( name == (*it)->GetName() ) {
return *it;
@@ -214,12 +214,11 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
}
}
}
-
+
/* set the exception */
- PyObject *value_str = PyObject_Repr(value); /* new ref */
- PyErr_Format(PyExc_ValueError, "'%s' not in this python controllers actuator list", _PyUnicode_AsString(value_str));
- Py_DECREF(value_str);
-
+ PyErr_Format(PyExc_ValueError,
+ "%R not in this python controllers actuator list", value);
+
return NULL;
}
@@ -500,7 +499,7 @@ int SCA_PythonController::pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_D
{
SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v);
- char *scriptArg = _PyUnicode_AsString(value);
+ const char *scriptArg = _PyUnicode_AsString(value);
if (scriptArg==NULL) {
PyErr_SetString(PyExc_TypeError, "controller.script = string: Python Controller, expected a string script text");
diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp
index 3b777031831..77438b8f48a 100644
--- a/source/gameengine/Ketsji/KX_Camera.cpp
+++ b/source/gameengine/Ketsji/KX_Camera.cpp
@@ -883,7 +883,9 @@ bool ConvertPythonToCamera(PyObject * value, KX_Camera **object, bool py_none_ok
if (*object) {
return true;
} else {
- PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_Camera in this scene", error_prefix, _PyUnicode_AsString(value));
+ PyErr_Format(PyExc_ValueError,
+ "%s, requested name \"%s\" did not match any KX_Camera in this scene",
+ error_prefix, _PyUnicode_AsString(value));
return false;
}
}
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 25145e87b78..c3a141e7405 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -705,7 +705,7 @@ static PyObject *gLibNew(PyObject*, PyObject* args)
KX_Scene *kx_scene= gp_KetsjiScene;
char *path;
char *group;
- char *name;
+ const char *name;
PyObject *names;
int idcode;
diff --git a/source/gameengine/Ketsji/KX_PythonSeq.cpp b/source/gameengine/Ketsji/KX_PythonSeq.cpp
index 7d7dc39ba32..430dcdbd153 100644
--- a/source/gameengine/Ketsji/KX_PythonSeq.cpp
+++ b/source/gameengine/Ketsji/KX_PythonSeq.cpp
@@ -189,7 +189,7 @@ static PyObject *KX_PythonSeq_getIndex(PyObject* self, int index)
return NULL;
}
-static PyObjectPlus * KX_PythonSeq_subscript__internal(PyObject *self, char *key)
+static PyObjectPlus * KX_PythonSeq_subscript__internal(PyObject *self, const char *key)
{
PyObjectPlus *self_plus= BGE_PROXY_REF(((KX_PythonSeq *)self)->base);
@@ -277,7 +277,7 @@ static PyObject * KX_PythonSeq_subscript(PyObject * self, PyObject *key)
return KX_PythonSeq_getIndex(self, PyLong_AsSsize_t( key ));
}
else if ( PyUnicode_Check(key) ) {
- char *name = _PyUnicode_AsString(key);
+ const char *name = _PyUnicode_AsString(key);
PyObjectPlus *ret = KX_PythonSeq_subscript__internal(self, name);
if(ret) {