Den Jean wrote 28 lines
On Tuesday 26 June 2007 05:17:28 pm zeljko wrote:
> Hi,
> I've located all problems and here is the fix.
nice :-)
> 1.Qt bindings (Den this is for you ;) ).
I am listening
> bindhelp.h
>
> inline void copyQStringToPWideString(const QString &qs, PWideString ps)
> {
> copyUnicodeToPWideString(qs.unicode(), ps, qs.length());
> }
>
>
> should be
>
> inline void copyQStringToPWideString(const QString &qs, PWideString ps)
> {
> if (qs != 0 && ps) /* we must check our params */
> copyUnicodeToPWideString(qs.unicode(), ps, qs.length());
> }
Like the "try...except...end;" trick this hides problems.
("ps" should not be nil). We should first identify all problems.
As I said below, maybe this part isn't needed anymore , if I have some time later, I'll recompile bindings without this oneliner and run test.
Show quoted text 7 lines
I already found one (no factory call on reference counted PWidestring)
and fixed it (i.e. V1.38)
You are better placed to verify if this resolves all the problems you could
trigger. (I do not have any AVs in linux, my lcl program is too simple
probably :-)
You have to drop TEdit onto form, and then try to type something inside. textChanged() should trigger and raise av.
Problem lies in events (hooks) not in bindings routines, I've mentioned later all files where are problems. All files in hooks directory (which declares PWidestring variables have to be initialized as 0 eg. this is snippet from qlineedit.hk. Now it doesn't raise any AV.
I didn't remove "if (qs != 0 && ps)" later, but it's possible that it'll work ok now without pointers check inside copyQStringToPWideString(). One thing you must know: This works now without single problem, heavy tested.
private slots:
void textChanged_hook(const QString& p1) {
if ( textChanged_event.func ) {
typedef void (*func_type)(void *data, PWideString p1);
PWideString t_p1 = 0; /* this was killer */
copyQStringToPWideString(p1, t_p1);
(*(func_type)textChanged_event.func)(textChanged_event.data, t_p1);
}
}
void textEdited_hook(const QString& p1) {
if ( textEdited_event.func ) {
typedef void (*func_type)(void *data, PWideString p1);
PWideString t_p1 = 0; /* this was killer */
copyQStringToPWideString(p1, t_p1);
(*(func_type)textEdited_event.func)(textEdited_event.data, t_p1);
}
}
Show quoted text 23 lines
When we (euh you ;-) verified this really fixes it, I will add the param
protection as default (now it is enclosed by a define). This will protect
against providing nil as parameter in Pascal. I will also investigate if I
can disallow this at compile time with "var Widestring", instead
of "PWidestring" (ABI question)
> 2.qwidgets.pas in
>
> function TQtLineEdit.CreateWidget(const AParams: TCreateParams):
> QWidgetH;
>
> Str := UTF8Decode((LCLObject as TCustomEdit).Text);
> Result := QLineEdit_create(@Str, Parent);
>
> should be
>
> Str := UTF8Decode((LCLObject as TCustomEdit).Text);
> if Length(Str) = 0 then
> Str := #0;
> Result := QLineEdit_create(@Str, Parent);
Did not look into this, tell me if it still exists
not, it's fixed , forget it, this is written before I've catched uninitialized pointers in hooks (there was just oneliner in copyQStringToPWideString()).
Show quoted text 10 lines
> I've founded only in QLineEdit that empty string initalization (length of
> Str is 0) raises AV.
>
> now, after recompiling bindings, and fix in TQtLineEdit constructor, you
> can remove try .. except and test.
>
> Any feedback is welcome ;)
thanks for all the great work.
you're welcome ;)
zeljko