wxMutex* wxPyTMutex = NULL;
#endif
+#define DEFAULTENCODING_SIZE 64
+static char wxPyDefaultEncoding[DEFAULTENCODING_SIZE] = "ascii";
static PyObject* wxPython_dict = NULL;
static PyObject* wxPyAssertionError = NULL;
//---------------------------------------------------------------------------
-
-void wxPyClientData_dtor(wxPyClientData* self) {
- if (! wxPyDoingCleanup) { // Don't do it during cleanup as Python
- // may have already garbage collected the object...
+void wxPyUserData_dtor(wxPyUserData* self) {
+ if (! wxPyDoingCleanup) {
bool blocked = wxPyBeginBlockThreads();
Py_DECREF(self->m_obj);
self->m_obj = NULL;
}
}
-void wxPyUserData_dtor(wxPyUserData* self) {
- if (! wxPyDoingCleanup) {
- bool blocked = wxPyBeginBlockThreads();
- Py_DECREF(self->m_obj);
+
+void wxPyClientData_dtor(wxPyClientData* self) {
+ if (! wxPyDoingCleanup) { // Don't do it during cleanup as Python
+ // may have already garbage collected the object...
+ if (self->m_incRef) {
+ bool blocked = wxPyBeginBlockThreads();
+ Py_DECREF(self->m_obj);
+ wxPyEndBlockThreads(blocked);
+ }
self->m_obj = NULL;
- wxPyEndBlockThreads(blocked);
}
}
+
// This is called when an OOR controled object is being destroyed. Although
// the C++ object is going away there is no way to force the Python object
// (and all references to it) to die too. This causes problems (crashes) in
}
- // Only if there is more than one reference to the object
- if ( !wxPyDoingCleanup && self->m_obj->ob_refcnt > 1 ) {
+ // Only if there is more than one reference to the object and we are
+ // holding the OOR reference:
+ if ( !wxPyDoingCleanup && self->m_obj->ob_refcnt > 1 && self->m_incRef) {
// bool isInstance = wxPyInstance_Check(self->m_obj);
// TODO same here
//wxASSERT_MSG(isInstance, wxT("m_obj not an instance!?!?!"));
}
wxPyInputStream::~wxPyInputStream() {
- /* do nothing */
+ if (m_wxis)
+ delete m_wxis;
}
return 0;
}
+
wxFileOffset wxPyCBInputStream::OnSysSeek(wxFileOffset off, wxSeekMode mode) {
bool blocked = wxPyBeginBlockThreads();
-#if defined( __WINCE__) || defined(_LARGE_FILES) || wxHAS_HUGE_FILES
- // wxFileOffset is a 64-bit value...
- PyObject* arglist = Py_BuildValue("(Li)", off, mode);
-#else
- PyObject* arglist = Py_BuildValue("(ii)", off, mode);
-#endif
+ PyObject* arglist = PyTuple_New(2);
+
+ if (sizeof(wxFileOffset) > sizeof(long))
+ // wxFileOffset is a 64-bit value...
+ PyTuple_SET_ITEM(arglist, 0, PyLong_FromLongLong(off));
+ else
+ PyTuple_SET_ITEM(arglist, 0, PyInt_FromLong(off));
+
+ PyTuple_SET_ITEM(arglist, 1, PyInt_FromLong(mode));
+
+
PyObject* result = PyEval_CallObject(m_seek, arglist);
Py_DECREF(arglist);
Py_XDECREF(result);
Py_DECREF(arglist);
wxFileOffset o = 0;
if (result != NULL) {
-#if defined( __WINCE__) || defined(_LARGE_FILES) || wxHAS_HUGE_FILES
if (PyLong_Check(result))
o = PyLong_AsLongLong(result);
else
-#endif
o = PyInt_AsLong(result);
Py_DECREF(result);
};
#if wxUSE_UNICODE
PyObject* uni = source;
if (PyString_Check(source)) {
- uni = PyUnicode_FromObject(source);
+ uni = PyUnicode_FromEncodedObject(source, wxPyDefaultEncoding, "strict");
if (PyErr_Occurred()) return NULL;
}
target = new wxString();
#else
// Convert to a string object if it isn't already, then to wxString
PyObject* str = source;
- if (!PyString_Check(source)) {
+ if (PyUnicode_Check(source)) {
+ str = PyUnicode_AsEncodedString(source, wxPyDefaultEncoding, "strict");
+ if (PyErr_Occurred()) return NULL;
+ }
+ else if (!PyString_Check(source)) {
str = PyObject_Str(source);
if (PyErr_Occurred()) return NULL;
}
// Convert to a unicode object, if not already, then to a wxString
PyObject* uni = source;
if (!PyUnicode_Check(source)) {
- uni = PyUnicode_FromObject(source);
+ uni = PyUnicode_FromEncodedObject(source, wxPyDefaultEncoding, "strict");
if (PyErr_Occurred()) return wxEmptyString; // TODO: should we PyErr_Clear?
}
size_t len = PyUnicode_GET_SIZE(uni);
#else
// Convert to a string object if it isn't already, then to wxString
PyObject* str = source;
- if (!PyString_Check(source)) {
+ if (PyUnicode_Check(source)) {
+ str = PyUnicode_AsEncodedString(source, wxPyDefaultEncoding, "strict");
+ if (PyErr_Occurred()) return wxEmptyString; // TODO: should we PyErr_Clear?
+ }
+ else if (!PyString_Check(source)) {
str = PyObject_Str(source);
if (PyErr_Occurred()) return wxEmptyString; // TODO: should we PyErr_Clear?
}
}
+
+void wxSetDefaultPyEncoding(const char* encoding)
+{
+ strncpy(wxPyDefaultEncoding, encoding, DEFAULTENCODING_SIZE);
+}
+
+const char* wxGetDefaultPyEncoding()
+{
+ return wxPyDefaultEncoding;
+}
+
//----------------------------------------------------------------------