annotate Python/dynload_beos.c @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents fd25030223b0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Support for dynamic loading of extension modules */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #include <kernel/image.h>
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #include <kernel/OS.h>
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 #include <stdlib.h>
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 #include "Python.h"
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #include "importdl.h"
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 const struct filedescr _PyImport_DynLoadFiletab[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
12 {".so", "rb", C_EXTENSION},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
13 {"module.so", "rb", C_EXTENSION},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
14 {0, 0}
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 };
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #if defined(MAXPATHLEN) && !defined(_SYS_PARAM_H)
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 #undef MAXPATHLEN
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 #ifdef WITH_THREAD
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 #include "pythread.h"
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 static PyThread_type_lock beos_dyn_lock;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 static PyObject *beos_dyn_images = NULL;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 /* ----------------------------------------------------------------------
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 * BeOS dynamic loading support
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 *
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 * This uses shared libraries, but BeOS has its own way of doing things
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 * (much easier than dlfnc.h, from the look of things). We'll use a
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 * Python Dictionary object to store the images_ids so we can be very
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 * nice and unload them when we exit.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 *
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 * Note that this is thread-safe. Probably irrelevent, because of losing
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 * systems... Python probably disables threads while loading modules.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 * Note the use of "probably"! Better to be safe than sorry. [chrish]
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 *
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 * As of 1.5.1 this should also work properly when you've configured
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 * Python without thread support; the 1.5 version required it, which wasn't
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 * very friendly. Note that I haven't tested it without threading... why
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 * would you want to avoid threads on BeOS? [chrish]
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 *
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 * As of 1.5.2, the PyImport_BeImageID() function has been removed; Donn
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 * tells me it's not necessary anymore because of PyCObject_Import().
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 * [chrish]
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 /* Whack an item; the item is an image_id in disguise, so we'll call
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 * unload_add_on() for it.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 static void beos_nuke_dyn( PyObject *item )
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
55 status_t retval;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
57 if( item ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
58 image_id id = (image_id)PyInt_AsLong( item );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
59
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
60 retval = unload_add_on( id );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
61 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 /* atexit() handler that'll call unload_add_on() for every item in the
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 * dictionary.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 static void beos_cleanup_dyn( void )
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
69 if( beos_dyn_images ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
70 int idx;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
71 int list_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
72 PyObject *id_list;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 #ifdef WITH_THREAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
75 PyThread_acquire_lock( beos_dyn_lock, 1 );
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
77
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
78 id_list = PyDict_Values( beos_dyn_images );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
79
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
80 list_size = PyList_Size( id_list );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
81 for( idx = 0; idx < list_size; idx++ ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
82 PyObject *the_item;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
84 the_item = PyList_GetItem( id_list, idx );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
85 beos_nuke_dyn( the_item );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
86 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
88 PyDict_Clear( beos_dyn_images );
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 #ifdef WITH_THREAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
91 PyThread_free_lock( beos_dyn_lock );
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
93 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 /*
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 * Initialize our dictionary, and the dictionary mutex.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 static void beos_init_dyn( void )
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
101 /* We're protected from a race condition here by the atomic init_count
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
102 * variable.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
103 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
104 static int32 init_count = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
105 int32 val;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
107 val = atomic_add( &init_count, 1 );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
108 if( beos_dyn_images == NULL && val == 0 ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
109 beos_dyn_images = PyDict_New();
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 #ifdef WITH_THREAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
111 beos_dyn_lock = PyThread_allocate_lock();
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
113 atexit( beos_cleanup_dyn );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
114 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
116
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 /*
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 * Add an image_id to the dictionary; the module name of the loaded image
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 * is the key. Note that if the key is already in the dict, we unload
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 * that image; this should allow reload() to work on dynamically loaded
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 * modules (super-keen!).
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 static void beos_add_dyn( char *name, image_id id )
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
125 int retval;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
126 PyObject *py_id;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
128 if( beos_dyn_images == NULL ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
129 beos_init_dyn();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
130 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
131
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 #ifdef WITH_THREAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
133 retval = PyThread_acquire_lock( beos_dyn_lock, 1 );
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
135
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
136 /* If there's already an object with this key in the dictionary,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
137 * we're doing a reload(), so let's nuke it.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
138 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
139 py_id = PyDict_GetItemString( beos_dyn_images, name );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
140 if( py_id ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
141 beos_nuke_dyn( py_id );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
142 retval = PyDict_DelItemString( beos_dyn_images, name );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
143 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
144
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
145 py_id = PyInt_FromLong( (long)id );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
146 if( py_id ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
147 retval = PyDict_SetItemString( beos_dyn_images, name, py_id );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
148 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
149
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 #ifdef WITH_THREAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
151 PyThread_release_lock( beos_dyn_lock );
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
157 dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
158 const char *pathname, FILE *fp)
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
160 dl_funcptr p;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
161 image_id the_id;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
162 status_t retval;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
163 char fullpath[PATH_MAX];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
164 char funcname[258];
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
165
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
166 if( Py_VerboseFlag ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
167 printf( "load_add_on( %s )\n", pathname );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
168 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
169
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
170 /* Hmm, this old bug appears to have regenerated itself; if the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
171 * path isn't absolute, load_add_on() will fail. Reported to Be
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
172 * April 21, 1998.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
173 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
174 if( pathname[0] != '/' ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
175 (void)getcwd( fullpath, PATH_MAX );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
176 (void)strncat( fullpath, "/", PATH_MAX );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
177 (void)strncat( fullpath, pathname, PATH_MAX );
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
178
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
179 if( Py_VerboseFlag ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
180 printf( "load_add_on( %s )\n", fullpath );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
181 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
182 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
183 (void)strcpy( fullpath, pathname );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
184 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
185
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
186 the_id = load_add_on( fullpath );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
187 if( the_id < B_NO_ERROR ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
188 /* It's too bad load_add_on() doesn't set errno or something...
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
189 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
190 char buff[256]; /* hate hard-coded string sizes... */
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
191
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
192 if( Py_VerboseFlag ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
193 printf( "load_add_on( %s ) failed", fullpath );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
194 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
195
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
196 if( the_id == B_ERROR )
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
197 PyOS_snprintf( buff, sizeof(buff),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
198 "BeOS: Failed to load %.200s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
199 fullpath );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
200 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
201 PyOS_snprintf( buff, sizeof(buff),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
202 "Unknown error loading %.200s",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
203 fullpath );
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
204
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
205 PyErr_SetString( PyExc_ImportError, buff );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
206 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
207 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
208
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
209 PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
210 if( Py_VerboseFlag ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
211 printf( "get_image_symbol( %s )\n", funcname );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
212 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
214 retval = get_image_symbol( the_id, funcname, B_SYMBOL_TYPE_TEXT, &p );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
215 if( retval != B_NO_ERROR || p == NULL ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
216 /* That's bad, we can't find that symbol in the module...
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
217 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
218 char buff[256]; /* hate hard-coded string sizes... */
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
219
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
220 if( Py_VerboseFlag ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
221 printf( "get_image_symbol( %s ) failed", funcname );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
222 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
223
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
224 switch( retval ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
225 case B_BAD_IMAGE_ID:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
226 PyOS_snprintf( buff, sizeof(buff),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
227 "can't load init function for dynamic module: "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
228 "Invalid image ID for %.180s", fullpath );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
229 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
230 case B_BAD_INDEX:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
231 PyOS_snprintf( buff, sizeof(buff),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
232 "can't load init function for dynamic module: "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
233 "Bad index for %.180s", funcname );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
234 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
235 default:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
236 PyOS_snprintf( buff, sizeof(buff),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
237 "can't load init function for dynamic module: "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
238 "Unknown error looking up %.180s", funcname );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
239 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
240 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
241
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
242 retval = unload_add_on( the_id );
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
243
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
244 PyErr_SetString( PyExc_ImportError, buff );
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
245 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
246 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
247
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
248 /* Save the module name and image ID for later so we can clean up
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
249 * gracefully.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
250 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
251 beos_add_dyn( fqname, the_id );
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
252
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 21790
diff changeset
253 return p;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 }