View Issue Details

IDProjectCategoryView StatusLast Update
0001658ScribusScripterpublic2005-03-01 07:07
ReporterringercAssigned Toringerc 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86 LinuxOSFedora CoreOS Version3
Product Version1.3.0cvs 
Fixed in Version1.3.0cvs 
Summary0001658: PATCH: Minor scripter fixes, initialize variable in ScrAction constructor
DescriptionThis patch includes three scripter fixes:
   - fix scriptplugin.cpp:tr()'s string handling
   - more correctly create the unicode string for the top-level docstring
   - fix incorrect line wrapping in top level docstring

It also ensures that the ScrAction constructors all initialize containerWidgetAddedTo correctly.
TagsNo tags attached.
Patch

Relationships

child of 0003813 acknowledged Metabug: Scripter 

Activities

2005-02-10 07:55

 

valgrind_bugs_1.diff (4,396 bytes)   
Index: scraction.cpp
===================================================================
RCS file: /cvs/Scribus/scribus/Attic/scraction.cpp,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 scraction.cpp
--- scraction.cpp	31 Jan 2005 00:11:53 -0000	1.1.2.10
+++ scraction.cpp	10 Feb 2005 08:43:25 -0000
@@ -23,6 +23,7 @@
 	menuType=ScrAction::Normal;
 	menuIndex=-1;
 	widgetAddedTo=NULL;
+	containerWidgetAddedTo=NULL;
 }
 
 ScrAction::ScrAction( const QString & menuText, QKeySequence accel, QObject * parent, const char * name ) : QAction( menuText, accel, parent, name )
@@ -30,6 +31,7 @@
 	menuType=ScrAction::Normal;
 	menuIndex=-1;
 	widgetAddedTo=NULL;
+	containerWidgetAddedTo=NULL;
 }
 
 ScrAction::ScrAction( MenuType mType, const QIconSet & icon, const QString & menuText, QKeySequence accel, QObject * parent, const char * name, int extraInt, double extraDouble, QString extraQString ) : QAction( icon, menuText, accel, parent, name )
@@ -37,6 +39,7 @@
 	setIconSizes();
 	menuIndex=-1;
 	widgetAddedTo=NULL;
+	containerWidgetAddedTo=NULL;
 	menuType=mType;
 	switch (mType)
 	{
@@ -78,6 +81,7 @@
 	setIconSizes();
 	menuIndex=-1;
 	widgetAddedTo=NULL;
+	containerWidgetAddedTo=NULL;
 }
 
 ScrAction::~ScrAction()
Index: plugins/scriptplugin/scriptplugin.cpp
===================================================================
RCS file: /cvs/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp,v
retrieving revision 1.33.2.43
diff -u -r1.33.2.43 scriptplugin.cpp
--- plugins/scriptplugin/scriptplugin.cpp	9 Feb 2005 12:00:24 -0000	1.33.2.43
+++ plugins/scriptplugin/scriptplugin.cpp	10 Feb 2005 08:43:25 -0000
@@ -640,8 +640,13 @@
 	 * a text string in a particular text encoding.
 	 */
 	//QCString utfTranslated = translated.utf8();
-	const char* trch = translated.utf8().data();
-	return strndup(trch, strlen(trch));
+	QCString trch = translated.utf8();
+	char* utfstr = strdup(trch.data());
+	if (!utfstr)
+		// Complain, but then return NULL anyway. Python will treat NULL as
+		// "no value" so that's fine.
+		qDebug("scriptplugin.cpp:tr() - strdup() failure");
+	return utfstr;
 }
 
 /* Now we're using the more pythonic convention for names:
@@ -998,11 +1003,11 @@
 optional (non-keyword) parameter, a frame name.\n\
 Many exceptions are also common across most functions. These are\n\
 not currently documented in the docstring for each function.\n\
-- Many functions will raise a NoDocOpenError if you try to use them\
+- Many functions will raise a NoDocOpenError if you try to use them\n\
 without a document to operate on.\n\
-- If you do not pass a frame name to a function that requires one,\
-the function will use the currently selected frame, if any, or\
-raise a NoValidObjectError if it can't find anything to operate\
+- If you do not pass a frame name to a function that requires one,\n\
+the function will use the currently selected frame, if any, or\n\
+raise a NoValidObjectError if it can't find anything to operate\n\
 on.\n\
 - Many functions will raise WrongFrameTypeError if you try to use them\n\
 on a frame type that they do not make sense with. For example, setting\n\
@@ -1013,15 +1018,25 @@
 any function as provided here and in its docstring is incomplete.\n\
 \n\
 Details of what exceptions each function may throw are provided on the\n\
-function's documentation.");
+function's documentation, though as with most Python code this list\n\
+is not exhaustive due to exceptions from called functions.\n\
+");
 
-	// Py_UNICODE is a typedef for unsigned short
-	PyObject* uniDocStr = Py_BuildValue(const_cast<char*>("u"), (Py_UNICODE*)(docstring.ucs2()));
-	if (uniDocStr == NULL)
-		qDebug("Failed to create module-level docstring object!");
+	PyObject* docStr = PyString_FromString(docstring.utf8().data());
+	if (!docStr)
+		qDebug("Failed to create module-level docstring (couldn't make str)");
 	else
-		PyDict_SetItemString(d, const_cast<char*>("__doc__"), uniDocStr);
-	Py_DECREF(uniDocStr);
+	{
+		PyObject* uniDocStr = PyUnicode_FromEncodedObject(docStr, "utf-8", NULL);
+		Py_DECREF(docStr);
+		docStr = NULL;
+		if (!uniDocStr)
+			qDebug("Failed to create module-level docstring object (couldn't make unicode)");
+		else
+			PyDict_SetItemString(d, const_cast<char*>("__doc__"), uniDocStr);
+		Py_DECREF(uniDocStr);
+		uniDocStr = NULL;
+	}
 
 	// Wrap up pointers to the the QApp and main window and push them out
 	// to Python.
valgrind_bugs_1.diff (4,396 bytes)   

ringerc

2005-02-10 07:56

reporter   ~0003676

Patch applies with -p0 in Scribus/scribus dir (forgot to generate it from the module root).

subik

2005-02-10 16:10

manager   ~0003681

can anybody apply it instead of me? i'm too busy till the end of the week to test it properly :-/
sorry

Issue History

Date Modified Username Field Change
2005-02-10 07:55 ringerc New Issue
2005-02-10 07:55 ringerc File Added: valgrind_bugs_1.diff
2005-02-10 07:56 ringerc Note Added: 0003676
2005-02-10 16:10 subik Note Added: 0003681
2005-03-01 07:02 ringerc Status new => assigned
2005-03-01 07:02 ringerc Assigned To => ringerc
2005-03-01 07:07 ringerc Status assigned => closed
2005-03-01 07:07 ringerc Resolution open => fixed
2005-03-01 07:07 ringerc Fixed in Version => 1.3.0cvs
2006-05-13 21:45 christoph_s Relationship added child of 0003813