Browse Source

Convert PyString_*Ex functions over to plString

Adam Johnson 13 years ago
parent
commit
e0cd86bfc1
  1. 11
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp
  2. 4
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h
  3. 14
      Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp
  4. 4
      Sources/Plasma/FeatureLib/pfPython/pyPlayer.h
  5. 15
      Sources/Plasma/FeatureLib/pfPython/pyPlayerGlue.cpp
  6. 12
      Sources/Plasma/FeatureLib/pfPython/pyStatusLog.cpp
  7. 6
      Sources/Plasma/FeatureLib/pfPython/pyStatusLog.h

11
Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp

@ -42,19 +42,20 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "pyGlueHelpers.h"
#include "plString.h"
char* PyString_AsStringEx(PyObject* obj)
plString PyString_AsStringEx(PyObject* obj)
{
if (PyString_Check(obj))
return hsStrcpy(PyString_AsString(obj));
return plString::FromUtf8(PyString_AsString(obj));
else if (PyUnicode_Check(obj))
{
PyObject* utf8 = PyUnicode_AsUTF8String(obj);
char* buf = hsStrcpy(PyString_AsString(utf8));
plString str = plString::FromUtf8(PyString_AsString(utf8));
Py_DECREF(utf8);
return buf;
return str;
} else
return NULL; // You suck.
return plString::Null;
}
bool PyString_CheckEx(PyObject* obj)

4
Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h

@ -45,7 +45,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <Python.h>
// Useful string functions
char* PyString_AsStringEx(PyObject* obj);
class plString;
plString PyString_AsStringEx(PyObject* obj);
bool PyString_CheckEx(PyObject* obj);
// A set of macros to take at least some of the tediousness out of creating straight python glue code

14
Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp

@ -287,11 +287,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadJPEGFromDisk, args, "Params: filename,widt
if (PyString_CheckEx(filenameObj))
{
char* text = PyString_AsStringEx(filenameObj);
wchar_t* wText = hsStringToWString(text);
PyObject* ret = pyImage::LoadJPEGFromDisk(wText, width, height);
delete[] wText;
delete[] text;
plString text = PyString_AsStringEx(filenameObj);
PyObject* ret = pyImage::LoadJPEGFromDisk(_TEMP_CONVERT_TO_WCHAR_T(text), width, height);
return ret;
}
else
@ -312,11 +309,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadPNGFromDisk, args, "Params: filename,width
}
if (PyString_CheckEx(filenameObj))
{
char* text = PyString_AsStringEx(filenameObj);
wchar_t* wText = hsStringToWString(text);
PyObject* ret = pyImage::LoadPNGFromDisk(wText, width, height);
delete[] wText;
delete[] text;
plString text = PyString_AsStringEx(filenameObj);
PyObject* ret = pyImage::LoadPNGFromDisk(_TEMP_CONVERT_TO_WCHAR_T(text), width, height);
return ret;
}
else

4
Sources/Plasma/FeatureLib/pfPython/pyPlayer.h

@ -62,8 +62,8 @@ class pyPlayer
protected:
plKey fAvatarKey;
std::string fPlayerName;
uint32_t fPlayerID;
float fDistSq; // from local player, temp
uint32_t fPlayerID;
float fDistSq; // from local player, temp
hsBool fIsCCR;
hsBool fIsServer;

15
Sources/Plasma/FeatureLib/pfPython/pyPlayerGlue.cpp

@ -65,31 +65,31 @@ PYTHON_INIT_DEFINITION(ptPlayer, args, keywords)
}
pyKey* key = NULL;
char* name = NULL;
plString name;
uint32_t pid = -1;
float distSeq = -1;
if (pyKey::Check(firstObj))
{
key = pyKey::ConvertFrom(firstObj);
if (!(name = PyString_AsStringEx(secondObj)))
if (!PyString_CheckEx(secondObj))
{
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
PYTHON_RETURN_INIT_ERROR;
}
} else
name = PyString_AsStringEx(secondObj);
if (!(PyNumber_Check(thirdObj) && PyFloat_Check(fourthObj)))
{
delete[] name;
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
PYTHON_RETURN_INIT_ERROR;
}
pid = PyNumber_AsSsize_t(thirdObj, NULL);
distSeq = (float)PyFloat_AsDouble(fourthObj);
} else if (name = PyString_AsStringEx(firstObj)) {
} else if (PyString_CheckEx(firstObj)) {
name = PyString_AsStringEx(firstObj);
if (!PyNumber_Check(secondObj) || thirdObj || fourthObj)
{
delete[] name;
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
PYTHON_RETURN_INIT_ERROR;
}
@ -100,8 +100,7 @@ PYTHON_INIT_DEFINITION(ptPlayer, args, keywords)
PYTHON_RETURN_INIT_ERROR;
}
self->fThis->Init(key, name, pid, distSeq);
delete[] name;
self->fThis->Init(key, _TEMP_CONVERT_TO_CONST_CHAR(name), pid, distSeq);
PYTHON_RETURN_INIT_OK;
}

12
Sources/Plasma/FeatureLib/pfPython/pyStatusLog.cpp

@ -62,14 +62,14 @@ pyStatusLog::~pyStatusLog()
}
hsBool pyStatusLog::Open(const char* logName, uint32_t numLines, uint32_t flags)
hsBool pyStatusLog::Open(plString logName, uint32_t numLines, uint32_t flags)
{
// make sure its closed first
Close();
// create a status log guy for this
fICreatedLog = true;
fLog = plStatusLogMgr::GetInstance().CreateStatusLog( (uint8_t)numLines, logName, flags );
fLog = plStatusLogMgr::GetInstance().CreateStatusLog( (uint8_t)numLines, _TEMP_CONVERT_TO_CONST_CHAR(logName), flags );
if (fLog)
{
fLog->SetForceLog(true);
@ -78,18 +78,18 @@ hsBool pyStatusLog::Open(const char* logName, uint32_t numLines, uint32_t flags)
return false;
}
hsBool pyStatusLog::Write(const char* text)
hsBool pyStatusLog::Write(plString text)
{
if (fLog)
{
fLog->AddLine(text);
fLog->AddLine(_TEMP_CONVERT_TO_CONST_CHAR(text));
return true;
}
return false;
}
hsBool pyStatusLog::WriteColor(const char* text, pyColor& color)
hsBool pyStatusLog::WriteColor(plString text, pyColor& color)
{
if (fLog)
{
@ -97,7 +97,7 @@ hsBool pyStatusLog::WriteColor(const char* text, pyColor& color)
((uint32_t)(color.getRed()*255)<<16) +
((uint32_t)(color.getGreen()*255)<<8) +
((uint32_t)(color.getBlue()*255));
fLog->AddLine( text, st_color );
fLog->AddLine( _TEMP_CONVERT_TO_CONST_CHAR(text), st_color );
return true;
}

6
Sources/Plasma/FeatureLib/pfPython/pyStatusLog.h

@ -80,9 +80,9 @@ public:
static void AddPlasmaClasses(PyObject *m);
static void AddPlasmaConstantsClasses(PyObject *m);
virtual hsBool Open(const char* logName, uint32_t numLines, uint32_t flags);
virtual hsBool Write(const char* text);
virtual hsBool WriteColor(const char* text, pyColor& color);
virtual hsBool Open(plString logName, uint32_t numLines, uint32_t flags);
virtual hsBool Write(plString text);
virtual hsBool WriteColor(plString text, pyColor& color);
virtual void Close();
virtual hsBool IsOpen();

Loading…
Cancel
Save