Example Library Code

1 post / 0 new
msteed's picture
Last seen: 1 week 5 days ago
Joined: 2022-01-18 08:34
Example Library Code

I've been working on a datatype lately. Since datatypes are built on top of Exec libraries, I've been spending some time looking at example library code, including skeleton code created by tools like IDLTool and LDCK. I've found an unsettling number of inconsistencies in the ways these different code examples work.

One example: OS3 example library code, as well as code that's designed to compile under both OS3 and OS4, calls DeleteLibrary() (or the OS3 equivalent) if the library initialization function fails. This frees the memory used by the library base and the OS4 interfaces, which is allocated by Exec as it installs the library. But OS4 example code, including that generated by IDLTool and LDCK, doesn't call DeleteLibrary(). This would seem to lead to a memory leak if library initialization fails.

Another example: The library expunge code for both OS3 and OS4 example libraries sets the delayed expunge flag if the expunge fails because someone still has the library open. The OS3 example libraries check this flag in the library close code, and if the open count has gone to zero the delayed expunge is performed. But the OS4 example code, including that generated by IDLTool and LDCK, ignores the flag, and so never performs delayed expunges.

Related to the above: Some example code clears the delayed expunge flag when the library is opened, such that opening the library cancels a delayed expunge request. But most example code does not do that. Which is correct? (Of course, it doesn't matter if you don't perform delayed expunges anyway.)

These aren't critical failures-- nothing crashes, and the memory impacts are fairly small. Still, it's disconcerting to see code generated by developer tools that has apparent flaws, even if they are minor ones. It leaves me uncertain what to use for my library code-- do I fix the flaws, or just use the standard but seemingly buggy skeleton code? What have those of you that work with this library code done?