Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / qt / 2007-06

Qt fix for try..except in CopyUnicodeToPWideString()

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

zeljko

Hi,
I've located all problems and here is the fix.

1.Qt bindings (Den this is for you ;) ).
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());

}

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);

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 ;)

zeljko

Unknown author
to Felipe Monteiro de Carvalho

Quoting Felipe Monteiro de Carvalho :

Show quoted text 6 lines
On 6/26/07, zeljko wrote: > Any feedback is welcome ;) Great work =) I'll apply that soon

One more thing, I think that this is fixed at all, I've also removed all ifdef's from qt43.CopyUnicodeToPWideString() so all platforms uses SetString(S, Unicode, Len); without any try..except, and without any error ;)
There's another small patch for binding + things I mentioned in my previous post.
In qlineedit.hk find lines which says
PWideString t_p1;
and change so it looks like
PWideString t_p1 = 0 ;

(and don't forget to add if (qs !=0 && ps) in bindings.h !

Additional change for TQtLineEdit constructor is not necessary, since all problems arised from those 2 changes in bindings. I'll take a look to other hooks and search for uninitialized PWideStrings.

now it really works nice ;)

zeljko

zeljko
to Felipe Monteiro de Carvalho: Great work =) I'll apply that soon Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 6 lines
On 6/26/07, zeljko wrote: > Any feedback is welcome ;) Great work =) I'll apply that soon

affected hooks (widgets):

qtextbrowser.hk
qspinbox.hk
qstatusbar.hk
qlineedit.hk
qlistwidget.hk
qlabel.hk
qcombobox.hk

search for var declaration
PWideString someting;
replace with
PWideString something = 0;

Those uninitialized pointers produced a real mess in above widgets.

Tested with all components, didn't found any problem at all (using SetString() inside CopyUnicodeToPWideString() , so it's now platform independent function (no ifdefs).

end of transmission ;)

zeljko

Den Jean
to zeljko: I've located all problems and here is the fix. 1.Qt bindings (Den this is for you ;) ).…
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

Show quoted text 15 lines
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.

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 :-)

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)

Show quoted text 14 lines
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

Show quoted text 7 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.

zeljko

regards,

Den Jean

Felipe Monteiro de Carvalho
to Den Jean
Den Jean wrote
I do not have any AVs in linux, my lcl program is too simple probably :-)

By the way, your linux dlls don't work on my system or on the system from zeljko. They raise float-pointing errors on startup. They used to work before. Did anything change on your system?

Also, please take a look at the problems on mac with structures. Rectangles and other things seam to get inverted. This applies to lot's of function. I already post a detailed description some days ago. This is keeping me from porting the magnifier and also testing some important things on the mac compiler.

thanks,

Felipe Monteiro de Carvalho
zeljko
to Den Jean: nice :-) I am listening Like the "try...except...end;" trick this hides problems. ("ps"…
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

zeljko
to Felipe Monteiro de Carvalho: By the way, your linux dlls don't work on my system or on the system from zeljko. They…
Felipe Monteiro de Carvalho wrote 7 lines
On 7/3/07, Den Jean wrote: > I do not have any AVs in linux, my lcl program is too simple > probably :-) By the way, your linux dlls don't work on my system or on the system from zeljko. They raise float-pointing errors on startup. They used to work before. Did anything change on your system?

I have to compile my Qt4 without stl --no-stl (I have gcc-3.4.2, glibc-2.3.4, so maybe, that's the reason why it raises AV).
Felipe, what is glibc version at your system ?

zeljko

zeljko
to Den Jean: nice :-) I am listening Like the "try...except...end;" trick this hides problems. ("ps"…
Den Jean wrote 7 lines
On Tuesday 26 June 2007 05:17:28 pm zeljko wrote: > inline void copyQStringToPWideString(const QString &qs, PWideString ps) > { > if (qs != 0 && ps) /* we must check our params */ > copyUnicodeToPWideString(qs.unicode(), ps, qs.length()); > }

so, I've recompiled bindings without if (qs != 0 && ps) and it works, just PWideStrings assignments in hooks have to be initialized to 0 eg. PWideString myws = 0;

zeljko

Den Jean
to zeljko: affected hooks (widgets): qtextbrowser.hk qspinbox.hk qstatusbar.hk qlineedit.hk…
am zeljko wrote 6 lines
search for var declaration PWideString someting; replace with PWideString something = 0; Those uninitialized pointers produced a real mess in above widgets.

Note that I did not add the "= 0" initialization,
but I added a factory call. Only pascal compiler can create widestring with refcount and len before the pointer.

....
PWideString t_p1;
initializePWideString(t_p1);   <<-----------
copyQStringToPWideString(p1, t_p1);
(*(func_type)valueChanged2_event.func)(valueChanged2_event.data, t_p1);
finalizePWideString(t_p1);
....

So with this version (no "= 0"), are your problems gone ?

regards,

Den Jean

zeljko
to Den Jean
Den Jean wrote 21 lines
On Wednesday 27 June 2007 10:07:34 am zeljko wrote: > search for var declaration > PWideString someting; > replace with > PWideString something = 0; > > Those uninitialized pointers produced a real mess in above widgets. Note that I did not add the "= 0" initialization, but I added a factory call. Only pascal compiler can create widestring with refcount and len before the pointer. .... PWideString t_p1; initializePWideString(t_p1); <<----------- copyQStringToPWideString(p1, t_p1); (*(func_type)valueChanged2_event.func)(valueChanged2_event.data, t_p1); finalizePWideString(t_p1); .... So with this version (no "= 0"), are your problems gone ?

yes, there's no more problems, you can remove PROTECT ifdef and pointer check from bindings.h. You must know that I don't know how your bindings generator works, I've fixed problem for my self as best as I know , and it worked ok also ;)

tnx

zeljko