Skip to content

Commit 0fd377e

Browse files
usiemsjcfr
authored andcommitted
[Backport] Limit string representation of argument list in length
otherwise when passing image data to the QImage constructor this can get rather long (cherry picked from commit MeVisLab/pythonqt@ea27670)
1 parent e747df2 commit 0fd377e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/PythonQtSlot.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,20 @@ PyObject *PythonQtMemberFunction_Call(PythonQtSlotInfo* info, PyObject* m_self,
327327
return nullptr;
328328
}
329329

330+
namespace {
331+
QString limitString(const QString& aString, int maxLength = 2000, const QString& ellipsis = "...")
332+
{
333+
if (aString.length() <= maxLength)
334+
return aString;
335+
336+
const int beforeSize = (maxLength - ellipsis.length()) / 2;
337+
auto beforeEllipsis = aString.left(beforeSize);
338+
auto afterEllipsis = aString.right(maxLength - ellipsis.length() - beforeSize);
339+
340+
return beforeEllipsis + ellipsis + afterEllipsis;
341+
}
342+
};
343+
330344
PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* objectToCall, PythonQtSlotInfo* info, PyObject *args, PyObject * kw, void* firstArg, void** directReturnValuePointer, PythonQtPassThisOwnershipType* passThisOwnershipToCPP)
331345
{
332346
int argc = args?PyTuple_Size(args):0;
@@ -381,7 +395,7 @@ PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* o
381395

382396
ok = PythonQtCallSlot(classInfo, objectToCall, combinedArgs, false, slotInfo, firstArg, &r, directReturnValuePointer, passThisOwnershipToCPP);
383397
if (!ok && !PyErr_Occurred()) {
384-
QString e = QString("Called ") + info->fullSignature() + " with wrong arguments: " + PythonQtConv::PyObjGetString(args);
398+
QString e = QString("Called ") + info->fullSignature() + " with wrong arguments: " + limitString(PythonQtConv::PyObjGetString(args));
385399
PyErr_SetString(PyExc_ValueError, QStringToPythonConstCharPointer(e));
386400
}
387401
} else {
@@ -413,7 +427,7 @@ PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* o
413427
}
414428
}
415429
if (!ok && !PyErr_Occurred()) {
416-
QString e = QString("Could not find matching overload for given arguments:\n" + PythonQtConv::PyObjGetString(args) + "\n The following slots are available:\n");
430+
QString e = QString("Could not find matching overload for given arguments:\n" + limitString(PythonQtConv::PyObjGetString(args)) + "\n The following slots are available:\n");
417431
PythonQtSlotInfo* i = info;
418432
while (i) {
419433
e += QString(i->fullSignature()) + "\n";
@@ -431,11 +445,11 @@ PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* o
431445
#endif
432446
ok = PythonQtCallSlot(classInfo, objectToCall, args, false, info, firstArg, &r, directReturnValuePointer, passThisOwnershipToCPP);
433447
if (!ok && !PyErr_Occurred()) {
434-
QString e = QString("Called ") + info->fullSignature() + " with wrong arguments: " + PythonQtConv::PyObjGetString(args);
448+
QString e = QString("Called ") + info->fullSignature() + " with wrong arguments: " + limitString(PythonQtConv::PyObjGetString(args));
435449
PyErr_SetString(PyExc_ValueError, QStringToPythonConstCharPointer(e));
436450
}
437451
} else {
438-
QString e = QString("Called ") + info->fullSignature() + " with wrong number of arguments: " + PythonQtConv::PyObjGetString(args);
452+
QString e = QString("Called ") + info->fullSignature() + " with wrong number of arguments: " + limitString(PythonQtConv::PyObjGetString(args));
439453
PyErr_SetString(PyExc_ValueError, QStringToPythonConstCharPointer(e));
440454
}
441455
}

0 commit comments

Comments
 (0)