annotate Python/dynload_beos.c @ 20737:00a581bdedeb legacy-trunk

When overriding __str__ or __repr__, set the tp_print slot to NULL.
author Guido van Rossum <guido@python.org>
date Mon, 29 Oct 2001 14:33:44 +0000
parents 6f6f965c5e2d
children c5fbe92e02d3
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 #include <unistd.h>
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #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
10 #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
11
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 const struct filedescr _PyImport_DynLoadFiletab[] = {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 {".so", "rb", C_EXTENSION},
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 {"module.so", "rb", C_EXTENSION},
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 {0, 0}
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 #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
19 #undef MAXPATHLEN
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 #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
23 #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
24 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
25 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 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
28
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 /* ----------------------------------------------------------------------
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 * 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
31 *
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 * 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
33 * (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
34 * 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
35 * 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
36 *
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 * 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
38 * 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
39 * 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
40 *
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 * 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
42 * 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
43 * 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
44 * 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
45 *
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 * 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
47 * 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
48 * [chrish]
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 /* 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
52 * 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
53 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 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
55 {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 status_t retval;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 if( item ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 image_id id = (image_id)PyInt_AsLong( item );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 retval = unload_add_on( id );
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 /* 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
66 * dictionary.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 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
69 {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 if( beos_dyn_images ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 int idx;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 int list_size;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 PyObject *id_list;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 #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
76 PyThread_acquire_lock( beos_dyn_lock, 1 );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
78
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 id_list = PyDict_Values( beos_dyn_images );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
80
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 list_size = PyList_Size( id_list );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 for( idx = 0; idx < list_size; idx++ ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 PyObject *the_item;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 the_item = PyList_GetItem( id_list, idx );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 beos_nuke_dyn( the_item );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
88
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 PyDict_Clear( beos_dyn_images );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 #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
92 PyThread_free_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
93 #endif
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 /*
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 * 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
99 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 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
101 {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 /* We're protected from a race condition here by the atomic init_count
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 * variable.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 static int32 init_count = 0;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 int32 val;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
107
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 val = atomic_add( &init_count, 1 );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 if( beos_dyn_images == NULL && val == 0 ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 beos_dyn_images = PyDict_New();
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 #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
112 beos_dyn_lock = PyThread_allocate_lock();
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 atexit( beos_cleanup_dyn );
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 /*
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 * 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
120 * 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
121 * 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
122 * 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
123 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 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
125 {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 int retval;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 PyObject *py_id;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
128
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 if( 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
130 beos_init_dyn();
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 #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
134 retval = PyThread_acquire_lock( beos_dyn_lock, 1 );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
136
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 /* If there's already an object with this key in the dictionary,
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 * we're doing a reload(), so let's nuke it.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 py_id = PyDict_GetItemString( beos_dyn_images, name );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 if( py_id ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 beos_nuke_dyn( py_id );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 retval = PyDict_DelItemString( beos_dyn_images, name );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 py_id = PyInt_FromLong( (long)id );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 if( py_id ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 retval = PyDict_SetItemString( beos_dyn_images, name, py_id );
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 #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
152 PyThread_release_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
153 #endif
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
157
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
158 dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 const char *pathname, FILE *fp)
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 dl_funcptr p;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 image_id the_id;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 status_t retval;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 char fullpath[PATH_MAX];
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
165 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
166
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 if( Py_VerboseFlag ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 printf( "load_add_on( %s )\n", pathname );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
170
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 /* Hmm, this old bug appears to have regenerated itself; if the
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 * path isn't absolute, load_add_on() will fail. Reported to Be
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 * April 21, 1998.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 if( pathname[0] != '/' ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 (void)getcwd( fullpath, PATH_MAX );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 (void)strncat( fullpath, "/", PATH_MAX );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 (void)strncat( fullpath, pathname, PATH_MAX );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
179
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 if( Py_VerboseFlag ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 printf( "load_add_on( %s )\n", fullpath );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 } else {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 (void)strcpy( fullpath, pathname );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
186
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 the_id = load_add_on( fullpath );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 if( the_id < B_NO_ERROR ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 /* It's too bad load_add_on() doesn't set errno or something...
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 char buff[256]; /* hate hard-coded string sizes... */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
192
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 if( Py_VerboseFlag ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 printf( "load_add_on( %s ) failed", fullpath );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
196
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 switch( the_id ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 case B_ERROR:
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 sprintf( buff, "BeOS: Failed to load %.200s", fullpath );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 break;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 default:
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 sprintf( buff, "Unknown error loading %.200s", fullpath );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 break;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
205
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 PyErr_SetString( PyExc_ImportError, buff );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 return NULL;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
209
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
210 sprintf(funcname, "init%.200s", shortname);
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 if( Py_VerboseFlag ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 printf( "get_image_symbol( %s )\n", funcname );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
214
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 retval = get_image_symbol( the_id, funcname, B_SYMBOL_TYPE_TEXT, &p );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 if( retval != B_NO_ERROR || p == NULL ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 /* That's bad, we can't find that symbol in the module...
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 char buff[256]; /* hate hard-coded string sizes... */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
220
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 if( Py_VerboseFlag ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 printf( "get_image_symbol( %s ) failed", funcname );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
224
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 switch( retval ) {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 case B_BAD_IMAGE_ID:
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 sprintf( buff, "can't load init function for dynamic module: "
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 "Invalid image ID for %.180s", fullpath );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 break;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 case B_BAD_INDEX:
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 sprintf( buff, "can't load init function for dynamic module: "
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 "Bad index for %.180s", funcname );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 break;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 default:
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 sprintf( buff, "can't load init function for dynamic module: "
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 "Unknown error looking up %.180s", funcname );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 break;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
239
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 retval = unload_add_on( the_id );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
241
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 PyErr_SetString( PyExc_ImportError, buff );
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 return NULL;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
245
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 /* Save the module name and image ID for later so we can clean up
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 * gracefully.
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 */
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
249 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
250
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 return p;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 }