Sign in Join

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

Mailing lists / fpc-pascal / 2015-09

howto find alternatives for deprecated fucntions?

11 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Klaus Hartnegg

Hi,

if the docs and the compiler say that a function is deprecated, how can I find out which other function should be used instead?

Example: www.freepascal.org/docs-html/rtl/sockets/accept.html says that accept is deprecated. Whould I switch to fpaccept eventhough that can do a lot less? I hope that Sock2Text works there as well.

In an ideal world every occurance of the word deprecated in the docs would be accompanied by the info which is the alternative.

Btw. the docs for fpaccept contains an example for accept, not for fpaccept.

thanks,
Klaus

Graeme Geldenhuys
to Klaus Hartnegg
Klaus Hartnegg wrote
if the docs and the compiler say that a function is deprecated, how can I find out which other function should be used instead?

I suggest you report those as a bug in FPC, and a bug in the Documentation.

The Object Pascal language supports the syntax that allows a short message to guide the developer to the replacement or alternative:

<deprecated ['some message'];>

That message will also appear in the compiler output.

For example:

    procedure   UpdateWindowPosition; deprecated 'use UpdatePosition';

The fpdoc documentation tool also supports the ability to correctly document deprecated methods, classes etc.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/
Marco van de Voort
to Klaus Hartnegg: if the docs and the compiler say that a function is deprecated, how can I find out which…

In our previous episode, Klaus Hartnegg said:

if the docs and the compiler say that a function is deprecated, how can I find out which other function should be used instead?

Reading release manifests?

http://wiki.freepascal.org/User_Changes_2.4.0#Almost_all_old_1.0.x_socket_unit_functions_have_been_removed

Specially the major versions often have loads of this kind of useful info. We can't keep all legacy considerations in the docs forever.

Example: www.freepascal.org/docs-html/rtl/sockets/accept.html says that accept is deprecated. Whould I switch to fpaccept eventhough that can do a lot less? I hope that Sock2Text works there as well.

The socket functions were the OS functions for networking but overloaded for the sock2text related calls. That overlated "text" functionality is the "different functionality" the above message speaks of.

Note that these functions were essentially deprecated in spring 2004, before deprecated existed, let alone the text option that Graeme mention.

If I had had my way, the whole shebang would have been removed in 2.0.0, but that was deemed to drastic.

In an ideal world every occurance of the word deprecated in the docs would be accompanied by the info which is the alternative.

In an ideal world people would have updated code that used these functions in 2005 when 2.0 came out :-)

Documentation is not meant to preserve a history of every change every made, specially when the flaws are older than the docs (and compiler) tooling.

Mark Morgan Lloyd
to Marco van de Voort
Marco van de Voort wrote 8 lines
> In an ideal world every occurance of the word deprecated in the docs > would be accompanied by the info which is the alternative. In an ideal world people would have updated code that used these functions in 2005 when 2.0 came out :-) Documentation is not meant to preserve a history of every change every made, specially when the flaws are older than the docs (and compiler) tooling.

I've got various old stuff that I try to keep running, but in practical terms there are very good reasons for not trying to support compiler versions older than 2.2.4. So anybody who insists on using functions which were already deprecated by that point had better have a compelling reason, and should have made that reason clear to the core developers in case they were missing some detail.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Marco van de Voort
to Jonas Maebe

In our previous episode, Jonas Maebe said:

Show quoted text 7 lines
[sock2text etc] > If I had had my way, the whole shebang would have been removed in 2.0.0, but > that was deemed to drastic. It's more that some people (including me) didn't agree that those routines should be deprecated and 's what I meant. Removed from sockets and put in an own unit, possibly

with new names. That would have reduced confusion of an overloaded function that is now not overloaded anymore.

The problem is that at the time more new code was written using deprecated functions than was already out there, which was the cycle I wanted to break.

Jonas Maebe
to Klaus Hartnegg

Klaus Hartnegg wrote on Mon, 28 Sep 2015:

What can I use instead of Sock2Text? That's also deprecated.

That is part of the "X wanted to remove that functionality altogether and deprecating it was a first step, and Y wanted to keep it". Eventually, it will probably be moved to a separate unit. There is no alternative for that function.

Jonas

Klaus Hartnegg
to Jonas Maebe

The sample for 'access' from the manual drives me crazy.

http://www.freepascal.org/docs-html/rtl/sockets/fpaccept.html

S:=fpSocket (AF_INET,SOCK_STREAM,0);
if SocketError0 then
(* ERROR! SHOULD BE "IF S = -1" *)
(* (SocketError can be 25 while S is  -1, and this signals success) *)
if fpBind(S,@SAddr,sizeof(saddr))=-1 then
(* ERROR! Incompatible types: got "^sockaddr_in" expected "psockaddr" *)
if Accept(S,FromName,Sin,Sout) then
(* WARNING: Accept is deprecated *)
(* ERROR: fromname contains nonsense characters *)
  PError ('Server : Accept : '+fromname);
(* ERROR: should bei "writeln" instead of "PError" *)
When I fix the errors and try work around the Warning with this:
   slen := sizeof(saddr);
   fpAccept (S, @SAddr, @slen);
   FromName := NetAddrToStr(SAddr.sin_addr);
   Sock2Text(S,Sin,Sout);
   reset (Sin);
   rwrite (Sout);
then reset (Sin) crashes or hangs, and it also triggers a deprecated
warning.

Here is my version of it. It works only in Linux, but at least it works:

{$mode fpc}
{$I+,O+,R+,T+} { check io, overflow, range, stack }
uses
   unixtype, Sockets, baseunix;
Var
   FromName : string;
   Buffer   : shortstring;
   S        : Longint;
   Sin,Sout : Text;
   SAddr    : sockaddr;
   slen     : SockLen_t;
   filedescr: cint;
   numread  : TsSize;
procedure perror (const S:string);
begin
   writeln (S,SocketError);
   halt(100);
end;
begin
   S:=fpSocket (AF_INET,SOCK_STREAM,0);
   if S = -1 then
    Perror ('Server : Socket : ');
   SAddr.sin_family:=AF_INET;
   SAddr.sin_port:=htons(5000);
   SAddr.sin_addr.s_addr:=0;
   if fpBind(S,@SAddr,sizeof(saddr))=-1 then
    PError ('Server : Bind : ');
   if fpListen (S,1)=-1 then
    PError ('Server : Listen : ');
   Writeln('Waiting for Connect from Client');
   slen := sizeof(saddr);
   filedescr := fpaccept(S, @SAddr, @slen);
   if filedescr = -1 then
    PError ('Server : Accept : ');
   { ### should verify that SAddr.sin_family is AF_INET }
   FromName := NetAddrToStr(SAddr.sin_addr);
   writeln ('Connect from ',FromName);
   numread := fpread (filedescr, buffer[1], sizeof(buffer)-1);
   if numread  -1 then begin
      buffer[0] := chr(numread);
      write (buffer);
   end;
end.
Klaus Hartnegg
to Klaus Hartnegg

Sorry, I meant accept, not access.

Klaus Hartnegg wrote 11 lines
http://www.freepascal.org/docs-html/rtl/sockets/fpaccept.html if Accept(S,FromName,Sin,Sout) then (* WARNING: Accept is deprecated *) (* ERROR: fromname contains nonsense characters *) Sock2Text(S,Sin,Sout); reset (Sin); rwrite (Sout); then reset (Sin) crashes or hangs, and it also triggers a deprecated warning.

My conclusion from these two is that Accept and Sock2Text are more than deprecated, they are broken (in version 2.6.4 for Linux).

filedescr := fpaccept(S, @SAddr, @slen);

How can this filedescr be used other than with fpread? Can it be implanted into a file of type "text"?
I would prefer to just readln from it.

Klaus