aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source/main.cpp
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2004-08-31 04:07:35 +0000
committerThomas Grill <xovo@users.sourceforge.net>2004-08-31 04:07:35 +0000
commit1a23e8233e6c1cbc30b9ddee4df153c21f4b282b (patch)
tree1c79382a41ef857e5beeed6f27ca1c85c81ddac1 /externals/grill/py/source/main.cpp
parentd28900c480f4ea568acdff80372f12383d463e8c (diff)
""
svn path=/trunk/; revision=1982
Diffstat (limited to 'externals/grill/py/source/main.cpp')
-rw-r--r--externals/grill/py/source/main.cpp60
1 files changed, 32 insertions, 28 deletions
diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp
index 034fefd2..20e7a865 100644
--- a/externals/grill/py/source/main.cpp
+++ b/externals/grill/py/source/main.cpp
@@ -279,7 +279,7 @@ V py::AddToPath(const C *dir)
if(pobj && PyList_Check(pobj)) {
int i,n = PyList_Size(pobj);
for(i = 0; i < n; ++i) {
- PyObject *pt = PyList_GetItem(pobj,i);
+ PyObject *pt = PyList_GetItem(pobj,i); // borrowed reference
if(PyString_Check(pt) && !strcmp(dir,PyString_AS_STRING(pt))) break;
}
if(i == n) { // string is not yet existent in path
@@ -296,33 +296,37 @@ static PyObject *output = NULL;
// post to the console
PyObject* py::StdOut_Write(PyObject* self, PyObject* args)
{
- if(PySequence_Check(args)) {
- int sz = PySequence_Size(args);
- for(int i = 0; i < sz; ++i) {
- PyObject *val = PySequence_GetItem(args,i); // borrowed
- PyObject *str = PyObject_Str(val);
- char *cstr = PyString_AS_STRING(str);
- char *lf = strchr(cstr,'\n');
-
- // line feed in string
- if(!lf) {
- // no -> just append
- if(output)
- PyString_ConcatAndDel(&output,str);
- else
- output = str;
- }
- else {
- // yes -> append up to line feed, reset output buffer to string remainder
- PyObject *part = PyString_FromStringAndSize(cstr,lf-cstr);
- if(output)
- PyString_ConcatAndDel(&output,part);
- else
- output = part;
- post(PyString_AS_STRING(output));
- Py_DECREF(output);
- output = PyString_FromString(lf+1);
- }
+ // should always be a tuple
+ FLEXT_ASSERT(PyTuple_Check(args));
+
+ int sz = PyTuple_Size(args);
+ for(int i = 0; i < sz; ++i) {
+ PyObject *val = PyTuple_GetItem(args,i); // borrowed reference
+ PyObject *str = PyObject_Str(val); // new reference
+ char *cstr = PyString_AS_STRING(str);
+ char *lf = strchr(cstr,'\n');
+
+ // line feed in string
+ if(!lf) {
+ // no -> just append
+ if(output)
+ PyString_ConcatAndDel(&output,str); // str is decrefd
+ else
+ output = str; // take str reference
+ }
+ else {
+ // yes -> append up to line feed, reset output buffer to string remainder
+ PyObject *part = PyString_FromStringAndSize(cstr,lf-cstr); // new reference
+ if(output)
+ PyString_ConcatAndDel(&output,part); // str is decrefd
+ else
+ output = part; // take str reference
+
+ // output concatenated string
+ post(PyString_AS_STRING(output));
+
+ Py_DECREF(output);
+ output = PyString_FromString(lf+1); // new reference
}
}