Example Library Code

3 posts / 0 new
Last post
msteed
msteed's picture
Offline
Last seen: 1 month 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?

jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 4 days ago
Joined: 2013-05-30 00:53
Re: Example Library Code

Hi, maybe you already visited this amigaos wiki:

https://wiki.amigaos.net/wiki/How_to_create_an_AmigaOS_4_library

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

msteed
msteed's picture
Offline
Last seen: 1 month 5 days ago
Joined: 2022-01-18 08:34
Re: Example Library Code

Yes, I've read that entry at the wiki. It's quite detailed and helpful, but it assumes you're using IDLTool to generate the library skeleton code. Of course, it also assumes that the skeleton code that is generated is correct. My issue is that the skeleton code doesn't seem to be entirely correct, or at least is inconsistent with other example library code.

Log in or register to post comments