PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate;
#define LEAVE_TCL \
- tcl_tstate = NULL; PyThread_release_lock(tcl_lock); Py_END_ALLOW_THREADS}
+ tcl_tstate = NULL; PyThread_release_lock(tcl_lock); Py_END_ALLOW_THREADS}
#define ENTER_OVERLAP \
Py_END_ALLOW_THREADS
#include <Events.h> /* For EventRecord */
typedef int (*TclMacConvertEventPtr) (EventRecord *eventPtr);
-void Tcl_MacSetEventProc (TclMacConvertEventPtr procPtr);
-int TkMacConvertEvent (EventRecord *eventPtr);
+void Tcl_MacSetEventProc(TclMacConvertEventPtr procPtr);
+int TkMacConvertEvent(EventRecord *eventPtr);
-staticforward int PyMacConvertEvent (EventRecord *eventPtr);
+staticforward int PyMacConvertEvent(EventRecord *eventPtr);
#if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
#pragma import on
{
if (PyString_Check(value))
return PyString_AsString(value);
+ else if (PyUnicode_Check(value)) {
+ PyObject *v = PyUnicode_AsUTF8String(value);
+ if (v == NULL)
+ return NULL;
+ if (PyList_Append(tmp, v) != 0) {
+ Py_DECREF(v);
+ return NULL;
+ }
+ Py_DECREF(v);
+ return PyString_AsString(v);
+ }
else {
PyObject *v = PyObject_Str(value);
- PyList_Append(tmp, v);
+ if (v == NULL)
+ return NULL;
+ if (PyList_Append(tmp, v) != 0) {
+ Py_DECREF(v);
+ return NULL;
+ }
Py_DECREF(v);
return PyString_AsString(v);
}
char **argv = NULL;
int fvStore[ARGSZ];
int *fv = NULL;
- int argc = 0, i;
+ int argc = 0, fvc = 0, i;
char *res = NULL;
if (!(tmp = PyList_New(0)))
else if (!PyTuple_Check(args)) {
argc = 1;
fv[0] = 0;
- argv[0] = AsString(args, tmp);
+ if (!(argv[0] = AsString(args, tmp)))
+ goto finally;
}
else {
argc = PyTuple_Size(args);
fv[i] = 1;
if (!(argv[i] = Merge(v)))
goto finally;
+ fvc++;
}
else if (v == Py_None) {
argc = i;
}
else {
fv[i] = 0;
- argv[i] = AsString(v, tmp);
+ if (!(argv[i] = AsString(v, tmp)))
+ goto finally;
+ fvc++;
}
}
}
res = Tcl_Merge(argc, argv);
+ if (res == NULL)
+ PyErr_SetString(Tkinter_TclError, "merge failed");
finally:
- for (i = 0; i < argc; i++)
+ for (i = 0; i < fvc; i++)
if (fv[i]) {
ckfree(argv[i]);
}
else if (PyUnicode_Check(value)) {
#if TKMAJORMINOR <= 8001
/* In Tcl 8.1 we must use UTF-8 */
- PyObject* utf8 = PyUnicode_AsUTF8String (value);
+ PyObject* utf8 = PyUnicode_AsUTF8String(value);
if (!utf8)
return 0;
- result = Tcl_NewStringObj (PyString_AS_STRING (utf8),
- PyString_GET_SIZE (utf8));
+ result = Tcl_NewStringObj(PyString_AS_STRING(utf8),
+ PyString_GET_SIZE(utf8));
Py_DECREF(utf8);
return result;
#else /* TKMAJORMINOR > 8001 */
if (sizeof(Py_UNICODE) != sizeof(Tcl_UniChar)) {
/* XXX Should really test this at compile time */
PyErr_SetString(PyExc_SystemError,
- "Py_UNICODE and Tcl_UniChar differ in size");
+ "Py_UNICODE and Tcl_UniChar differ in size");
return 0;
}
return Tcl_NewUnicodeObj(PyUnicode_AS_UNICODE(value),
p = strchr(p, '\0');
res = PyUnicode_DecodeUTF8(s, (int)(p-s), "strict");
if (res == NULL) {
- PyErr_Clear();
- res = PyString_FromStringAndSize(s, (int)(p-s));
+ PyErr_Clear();
+ res = PyString_FromStringAndSize(s, (int)(p-s));
}
}
}
char **argv = NULL;
int fvStore[ARGSZ];
int *fv = NULL;
- int argc = 0, i;
+ int argc = 0, fvc = 0, i;
PyObject *res = NULL; /* except this has a different type */
Tcl_CmdInfo info; /* and this is added */
Tcl_Interp *interp = Tkapp_Interp(self); /* and this too */
else if (!PyTuple_Check(args)) {
argc = 1;
fv[0] = 0;
- argv[0] = AsString(args, tmp);
+ if (!(argv[0] = AsString(args, tmp)))
+ goto finally;
}
else {
argc = PyTuple_Size(args);
fv[i] = 1;
if (!(argv[i] = Merge(v)))
goto finally;
+ fvc++;
}
else if (v == Py_None) {
argc = i;
}
else {
fv[i] = 0;
- argv[i] = AsString(v, tmp);
+ if (!(argv[i] = AsString(v, tmp)))
+ goto finally;
+ fvc++;
}
}
}
/* Copied from Merge() again */
finally:
- for (i = 0; i < argc; i++)
+ for (i = 0; i < fvc; i++)
if (fv[i]) {
ckfree(argv[i]);
}
PyObject *res = NULL;
cmd = Merge(args);
- if (!cmd)
- PyErr_SetString(Tkinter_TclError, "merge failed");
-
- else {
+ if (cmd) {
int err;
ENTER_TCL
err = Tcl_GlobalEval(Tkapp_Interp(self), cmd);
else
res = PyString_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
- }
-
- if (cmd)
ckfree(cmd);
+ }
return res;
}
if (PyArg_ParseTuple(args, "sO:setvar", &name1, &newValue)) {
/* XXX Merge? */
s = AsString(newValue, tmp);
+ if (s == NULL)
+ return NULL;
ENTER_TCL
ok = Tcl_SetVar(Tkapp_Interp(self), name1, s, flags);
LEAVE_TCL
}
else {
PyErr_Clear();
- if (PyArg_ParseTuple(args, "ssO:setvar", &name1, &name2, &newValue)) {
- s = AsString (newValue, tmp);
+ if (PyArg_ParseTuple(args, "ssO:setvar",
+ &name1, &name2, &newValue)) {
+ s = AsString(newValue, tmp);
+ if (s == NULL)
+ return NULL;
ENTER_TCL
ok = Tcl_SetVar2(Tkapp_Interp(self), name1, name2,
s, flags);
res = PyString_FromString(s);
ckfree(s);
}
- else
- PyErr_SetString(Tkinter_TclError, "merge failed");
return res;
}
{
PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
PyObject *self, *func, *arg, *res, *tmp;
- int i;
+ int i, rv;
+ char *s;
ENTER_PYTHON
return PythonCmd_Error(interp);
}
- Tcl_SetResult(Tkapp_Interp(self), AsString(res, tmp), TCL_VOLATILE);
+ s = AsString(res, tmp);
+ if (s == NULL) {
+ rv = PythonCmd_Error(interp);
+ }
+ else {
+ Tcl_SetResult(Tkapp_Interp(self), s, TCL_VOLATILE);
+ rv = TCL_OK;
+ }
+
Py_DECREF(res);
Py_DECREF(tmp);
LEAVE_PYTHON
- return TCL_OK;
+ return rv;
}
static void
PyObject *file, *func;
int mask, tfile;
- if (!PyArg_ParseTuple(args, "OiO:createfilehandler", &file, &mask, &func))
+ if (!PyArg_ParseTuple(args, "OiO:createfilehandler",
+ &file, &mask, &func))
return NULL;
tfile = PyObject_AsFileDescriptor(file);
if (tfile < 0)
PyObject *func;
TkttObject *v;
- if (!PyArg_ParseTuple(args, "iO:createtimerhandler", &milliseconds, &func))
+ if (!PyArg_ParseTuple(args, "iO:createtimerhandler",
+ &milliseconds, &func))
return NULL;
if (!PyCallable_Check(func)) {
PyErr_SetString(PyExc_TypeError, "bad argument list");
static int
_bump(FlattenContext* context, int size)
{
- /* expand tuple to hold (at least) size new items. return true if
- successful, false if an exception was raised*/
+ /* expand tuple to hold (at least) size new items.
+ return true if successful, false if an exception was raised */
int maxsize = context->maxsize * 2;
int i, size;
if (depth > 1000) {
- PyErr_SetString(PyExc_ValueError,"nesting too deep in _flatten");
+ PyErr_SetString(PyExc_ValueError,
+ "nesting too deep in _flatten");
return 0;
} else if (PyList_Check(item)) {
size = PyList_GET_SIZE(item);
/* preallocate (assume no nesting) */
- if (context->size + size > context->maxsize && !_bump(context, size))
+ if (context->size + size > context->maxsize &&
+ !_bump(context, size))
return 0;
/* copy items to output tuple */
for (i = 0; i < size; i++) {
if (!_flatten1(context, o, depth + 1))
return 0;
} else if (o != Py_None) {
- if (context->size + 1 > context->maxsize && !_bump(context, 1))
+ if (context->size + 1 > context->maxsize &&
+ !_bump(context, 1))
return 0;
Py_INCREF(o);
- PyTuple_SET_ITEM(context->tuple, context->size++, o);
+ PyTuple_SET_ITEM(context->tuple,
+ context->size++, o);
}
}
} else if (PyTuple_Check(item)) {
/* same, for tuples */
size = PyTuple_GET_SIZE(item);
- if (context->size + size > context->maxsize && !_bump(context, size))
+ if (context->size + size > context->maxsize &&
+ !_bump(context, size))
return 0;
for (i = 0; i < size; i++) {
PyObject *o = PyTuple_GET_ITEM(item, i);
if (!_flatten1(context, o, depth + 1))
return 0;
} else if (o != Py_None) {
- if (context->size + 1 > context->maxsize && !_bump(context, 1))
+ if (context->size + 1 > context->maxsize &&
+ !_bump(context, 1))
return 0;
Py_INCREF(o);
- PyTuple_SET_ITEM(context->tuple, context->size++, o);
+ PyTuple_SET_ITEM(context->tuple,
+ context->size++, o);
}
}
} else {