The Wiert Corner – irregular stream of stuff

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

  • My badges

  • Twitter Updates

    • RT @EvaKestemont: Gezocht voor een vriendin met pech en een zware revalidatie: iemand die enkele maanden bij haar en haar lief en baby wil… 7 hours ago
    • RT @steve_asbell: My therapist said “Why did you get an autism diagnosis? You’re more than a label!” I told him “I have ALWAYS been labele… 7 hours ago
    • @Zangstem Ik duim dat je oud wordt. In goede gezondheid. 8 hours ago
    • RT @JasonErvD: Weet je van die docenten die de cijfers van de hele klas voorlezen of projecteren op het digibord? Moet echt stoppen. Is ec… 8 hours ago
    • RT @IanColdwater: I don't know why keynoting in front of 10,000 people feels less weird than this, but here we are 👩🏻‍💻 https://t.co/25ShsH… 11 hours ago
  • 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,821 other followers

Archive for the ‘Conferences’ Category

Delphi, compiler intrinsics and generic type matching

Posted by jpluimers on 2020/01/21

For my link archive in case I ever need to do Delphi generic type matching on intrinsic types. This will be tricky as you can have typed types like [WayBacktype TDate = type TDateTime since the early Delphi ages.

[WayBack] Hi, by using compiler intrinsics, is it possible to check if a generic type parameter is an unsigned integer? – Malcon X Portela – Google+

It will probably come down to fast intrinsic type mapping and slower typed type mapping.

–jeroen

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »

Delphi: A few notes on tracking down a use-after free related issue involving interfaces crashing inside System._IntfClear.

Posted by jpluimers on 2020/01/20

A few notes on tracking down a use-after free related issue involving interfaces.

The crash message is like this:

Project UseAfterFreeWithInterface.exe raised exception class $C0000005 with message 'access violation at 0x004106c0: read of address 0x80808088'.

Two things here:

An important note first

Basically any memory value in an exception starting with $8080 and sometimes even $80 should raise suspicion: it usually means a use-after-free case.

You see these errors with FastMM and not with the memory manager as [WayBack] delphi • View topic • Problem with FastMM and D7 explains:

Read the rest of this entry »

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | 8 Comments »

Python – list transformation; string formatting – Stack Overflow

Posted by jpluimers on 2020/01/08

Sometimes simple examples are the best: [WayBack] Python – list transformation – Stack Overflow.

Interactive example (note you can run and save at repl.it in either [WayBack] Repl.it – Python 3 or [WayBack] Repl.it – Python 2; you can run but not save it at [WayBack] Welcome to Python.org: interactive Python shell):

# Links the documentation are Python 2, though everything works in Python 3 as well.

x = [1,2,3,4,5,11]
print("x: ", repr(x))

y = ['01','02','03','04','05','11']
print("y: ", repr(y))

# List comprehension https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions
# ... using `str.format()` (Python >= 2.6): https://docs.python.org/2/library/stdtypes.html#str.format and https://docs.python.org/2/library/string.html#formatstrings
y = ["{0:0>2}".format(v) for v in x]
print("y: ", repr(y))

# ... using the traditional `%` formatting operator (Python < 2.6): https://docs.python.org/2/library/stdtypes.html#string-formatting y = ["%02d" % v for v in x] print("y: ", repr(y)) # ... using the format()` function (Python >= 2.6): https://docs.python.org/2/library/functions.html#format and https://docs.python.org/2/library/string.html#formatstrings
# this omits the "{0:...}" ceremony from the positional #0 parameter
y = [format(v, "0>2") for v in x]
print("y: ", repr(y))

# Note that for new style format strings, the positional argument (to specify argument #0) is optional (Python >= 2.7) https://docs.python.org/2/library/string.html#formatstrings
y = ["{:0>2}".format(v) for v in x]
print("y: ", repr(y))

# Using `lambda`
# ... Python < 3 return a list y = map(lambda v: "%02d" %v, x) print("y: ", repr(y)) # ... Python >= 3 return a map object to iterate over https://stackoverflow.com/questions/1303347/getting-a-map-to-return-a-list-in-python-3-x/1303354#1303354
y = list(map(lambda v: "%02d" %v, x))
print("y: ", repr(y))

Output:

Python 3 Python 2
Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
   
x:  [1, 2, 3, 4, 5, 11]
y:  ['01', '02', '03', '04', '05', '11']
y:  ['01', '02', '03', '04', '05', '11']
y:  ['01', '02', '03', '04', '05', '11']
y:  ['01', '02', '03', '04', '05', '11']
y:  ['01', '02', '03', '04', '05', '11']
y:  <map object at 0x7fe1218200b8>
y:  ['01', '02', '03', '04', '05', '11']
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.8.2] on linux
   
('x: ', '[1, 2, 3, 4, 5, 11]')
('y: ', "['01', '02', '03', '04', '05', '11']")
('y: ', "['01', '02', '03', '04', '05', '11']")
('y: ', "['01', '02', '03', '04', '05', '11']")
('y: ', "['01', '02', '03', '04', '05', '11']")
('y: ', "['01', '02', '03', '04', '05', '11']")
('y: ', "['01', '02', '03', '04', '05', '11']")
('y: ', "['01', '02', '03', '04', '05', '11']")

–jeroen

Read the rest of this entry »

Posted in Conference Topics, Conferences, Development, Event, Python, Scripting, Software Development | Leave a Comment »

TFreedObject in FastMM4/FastMM4.pas at master · pleriche/FastMM4 · GitHub

Posted by jpluimers on 2020/01/08

Reminder to Self:

  {The class used to catch attempts to execute a virtual method of a freed
   object}
  TFreedObject = class
  public
    procedure GetVirtualMethodIndex;
    procedure VirtualMethodError;
{$ifdef CatchUseOfFreedInterfaces}
    procedure InterfaceError;
{$endif}
  end;

If you encounter the class TFreedObject when doing a cast, then you’re working on a freed object and have FastMM4 enabled to detect that.

Source: [WayBackFastMM4/FastMM4.pas at master · pleriche/FastMM4 · GitHub; FastMM4 – A memory manager for Delphi and C++ Builder with powerful debugging facilities

Note that if you want to see the underlying FastMM data for any TObject allocation, use this watch (where Self is the current instance):

PFullDebugBlockHeader(PByte(Self) - SizeOf(TFullDebugBlockHeader))^

You can also put a ,r behind it to see the fields of this structure:

(Reserved1:nil; Reserved2:nil; AllocatedByRoutine:$41BF74; AllocationGroup:0; 
AllocationNumber:592682; 
AllocationStackTrace:(4224198, 4233131, 4235210, 11103806, 6552132, 131126, 6597961, 11106984, 4235210, 11107153, 11104090); 
AllocatedByThread:90428; FreedByThread:90428; 
FreeStackTrace:(4241541, 131126, 4235210, 11103806, 6552132, 131126, 6597961, 11106984, 4235210, 11107153, 11104090); 
UserSize:36; PreviouslyUsedByClass:132272; HeaderCheckSum:2673350594)

–jeroen

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »

Using a main check __main__ to call a main function in Python

Posted by jpluimers on 2020/01/01

[WayBack] __main__ — Top-level script environment — Python 3 documentation recommends code like this:

if __name__ == "__main__":
    # execute only if run as a script
    main()

This has many cool possibilities, including these that I like most as a beginning Python developer:

  • having your def main(): function in a separate source file
  • allowing to return prematurely from your main function (you cannot do this from the main block)
  • allowing a file to distinguish if it is being loaded as a module, or as a main program

Related:

–jeroen

Posted in Conference Topics, Conferences, Development, Event, Python, Scripting, Software Development | Leave a Comment »

 
%d bloggers like this: