The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Delphi: ^TNodeData incompatible with PNodeData – {$T+} versus {$T-}

Posted by jpluimers on 2017/11/14

In my Turbo Pascal days, I was fan of the {$T+} directive (now a.k.a TypedAddress on) as it would make the @ operator return typed pointers and the compiler would be more strict in forcing checks on pointer types to be compatible.

Not so much in Delphi any more, see the below comment on in a G+ thread on Delphi pointer type compatibility [WayBack] by David Millington from Embarcadero.

Basically we’re stuck with {$T-} which is a double edged sword:

  • on the one hand it forces you to ensure your typed pointers are always the same actual type (so you need to define a type like PNodeData once and use it everywhere)
  • on the other hand it still allows the generic Pointer type to be compatible with typed pointers which means people use that and will not have the benefit of typed pointer checking

David Millington:

So the question is why is PNodeData different to ^TNodeData? These two pages have the answer:

  • “Two distinct types are compatible if they satisfy at least one of the following conditions:
    … (snip)
  • One type is Pointer (an untyped pointer) and the other is any pointer type.
  • Both types are (typed) pointers to the same type and the {$T+} compiler directive is in effect.”

[WayBackhttp://docwiki.embarcadero.com/RADStudio/Berlin/en/Type_Compatibility_and_Identity_(Delphi)#Type_Compatibility

That line about $T+ is key; it’s the “Typed @ operator” compiler option which is off by default. “In the {$T-} state, distinct pointer types other than Pointer are incompatible (even if they are pointers to the same type)”. So with that off, PNodeData and ^TNodeData are different.

[WayBackhttp://docwiki.embarcadero.com/RADStudio/en/Type-checked_pointers_(Delphi)

The best solution is to define PNodeData, as you’ve done, and use it everywhere.

What David fails to mention there, and I added as a commen later is this:

The problem $T is that it’s a two-edged sword as it makes code that looks valid fail to compile because the compiler in the $T+ state (a.k.a. $TypedAddress on state) never got updated to:

  • handle @ to an array creates a pointer to the element of that array
  • handle @ to resourcestrings to become PResStringRec (and likely more examples)

Which means the below programs fail to compile.

The alternative (adding way more {$T+} compatible overloads to the RTL/VCL/FMX) was never done either, so now we’re stuck with {$T-}

Array of char example:

program TypedAddressDirectiveWithCharArrays;

{$APPTYPE CONSOLE}

{$TypedAddress on}

uses
  Winapi.Windows;

var
  TimeZone: string;
  TZ: TTimeZoneInformation;

begin
  TimeZone := 'Coordinated Universal Time';
  StringToWideChar(TimeZone, @(TZ.StandardName), SizeOf(TZ.StandardName) div SizeOf(WideChar));
end.

(*

[dcc32 Error] TypedAddressDirectiveWithCharArrays.dpr(16): E2010 Incompatible types: 'PWideChar' and 'Pointer'

In the System unit:

implicit types:

  PWideChar = WideChar;
  PChar = PWideChar

explicit:

function StringToWideChar(const Source: UnicodeString; Dest: PWideChar; DestSize: Integer): PWideChar;



In the Winapi.Windows unit:

type
  WCHAR = WideChar;

  PTimeZoneInformation = ^TTimeZoneInformation;
  _TIME_ZONE_INFORMATION = record
    Bias: Longint;
    StandardName: array[0..31] of WCHAR;
    StandardDate: TSystemTime;
    StandardBias: Longint;
    DaylightName: array[0..31] of WCHAR;
    DaylightDate: TSystemTime;
    DaylightBias: Longint;
  end;
  TTimeZoneInformation = _TIME_ZONE_INFORMATION;
  TIME_ZONE_INFORMATION = _TIME_ZONE_INFORMATION;

*)

ResourceString example:

program TypedAddressDirectiveWithResourceStrings;

{$APPTYPE CONSOLE}

{$TypedAddress on}

uses
  System.SysConst,
  System.SysUtils;

procedure RangeError;
begin
  raise ERangeError.CreateRes(@SRangeError);
end;

begin
end.

(*
[dcc32 Error] TypedAddressDirectiveWithResourceStrings.dpr(13): E2250 There is no overloaded version of 'CreateRes' that can be called with these arguments


System unit:

type
  PResStringRec = ^TResStringRec;
  {$IF defined(EXTERNALLINKER)}
  TResStringRec = record
    Key: MarshaledAString;
  end;
  {$ELSE}
  TResStringRec = packed record
    // 32bit = 8 bytes
    // 64bit = 16 bytes
    Module: ^HMODULE;
    Identifier: NativeUint;
  end;
  {$ENDIF}


System.SysConst unit:

resourcestring
  SRangeError = 'Range check error';


SysUtils unit:

constructor Exception.CreateRes(ResStringRec: PResStringRec);
begin
  FMessage := LoadResString(ResStringRec);
end;


*)

Source: [WayBackOn Friday I had a brain fade moment (which I don’t seems to have recovered…

–jeroen

Posted in Delphi, Development, Software Development | 2 Comments »

A 4-bit Calculator made in cardboard and marble

Posted by jpluimers on 2017/11/14

Cool device: [WayBackA 4-bit Calculator made in cardboard and marble

I really love this. Not just that it exists, but how it was made and how it’s explained.

Definitely worth reading.

via: [WayBack] Funny modern abacus https://lapinozz.github.io/learning/2016/11/19/calculator-with-caordboard-and-marbles.html – David Berneda – Google+

–jeroen

Posted in Algorithms, Development, Hardware Development, Software Development | Leave a Comment »

Did you miss the ‘View Certificate’ button in Chrome? : sysadmin

Posted by jpluimers on 2017/11/13

[WayBack] Did you miss the ‘View Certificate’ button in Chrome?:

Good news, it’s back for those who want it:

  1. chrome://flags/#show-cert-linkEnable
  2. , restart, Bob’s your uncle.

Via: [WayBackKristian Köhntopp – Google+ chrome://flags/#show-cert-link

It seems I need to update from Version 59.0.3071.115 (Official Build) (64-bit).

–jeroen

Posted in Chrome, Google, Power User | Leave a Comment »

For everyone who still loves and uses old computers.

Posted by jpluimers on 2017/11/13

For everyone who still loves and uses old computers.

Quite a few nice products for your vintage Apple II, //e and //c machines.

Posted in //e, 6502, Apple, Apple I, Apple ][, History, Power User | Leave a Comment »

Microsoft live/passport account Security settings URL

Posted by jpluimers on 2017/11/13

For my link archive:

Microsoft live/passport account Security settings are at https://account.live.com/proofs/Manage

–jeroen

Posted in Cloud, Infrastructure, Microsoft Live, Power User | Leave a Comment »

Vulnerability Note VU#446847 – Savitech USB audio drivers install a new root CA certificate

Posted by jpluimers on 2017/11/10

Savitech has released a new driver package to address the issue. Savitech drivers version 2.8.0.3 or later do not install the root CA certificate.

Users still must remove any previously installed certificate manually.

  1. SaviAudio root certificate
    • ‎Validity: Thursday, ‎May ‎31, ‎2012 – ‎Tuesday, ‎December ‎30, ‎2036
    • Serial number: 579885da6f791eb24de819bb2c0eeff0
    • Thumbprint: cb34ebad73791c1399cb62bda51c91072ac5b050
  2. SaviAudio root certificate
    • Validity: ‎Thursday, ‎December ‎31, ‎2015 – ‎Tuesday, ‎December ‎30, ‎2036
    • Serial number: ‎972ed9bce72451bb4bd78bfc0d8b343c
    • Thumbprint: 23e50cd42214d6252d65052c2a1a591173daace5

Source: [WayBackVulnerability Note VU#446847 – Savitech USB audio drivers install a new root CA certificate

Background: [WayBack] Inaudible Subversion – Did your Hi-Fi just subv… | RSA Link: While threat hunting, RSA FirstWatch came across a curious exposure in Windows PCs, involving driver packages provided by a certain manufacture…

Via:

–jeroen

Posted in Power User, Security, Windows | Leave a Comment »

Playing Humax 5400C content on a Mac under OS X

Posted by jpluimers on 2017/11/10

I’ve had success transferring files for off-line usage on OS X using FileZilla connecting over FTP to my Humax.

Playing with MPlayerX was a bit troublesome as sliding through the resulting media file over commercials is hard.

VLC player has come a long way and plays the files a lot better (the audio gets less out if sync with the video/subtitle).

In addition: VLC on Mac OS X supports DLNA – basically a superset of UPnP – well (at least version 2.2.4 does): start with Universal Plug'n'Play to view any devices, then click on the little triangles in the list to open any new level.

A few tips on streaming:

  1. Do not play other content on the Humax itself: the device and operating system are simply not well enough designed to do deliver multiple streams without jitter at the same time.
    1. Try to avoid recording on the Humax while playing: the Humax will prioritise recording over playback.
  2. Ensure the Humax is on wired internet: the Humax 150N wireless adapter has bad antennas and can’t keep up even in good WiFi conditions (even with a great 802.11n access point next to it: it never reaches the 150 megabit IEEE_802.11n-2009 data rates).
  3. Try to have your Mac on wired internet as well.
  4. Ensure any firewalls allow DLNA / UPnP traffic

–jeroen

via:

Posted in DLNA / UPnP, Media Streaming, Power User | Leave a Comment »

Some links on isolating parts of networks with Mikrotik

Posted by jpluimers on 2017/11/10

On my research list so I can do proper LoT.

–jeroen

Read the rest of this entry »

Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | Leave a Comment »

TLS tests for your mail server

Posted by jpluimers on 2017/11/09

Need to do some more research on this to ensure I didn’t goof up:

–jeroen

Posted in *nix, *nix-tools, Communications Development, Development, Internet protocol suite, postfix, Power User, Security, sendmail, SMTP | Leave a Comment »

MX Backup – Postfix Email Server | samhobbs.co.uk

Posted by jpluimers on 2017/11/09

Interesting as it has steps for both OpenSuSE and Debian each well suited for running on a Raspberry Pi.

[WayBackMX Backup – Postfix Email Server | samhobbs.co.uk

It seems postfix is a lot easier to configure than sendmail so I already like it.

First I need to read a bit more in Postfix greylisting.

I’ll need to catch up on Sam’s other parts with the postfix tag as well:

–jeroen

Posted in *nix, *nix-tools, Debian, Development, Hardware Development, Linux, openSuSE, Power User, Raspberry Pi, Raspbian, sendmail, SuSE Linux, Tumbleweed | Leave a Comment »