Skip to content

Fixes: DLL import library - #327

Open
ElminsterAU wants to merge 1 commit into
remobjects:masterfrom
ElminsterAU:fixes/dll
Open

ElminsterAU wants to merge 1 commit into
remobjects:masterfrom
ElminsterAU:fixes/dll

Conversation

@ElminsterAU

Copy link
Copy Markdown

DLL import library: 13 changes, each described in the commit messages.

This is one of a series of pull requests carrying the fixes NexusDB made to Pascal Script, split by area so that each can be reviewed on its own. The fixes are listed one per line in each commit's message.

Applies to master on its own.

Tested. With the whole series applied, every unit of Source compiles, and a script run through TPSScript (strings, Int64, reals, calls into host functions, exceptions, a class from the Classes library, for / Break) gives the expected results, on Delphi 7, 2005, 2006, 2007, 2009, 2010, XE, XE2 - XE8 and 10 Seattle - 13 Florence (Win32, and Win64 from XE2), and on Free Pascal 3.2.2 (i386) and 3.3.1 (x86_64), with and without PS_USESSUPPORT; compilers before XE4 need the last pull request of the series. Master as it stands does not compile on XE4, XE5 Win64, 10 Seattle, 10.1 Berlin, 10.3 Rio Win64, Free Pascal 3.2.2 or 3.3.1, nor on anything before XE4.

Beyond that smoke test, the fixes were developed and are covered in NexusDB, whose suite runs about 6,400 checks on 37 Delphi compiler / platform combinations and on Free Pascal. NexusDB defines PS_USECLASSICINVOKE, so there every Delphi calls native routines through x86.inc / x64.inc; the InvokeCall.inc path (the default from Delphi 10 Seattle) is exercised here by the smoke test only.

These fixes come from NexusDB, which ships Pascal Script as its script engine.  Each was found and fixed
there; most were measured against what Delphi itself does with the same code, and most have a regression
test in NexusDB's own suite, which runs on Delphi 7 through 13 Florence (Win32 and Win64) and on Free Pascal
3.2.2 (i386) and 3.3.1 (x86_64).  NexusDB builds the engine with PS_USECLASSICINVOKE and PS_USESSUPPORT; the
fixes are given here in Pascal Script's own unit names and configuration.

uPSC_dll.pas:
- A routine's name was taken up to the last @ of the whole text, so an @ inside a quoted library
  path put part of the path into the routine's name and the library was not found; the name now ends
  at the @ before the opening quote
- A routine name holding @" -- external 'Odd@"Name@kernel32.dll' -- was split there and the
  declaration refused; the library is quoted only where the text's last quote closes a quote opened
  right after an @ and ends the text or is followed by a space (a library path holds no quote, nor
  does an option word)
- A routine name holding a quoted part and a space -- external 'Odd@"Na" me@kernel32.dll' -- was
  split at the quote and the declaration refused; the library is quoted only where, besides an
  earlier fix test, no @ follows its closing quote (options hold none)

uPSR_dll.pas:
- UnloadAll
- [Free Pascal] 3.2.2's System has no UTF8ToUnicodeString; UTF8Decode returns UnicodeString
- [Free Pascal] Its Windows unit binds the plain names to the A entry points (PAnsiChar); the W
  entry point takes the name as UTF-16 in either string configuration
- [Free Pascal] As the previous entry
- A DLL routine's declaration was read past its end where it held fewer than the convention,
  delay-load, search-path and result bytes after its two names -- ProcessDllImportEx2 read the
  second, LoadDll the third, and DllProc, whose guard passed two, the first after deleting three --
  an access violation or a byte past the text; such a declaration (bytes a host altered, or a host
  shortening the declaration) is now refused before anything reads it
- _DllDeclTail looked for the library and routine names from the declaration's first byte while
  LoadDll and UnloadDLL take them after a four-byte prefix ('dll:'), so a declaration whose #0s sat
  in its first four bytes passed the check and LoadDll read past its end; the names are now taken
  after the prefix, as every reader takes them
- UnloadAll freed every library and left each routine holding its address, so the routine's next
  call jumped into the freed library; and a routine whose load failed stayed refused after
  UnloadDll, which is the script's way to have a library loaded again. Both now forget what the
  routines of that library loaded, so the next call loads it
- A routine whose library or entry point could not be loaded when it was called left DllGetLastError
  answering the last successful call's code; it now answers the load's
- Before Delphi 2009 a library name with the <utf8> prefix went to LoadLibrary with the prefix on
  it, so the library was not found; the name is now converted to the ANSI code page without it
- DllProc discarded the call layer's answer, so a routine the call layer refuses before calling it
  -- a procedural result or var parameter -- was not called and the script went on as though it had
  been; it now stops with Could not call proc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant