Objective-C function collision; Or how to achieve "namespaces"?

I have a Mac OS X application that supports plugins that need to be loaded at the same time. Some of these plugins are built on top of the Cocoa frame, which can receive updates in one plugin but not another. Given the current method of dispatching Objective-C functions, any call from any plugin to a given Objective-C procedure will jump to the same procedure each time. This means that plugin A can end up inside plugin B with a trivial Objective-C call! Obviously, we want each plugin to interact with its own version of the framework it was built on. I have some reading on Objective-C and this specific need, but haven't found a definitive solution for it yet.

Update. My use of the word "framework" above is misleading: a framework is a statically linked library built into the plugin (s) that need it. However, the Objective-C way handles dispatch, however even these statically linked pieces of scattered code will mix up in the Objective-C dispatcher, with unintended consequences.

Update 2: I'm still a little fuzzy in the answer presented here as it doesn't seem to offer a solution, nor is it an unproven hypothesis.

0


source to share


3 answers


The best solution so far is derived from the idea suggested in this question



0


source


You cannot do this (at least not trivially), Objective-C currently has no concept of namespaces, and the runtime only presents one (global) dispatch table.

Note that this is not unique to Objective-C, even C based plugins can also call among themselves quite trivially, since everything is in the same address space. Admittedly, if you're concerned about random execution, it's less likely due to the two-level namespaces, but it won't protect you if any plugin explicitly tries to inject different code.



If you really want to isolate plugins, you can create separate helper processes where you run the code that loads the plugin and your application performs RPC between itself and the helper applications. This is what Safari does in 64-bit on Snow Leopard, for example. There are a number of advantages to this approach, but it is quite difficult to implement and you have to roll most of it yourself.

+1


source


I don't think I understand that you will comment "plugin A might be inside plugin B." I assume what you mean is that once you download some dependent environment once, then everyone will be using it instead of loading their own, and rightly so. And that's right whether you have something like namespaces or not.

This is the same problem you would run into if one plugin required one version of OpenSSL and another plugin required a different version of OpenSSL. You cannot load two libraries that provide the same symbols.

As I understand the problem? Do different plugins require different, incompatible versions of the same framework? My approach, if possible, would be to change the structure to a static library and statically link your plugins to their framework. If you don't share frameworks between plugins, then the framework is really not what you want. You just want to compile the code (static linking). The whole point of the frame is to share.

0


source







All Articles