Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-14 Thread Alexey Tor. via fpc-pascal

That is another reason for PChar based inner func. :)


the input might be


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-14 Thread Benito van der Zander via fpc-pascal

Hi,


I don’t see what the problem with a shortstring buffer is.. strtoint 
could not make use of an input string longer than 256 characters 
anyway, because the output integer could not have more than 19 digits 
anyway.. so an input string longer than this would be useless… just 
convert to a shortstring and to strtoint.




the input might be


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-13 Thread Bart via fpc-pascal
On Wed, Jan 12, 2022 at 11:33 PM Sven Barth via fpc-pascal
 wrote:

> You can see it in Florian's commit to the branch about range checking where 
> he added the DestSize parameter.

Yes, I discovered that.
Will study a bit how this is done, just for the fun of it.


-- 
Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread Benito van der Zander via fpc-pascal

Hi,



If it is correct: Can we skip using ShortString buffer and have e.g. 
'common' PChar base function for AnsiString/ShortString? 


I keep arguing for that as well

You can always create such a function yourself,  gain experience using 
it, and share the source with us.




I wrote that for you:

https://forum.lazarus.freepascal.org/index.php/topic,55472.msg414973.html#msg414973

https://github.com/benibela/bbutils/blob/master/bbutils.pas#L3446-L3601

Cheers,
Benito

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread Sven Barth via fpc-pascal
Bart via fpc-pascal  schrieb am Mi., 12.
Jan. 2022, 22:31:

> On Wed, Jan 12, 2022 at 3:13 PM Michael Van Canneyt via fpc-pascal
>  wrote:
>
> > From the definition you can see it is a compilerproc function, meaning
> that the
> > compiler writes direct calls to this.
> > To change the signature of the function means the compiler itself also
> must be changed.
>
> Could you naybe point me to where in the compiler this "magic" happens?
> (fpc_Val_UInt_Shortstr() signature needs to be changed IMO)
>

You can see it in Florian's commit to the branch about range checking where
he added the DestSize parameter.

Regards,
Sven

>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread Bart via fpc-pascal
On Wed, Jan 12, 2022 at 10:28 PM Bart  wrote:

> Could you naybe point me to where in the compiler this "magic" happens?
> (fpc_Val_UInt_Shortstr() signature needs to be changed IMO)

Never mind, I just notice a new branch val_range_check was created
that just does this.
I'll get on trying to fix hte range check errors then.

-- 
Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread Bart via fpc-pascal
On Wed, Jan 12, 2022 at 3:13 PM Michael Van Canneyt via fpc-pascal
 wrote:

> From the definition you can see it is a compilerproc function, meaning that 
> the
> compiler writes direct calls to this.
> To change the signature of the function means the compiler itself also must 
> be changed.

Could you naybe point me to where in the compiler this "magic" happens?
(fpc_Val_UInt_Shortstr() signature needs to be changed IMO)


-- 
Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread Sven Barth via fpc-pascal
DougC  schrieb am Mi., 12. Jan. 2022, 17:57:

> So, are you saying the one cannot declare an IntToStr function with the
> string represented by a PChar argument? Seems pretty straightforward to me.
>
> Isn't that what is being requested?
>

No, it's not. He's requesting to change the functions that internally
provide the base for the Val intrinsic (which is in turn used by StrToInt
(not IntToStr)).

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread Michael Van Canneyt via fpc-pascal



On Wed, 12 Jan 2022, James Richters via fpc-pascal wrote:


I don’t see what the problem with a shortstring buffer is..  strtoint
could not make use of an input string longer than 256 characters anyway,
because the output integer could not have more than 19 digits anyway..  so
an input string longer than this would be useless… just convert to a
shortstring and to strtoint.


The "problem" is that IntToStr() gets an Ansistring argument, but uses Val()
to do the actual work, and Val() converts from whatever type you use to
ShortString to do the work.

Hence there is always a conversion AnsiString -> ShortString or (worse) 
WideString->ShortString
when you call IntToStr() and this is 'slow'.

What Alexey would like to see is that the basic function uses PChar, so that
no conversion is necessary. In that case, only the way in which the Pchar
(pointing to the string content) is passed to this new function will differ 
between AnsiString or ShortString.


In the case when you use widestring, a conversion is always performed.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread James Richters via fpc-pascal
I don’t see what the problem with a shortstring buffer is..  strtoint could not 
make use of an input string longer than 256 characters anyway, because the 
output integer could not have more than 19 digits anyway.. so an input string 
longer than this would be useless… just convert to a shortstring and to 
strtoint.
 
 
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread James Richters via fpc-pascal
A new function that works with other types of strings would simply need to be 
called something else, and not use the val function at all then it would 
interfere with nothing.
 
James
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread DougC via fpc-pascal
So, are you saying the one cannot declare an IntToStr function with the string 
represented by a PChar argument? Seems pretty straightforward to me.



Isn't that what is being requested?



Doug C.







 On Wed, 12 Jan 2022 11:10:57 -0500 Sven Barth via fpc-pascal 
 wrote 



DougC via fpc-pascal  schrieb am Mi., 
12. Jan. 2022, 15:20:

Alexey-



You can always create such a function yourself,  gain experience using it, and 
share the source with us. That way others can gain experience with it and maybe 
someday also ask for it to be added to the standard library.








While that is in general the case, here this is not that easy, cause as Michael 
wrote, Val is an intrinsic which is fact backed by multiple function and the 
compiler itself needs to call them correctly. So in this case to play around 
with it means adjusting *both* the RTL and the compiler. 



Regards, 

Sven 






___
fpc-pascal maillist  - mailto:fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread Sven Barth via fpc-pascal
DougC via fpc-pascal  schrieb am Mi., 12.
Jan. 2022, 15:20:

> Alexey-
>
> You can always create such a function yourself,  gain experience using it,
> and share the source with us. That way others can gain experience with it
> and maybe someday also ask for it to be added to the standard library.
>

While that is in general the case, here this is not that easy, cause as
Michael wrote, Val is an intrinsic which is fact backed by multiple
function and the compiler itself needs to call them correctly. So in this
case to play around with it means adjusting *both* the RTL and the
compiler.

Regards,
Sven

>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread DougC via fpc-pascal
Alexey-



You can always create such a function yourself,  gain experience using it, and 
share the source with us. That way others can gain experience with it and maybe 
someday also ask for it to be added to the standard library.



Doug C.







 On Tue, 11 Jan 2022 10:46:24 -0500 Alexey Tor. via fpc-pascal 
 wrote 



Hello. As I see in the commit 
https://gitlab.com/freepascal.org/fpc/source/-/commit/beecbf1581a986f544fde77aa428e05c21a35f6f

StrToInt always uses ShortString buffer:

Function fpc_Val_SInt_ShortStr(DestSize: SizeInt; Const S:
ShortString; out Code: ValSInt): ValSInt;

If it is correct: Can we skip using ShortString buffer and have e.g.
'common' PChar base function for AnsiString/ShortString?-- 
Alexey


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] StrToInt is using ShortString buffer?

2022-01-12 Thread Michael Van Canneyt via fpc-pascal



On Tue, 11 Jan 2022, Alexey Tor. via fpc-pascal wrote:

Hello. As I see in the commit 
https://gitlab.com/freepascal.org/fpc/source/-/commit/beecbf1581a986f544fde77aa428e05c21a35f6f


StrToInt always uses ShortString buffer:

*Function fpc_Val_SInt_ShortStr(DestSize: SizeInt; Const S: ShortString; out 
Code: ValSInt): ValSInt;*


If it is correct: Can we skip using ShortString buffer and have e.g. 'common' 
PChar base function for AnsiString/ShortString?


It's not that easy.

From the definition you can see it is a compilerproc function, meaning that the 
compiler writes direct calls to this. 
To change the signature of the function means the compiler itself also must be changed.


Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal