Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab076fd

Browse files
committed
Ted Horst writes in [email protected]:
This is a patch that Bill Bummgarner did for 1.4 that hasn't made its way into the distribution yet. This is important if you want to use the ObjC module.
1 parent 747e1ca commit ab076fd

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Python/importdl.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ typedef FARPROC dl_funcptr;
120120
#ifdef NeXT
121121
#define DYNAMIC_LINK
122122
#define USE_RLD
123+
/* Define this to 1 if you want be able to load ObjC modules as well:
124+
it switches between two different way of loading modules on the NeXT,
125+
one that directly interfaces with the dynamic loader (rld_load(), which
126+
does not correctly load ObjC object files), and another that uses the
127+
ObjC runtime (objc_loadModules()) to do the job.
128+
You'll have to add ``-ObjC'' to the compiler flags if you set this to 1.
129+
*/
130+
#define HANDLE_OBJC_MODULES 1
131+
#if HANDLE_OBJC_MODULES
132+
#include <objc/Object.h>
133+
#include <objc/objc-load.h>
134+
#endif
123135
#define SHORT_EXT ".so"
124136
#define LONG_EXT "module.so"
125137
#endif
@@ -584,9 +596,38 @@ _PyImport_LoadDynamicModule(name, pathname, fp)
584596
errorStream = NXOpenMemory(NULL, 0, NX_WRITEONLY);
585597
filenames[0] = pathname;
586598
filenames[1] = NULL;
599+
600+
#if HANDLE_OBJC_MODULES
601+
602+
/* The following very bogus line of code ensures that
603+
objc_msgSend, etc are linked into the binary. Without
604+
it, dynamic loading of a module that includes objective-c
605+
method calls will fail with "undefined symbol _objc_msgSend()".
606+
This remains true even in the presence of the -ObjC flag
607+
to the compiler
608+
*/
609+
610+
[Object name];
611+
612+
/* objc_loadModules() dynamically loads the object files
613+
indicated by the paths in filenames. If there are any
614+
errors generated during loading -- typically due to the
615+
inability to find particular symbols -- an error message
616+
will be written to errorStream.
617+
It returns 0 if the module is successfully loaded, 1
618+
otherwise.
619+
*/
620+
621+
ret = !objc_loadModules(filenames, errorStream,
622+
NULL, &new_header, NULL);
623+
624+
#else /* !HANDLE_OBJC_MODULES */
625+
587626
ret = rld_load(errorStream, &new_header,
588627
filenames, NULL);
589628

629+
#endif /* HANDLE_OBJC_MODULES */
630+
590631
/* extract the error messages for the exception */
591632
if(!ret) {
592633
char *streamBuf;

0 commit comments

Comments
 (0)