python string conversion
- use _PyUnicode_AsStringAndSize where possible - use %R for PyErr_Format(...) rather then running repr on the object explicitly - use const char
This commit is contained in:
@@ -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");
|
||||
|
Reference in New Issue
Block a user