swiftlang / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.3k stars 1.14k forks source link

[SR-10430] Need a way to know which image on disk a class is from #3453

Open millenomi opened 5 years ago

millenomi commented 5 years ago
Previous ID SR-10430
Radar None
Original Reporter @millenomi
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Foundation | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 8f9632f47485f4d3f6d48cdb3e059964

blocks:

Issue Description:

To correct some of Bundle's swift-corelibs-foundation shortcomings, it would be useful to have a way to know, given an **AnyClass, which image on disk it is from.

belkadan commented 5 years ago

dladdr will do this, although IIRC it's not very efficient about it.

millenomi commented 5 years ago

This has two parts: getting an appropriate symbol for the class that is known to originate in the image, and then using it. The first bit requires some stdlib support.

belkadan commented 5 years ago

Ah, gotcha. The appropriate symbol is the "nominal type descriptor", but the stdlib doesn't provide an easy way to get at that.