]> granicus.if.org Git - php/commitdiff
- MFZE1 - MacOSX fixes by Marko Karppinen
authorDerick Rethans <derick@php.net>
Thu, 18 Jul 2002 11:16:34 +0000 (11:16 +0000)
committerDerick Rethans <derick@php.net>
Thu, 18 Jul 2002 11:16:34 +0000 (11:16 +0000)
Zend/zend.h
Zend/zend_extensions.c

index d0c2667b6dba0bb0c066f0113a17263c64e7f332..d948eeba4fd51a362589975e39fc403dfa3b5d32 100644 (file)
 # include <dlfcn.h>
 #endif
 
+#if HAVE_MACH_O_DYLD_H
+#include <mach-o/dyld.h>
+
+/* MH_BUNDLE loading functions for Mac OS X / Darwin */
+void *zend_mh_bundle_load (char* bundle_path);
+int zend_mh_bundle_unload (void *bundle_handle);
+void *zend_mh_bundle_symbol(void *bundle_handle, const char *symbol_name);
+const char *zend_mh_bundle_error(void);
+
+#endif /* HAVE_MACH_O_DYLD_H */
+
 #if defined(HAVE_LIBDL)
 
 # ifndef RTLD_LAZY
index 45769d654a6186c0a22ea139a924e1a19d0e7364..6e50ae1398231909b406b0bd8c01a76b977a699a 100644 (file)
@@ -216,3 +216,64 @@ ZEND_API zend_extension *zend_get_extension(char *extension_name)
        }
        return NULL;
 }
+
+/*
+ * Support for dynamic loading of MH_BUNDLEs on Darwin / Mac OS X
+ *
+ */
+#if HAVE_MACH_O_DYLD_H
+
+void *zend_mh_bundle_load(char* bundle_path) 
+{
+       NSObjectFileImage bundle_image;
+       NSModule bundle_handle;
+       NSSymbol bundle_init_nssymbol;
+       void (*bundle_init)(void);
+
+       if (NSCreateObjectFileImageFromFile(bundle_path, &bundle_image) != NSObjectFileImageSuccess) {
+               return NULL;
+       }
+       
+       bundle_handle = NSLinkModule(bundle_image, bundle_path, NSLINKMODULE_OPTION_PRIVATE);
+       NSDestroyObjectFileImage(bundle_image);
+       
+       /* call the init function of the bundle */
+       bundle_init_nssymbol = NSLookupSymbolInModule(bundle_handle, "__init");
+       if (bundle_init_nssymbol != NULL) {
+               bundle_init = NSAddressOfSymbol(bundle_init_nssymbol);
+               bundle_init();
+       }
+       
+       return bundle_handle;
+}
+
+int zend_mh_bundle_unload(void *bundle_handle)
+{
+       NSSymbol bundle_fini_nssymbol;
+       void (*bundle_fini)(void);
+       
+       /* call the fini function of the bundle */
+       bundle_fini_nssymbol = NSLookupSymbolInModule(bundle_handle, "__fini");
+       if (bundle_fini_nssymbol != NULL) {
+               bundle_fini = NSAddressOfSymbol(bundle_fini_nssymbol);
+               bundle_fini();
+       }
+       
+       return (int) NSUnLinkModule(bundle_handle, NULL);
+}
+
+void *zend_mh_bundle_symbol(void *bundle_handle, const char *symbol_name)
+{
+       NSSymbol symbol;
+       symbol = NSLookupSymbolInModule(bundle_handle, symbol_name);
+       return NSAddressOfSymbol(symbol);
+}
+
+const char *zend_mh_bundle_error(void)
+{
+       /* Witness the state of the art error reporting */
+       return NULL;
+}
+
+#endif /* HAVE_MACH_O_DYLD_H */