Extending Wstring and Zstring with UDTs

General discussion for topics related to the FreeBASIC project or its community.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Extending Wstring and Zstring with UDTs

Post by MrSwiss »

I personally think, that we are currently dealing with a secondary issue.

Let me try to explain my point of view:
The currently implemented way, the CRT's file I/O functions (on WIN, at least)
are dealing with strings (everything converted to ANSI/ASCII before a call).

This behaviour is actually the very limitting factor (aka: priority issue).

Therefore the conversions (behind the scenes, FB to C), should be inverted.
(to actually only allow WString, originally or converted, handed over to those
I/O functions) Meaning of course, that they would need to be recoded in full.
Last edited by MrSwiss on Jul 01, 2019 16:54, edited 1 time in total.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Extending Wstring and Zstring with UDTs

Post by fxm »

@coderJeff,
Thank you for explaining your previous post, because I think I have now understood why 'If *pz Then ...' is accepted at compilation level:

Code: Select all

Dim As Zstring * 10 z = "FreeBASIC"
Dim As Zstring Ptr pz = @z

Dim As String s = "FreeBASIC"
Dim As String Ptr ps = @s

Dim As Boolean b
b = *pz  '' OK
b = z    '' error 181: Invalid assignment/conversion
b = *ps  '' error 181: Invalid assignment/conversion
b = s    '' error 181: Invalid assignment/conversion
So actually 'If *pz Then ...' (or 'If pz[0] Then ...') is converted into 'If (*pz)[0] Then ...'.
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: Extending Wstring and Zstring with UDTs

Post by Juergen Kuehlwein »

@MrSwiss,

please be patient, there already is work in progress behind the scenes. Jeff´s recent compiler changes (EXTENDS WSTRING) allows for a class-like-type acting as a string type. This makes a dynamic wide string tpye with full integration (can syntactically be used like a regular string type) possible. He found and fixed some bugs and inconsistencies regarding w/strings. It´s important to check and re-check all ramifications of these new possibilities in the context of the already existing features. Before going on you sure want to know, if you didn´t add new possibilities for existing or new problems.

The changes made and the changes necessary to get what you (and maybe many others want) are not trivial. So in order not to break existing code and to ensure safe future code, all of these little things are necessary.

JK
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Extending Wstring and Zstring with UDTs

Post by fxm »

If this automatic Zstring conversion was limited for a Byte only (and therefore not for an Integer nor a Boolean), 'If *pz Then ...' would probably be refused at compilation step.
(Wstring conversion limited to a Long or a Longint only, not for an Integer nor a Boolean)
Last edited by fxm on Jul 02, 2019 9:51, edited 3 times in total.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Extending Wstring and Zstring with UDTs

Post by MrSwiss »

@Juergen Kuehlwein,

unlike you, I don't think, that a dynamic WString is a prerequisite for the
proposed changes, and therefore, could easily be treated on it's own.

A fixed size WString, should be able to perform as needed, too.
(handed over as WString Ptr, since fix len "w/string type" isn't accepted)
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: Extending Wstring and Zstring with UDTs

Post by Juergen Kuehlwein »

@MrSwiss,

of course it will work with fixed size WSTRINGs too, but now that we have a chance for a dynamic wide string type in FreeBASIC, why not do it once and for good? If you cannot wait until it´s ready, you will have to do it yourself - sorry.

JK
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Extending Wstring and Zstring with UDTs

Post by fxm »

fxm wrote:If this automatic Zstring conversion was limited for a Byte only (and therefore not for an Integer nor a Boolean), 'If *pz Then ...' would probably be refused at compilation step.
(Wstring conversion limited to a Long or a Longint only, not for an Integer nor a Boolean)

To try to conclude on this problem of dereferencing a Zstring/Wstring null pointer when used in a condition expression ('If *p Then ...'), we do nothing because it's the normal functioning (but IMHO, not the expected)?
=>We do not add special note about dereferencing a Zstring/Wstring null pointer in documentation (working cases without automatic conversion, and crashing cases with automatic conversion)?
=> We do not fill in a bug report on this behavior of automatic conversion of a Zstring/Wstring pointer dereferenced when used in a condition expression?
Last edited by fxm on Jul 02, 2019 14:52, edited 1 time in total.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Extending Wstring and Zstring with UDTs

Post by MrSwiss »

From my point of view, there is only one thing worth a note, and that is:

Always check for "null pointer" before any other pointer usage!

(referres to any/all pointer types, if one wants to stay "on the safe side")
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Extending Wstring and Zstring with UDTs

Post by fxm »

Done:
- KeyPgOpValueOf → fxm [Added a caution about a null pointer use or a resulting address corresponding to invalid memory access]
- KeyPgOpPtrIndex → fxm [Added a caution about a null pointer use or a resulting address corresponding to invalid memory access]
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Extending Wstring and Zstring with UDTs

Post by MrSwiss »

Thx, fxm.

I've some questions regarding these changes:
  • 1) why not the main Ptr/Pointer pages: KeyPgPtr/KeyPgPointer?
    2) why is this split into two pages (it's the very same thing, after all)?
IIRC there is one page only for: Print|? (as example), KeyPgPrint.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Extending Wstring and Zstring with UDTs

Post by fxm »

1)
  • As long as it is not dereferenced, a pointer can take any value, even a value corresponding to an invalid memory address.
    This is why I wrote this caution only at the level of each dereferencing operator.

    For example, if one defines an array as:
    Dim As Integer array(10 To 20)
    the first information in the array descriptor is the address of the virtual (in this case) element corresponding to the index 0.
    - Do:
    Dim As Integer Ptr pa = descriptor_ptr[0]
    is licit
    - At the opposite, do:
    Dim As Integer i = *pa
    is illicit
    but:
    Dim As Integer i = pa[10]
    is licit
2)
  • Obviously we could merge the 2 pages ('Pointer' and 'Ptr') into one ('Pointer | Ptr').
    (keeping 'KeyPgPtr' as the main link, as there will be fewer 'KeyPgPointer' links to rename)

    @coderJeff,
    That does not bother me to do it, if you think it's useful?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Extending Wstring and Zstring with UDTs

Post by MrSwiss »

@fxm,

since you are currently the maintainer of doc's, therefore I think that
the decision is yours. (it's not linked to a development issue)
I'd do it, for the reason of simpler maintenance (in the future, at least).
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Extending Wstring and Zstring with UDTs

Post by fxm »

fxm wrote:Obviously we could merge the 2 pages ('Pointer' and 'Ptr') into one ('Pointer | Ptr').
(keeping 'KeyPgPtr' as the main link, as there will be fewer 'KeyPgPointer' links to rename)
Done (1 page emptied and 24 pages updated).

@coderJeff,
Can you completely remove the page POINTER (KeyPgPointer), now emptied and orphaned?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Extending Wstring and Zstring with UDTs

Post by fxm »

coderJeff wrote:It's been helpful that fxm, very consistently, brings the perspective of a skilled and and knowledgeable user to the community. I think we have made a pretty good team over last couple years to solve some compiler issues. fxm providing the user point of view, and myself providing the developer point of view.
That's how I see it too, and I did it before with dkl for many years.

Post Scriptum:
Saturday, I go on vacation for 6 weeks.
I hope the WIFI connection will work well.
Lost Zergling
Posts: 534
Joined: Dec 02, 2011 22:51
Location: France

Re: Extending Wstring and Zstring with UDTs

Post by Lost Zergling »

Taking a picture, I am very sensitive to the fact that for FB can be assured a lighthouse, a rescue boat and a permanence at the sea. What matters most for me (as a user), it is not the misunderstandings or susceptibilities but the fact that "service" continues to be assured and assumed. It is unfortunate maybe not being able to meet each other in real life (FB seminar?). I know that if I had to choose (one day) someone to take over my code, I'd rather prefer coderJeff or st_w, developer preference. Beside that, when I am stuck by a point that I do not understand, fxm has always given me the most relevant answer.
Post Reply