Exported Procedure Prototype Mangle Limited to 2 Source Lines by Templates

A topic the Compiler hangs in Debug mode drifted into a discussion Export Mangle problems so I am creating a separate topic.

If a Procedure Prototype is declared using 3 or more source lines then the Mangled name the Templates put in the EXP file is limited to the first 2 lines. The Compiler still mangles all 3+ lines, so it does not match and the Linker throws an Unresolved External error.

Another important note i would like to add is to not put a class prototype on more than 2 lines, because the ABC class parser #SERVICE('ClaTPLS.DLL','GenReadABCFiles') will not read more then 2 lines per method.

For example: this class method in a exporting dll, will generate as a unresolved external: EXECUTESQL@F11SQLCLASSsbRuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPu @?

ExecuteSQL PROCEDURE(STRING SQLQuery,  *ANY Out01 , <*ANY Out02>, <*ANY Out03>, <*ANY Out04>, <*ANY Out05>, <*ANY Out06>, <*ANY Out07>, <*ANY Out08>, <*ANY Out09>, <*ANY Out10>, |
                     <*ANY Out11>, <*ANY Out12>, <*ANY Out13>, <*ANY Out14>, <*ANY Out15>, <*ANY Out16>, <*ANY Out17>, <*ANY Out18>, <*ANY Out19>, <*ANY Out20>, | 
                     <*ANY Out21>, <*ANY Out22>, <*ANY Out23>, <*ANY Out24>, <*ANY Out25>, <*ANY Out26>, <*ANY Out27>, <*ANY Out28>, <*ANY Out29>, <*ANY Out30>, |
                     <*ANY Out31>, <*ANY Out32>, <*ANY Out33>, <*ANY Out34>, <*ANY Out35>, <*ANY Out36>, <*ANY Out37>, <*ANY Out38>, <*ANY Out39>, <*ANY Out40>), LONG, PROC
1 Like

The fix just has been sent to RZ.

2 Likes

That’s a bug I’ve experienced when seeing how many parameters I can pass…

The implementation limit is 100 parameters.

1 Like

Yikes, any more than about 4 parms I used TYPEd groups to hold that many parms.

Some places, such as with Mike’s printf() rendition, it makes sense to have a lot of params. GitHub - mikeduglas/printf: Convenient string formatting..

2 Likes

It’s nice to have options.

Can you use that method with win32 api’s?

I’ve seen how the debugger shows the parameters at procedure entry but I haven’t seen how the typed groups are handled in the debugger yet…

Because that EXP line only has 21 of 41 parameters (as you know)

While the compiler/linker would encode all 41 so not match:

EXECUTESQL@F11SQLCLASSsbRuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPuPu @?

I thought I would mention the Exp2Map tool on GitHub by @Owen that will decode the Mangled EXP line. It shows the Clarion Types and builds a Prototype for the MAP.

I added a # Column that shows count of 21 for the problem EXP line:


BTW for ANY / *ANY you can use ? / *? which would make your prototype 80 bytes shorter so about 1 line.

ExecuteSQL PROCEDURE(STRING SQLQuery, *? Out01 , <*? Out02>, <*? Out03>, <*? Out04>, <*? Out05>, <*? Out06>, <*? Out07>, ... <*? Out40>), LONG, PROC

Also change the Label “Out01” to “P01” and shorten by 160 bytes.
ExecuteSQL PROCEDURE(STRING SQLQuery, *? P01 , <*? P02>, <*? P03>, <*? P04>, <*? P05>, <*? P06>, <*? P07>, ... <*? P40>), LONG, PROC

Rules for mangling are not a secret. If I recall correctly, some variant of the mangling function known as LINKNAME in templates was in public access at the end of the last millennium :slight_smile:

The problem is in the parser of INC/INT files: it uses incorrect expression to concatenate the line with the break character | at the end and the next one.As result, the parsing of a long prototype can be finished prematurely. So, not only incorrect mangled name can be written to the EXP file but also calls to such functions can be generated with incorrect number of parameters.

Owen’s tool just makes it easy to take that Mangle and make it understandable. Maybe you have a DLL that is not working with the provided INC file. You can decode the DLL Exports easily. Or there are some RTL exports that are undocumented like _WslHelp$GetHelpFile@FiPc that gets the current HELP() file.

LINKNAME is a “Built-In Template Procedure”. I checked C5 from 1997 and the TPW files do not have Source for it, they just call it building the EXP.

The Pro2Exp example did document most all the Mangle except for a very few newer things like ANY.

Probably the most solid way to get the Mangle is to setup the Import and compile. That will throw an “Unresolved External” error with a compiler generated Mangle. I have a tool to Clean the Unresolved Errors and make the EXP lines.

LINKNAME is not a function :slight_smile: It is the bound name for the real function used by the Generator’s evaluator.

C5B-C11: Examples\Src\PRO2EXP

There were some changes since times when this program was published but it is a good start.

1 Like