annotate Modules/dlmodule.c @ 3216:d00a79ebb027 legacy-trunk

Added missing imgpbm and imgsgi modules
author Jack Jansen <jack.jansen@cwi.nl>
date Thu, 12 Oct 1995 10:23:27 +0000
parents 172ba04a5191
children 65d2d8e67da3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
2061
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1650
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1650
diff changeset
3 The Netherlands.
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 ******************************************************************/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /* dl module */
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 #include "allobjects.h"
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #include "modsupport.h"
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 #include <dlfcn.h>
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 #ifndef RTLD_LAZY
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 #define RTLD_LAZY 1
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #endif
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 typedef struct {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 OB_HEAD
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 ANY *dl_handle;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 } dlobject;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 staticforward typeobject Dltype;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 static object *Dlerror;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 static object *
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 newdlobject(handle)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 ANY *handle;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 dlobject *xp;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 xp = NEWOBJ(dlobject, &Dltype);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 if (xp == NULL)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 xp->dl_handle = handle;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 return (object *)xp;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 static void
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 dl_dealloc(xp)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 dlobject *xp;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 if (xp->dl_handle != NULL)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 dlclose(xp->dl_handle);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 DEL(xp);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 static object *
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 dl_close(xp, args)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 dlobject *xp;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 object *args;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 if (!getargs(args, ""))
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 if (xp->dl_handle != NULL) {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 dlclose(xp->dl_handle);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 xp->dl_handle = NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 INCREF(None);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 return None;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
80
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 static object *
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 dl_sym(xp, args)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 dlobject *xp;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 object *args;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 char *name;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 ANY *func;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 if (!getargs(args, "s", &name))
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 func = dlsym(xp->dl_handle, name);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 if (func == NULL) {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 INCREF(None);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 return None;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 return newintobject((long)func);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 static object *
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 dl_call(xp, args)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 dlobject *xp;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 object *args; /* (varargs) */
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 object *name;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 long (*func)();
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 long alist[10];
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 long res;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 int i;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 int n = gettuplesize(args);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 if (n < 1) {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 err_setstr(TypeError, "at least a name is needed");
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 name = gettupleitem(args, 0);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 if (!is_stringobject(name)) {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 err_setstr(TypeError, "function name must be a string");
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 func = dlsym(xp->dl_handle, getstringvalue(name));
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 if (func == NULL) {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 err_setstr(ValueError, dlerror());
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 if (n-1 > 10) {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 err_setstr(TypeError, "too many arguments (max 10)");
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 for (i = 1; i < n; i++) {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 object *v = gettupleitem(args, i);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 if (is_intobject(v))
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 alist[i-1] = getintvalue(v);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 else if (is_stringobject(v))
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 alist[i-1] = (long)getstringvalue(v);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 else if (v == None)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 alist[i-1] = (long) ((char *)NULL);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 else {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 err_setstr(TypeError,
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 "arguments must be int, string or None");
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 for (; i <= 10; i++)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 alist[i-1] = 0;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 res = (*func)(alist[0], alist[1], alist[2], alist[3], alist[4],
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 alist[5], alist[6], alist[7], alist[8], alist[9]);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 return newintobject(res);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
147
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 static struct methodlist dlobject_methods[] = {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 {"call", (method)dl_call, 1 /* varargs */},
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 {"sym", (method)dl_sym},
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 {"close", (method)dl_close},
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 {NULL, NULL} /* Sentinel */
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 };
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 static object *
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 dl_getattr(xp, name)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 dlobject *xp;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 char *name;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 return findmethod(dlobject_methods, (object *)xp, name);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
162
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 static typeobject Dltype = {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 OB_HEAD_INIT(&Typetype)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 0, /*ob_size*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 "dl", /*tp_name*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 sizeof(dlobject), /*tp_basicsize*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 0, /*tp_itemsize*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 /* methods */
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 (destructor)dl_dealloc, /*tp_dealloc*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 0, /*tp_print*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 (getattrfunc)dl_getattr,/*tp_getattr*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 0, /*tp_setattr*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 0, /*tp_compare*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 0, /*tp_repr*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 0, /*tp_as_number*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 0, /*tp_as_sequence*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 0, /*tp_as_mapping*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 0, /*tp_hash*/
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 };
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
182
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 static object *
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 dl_open(self, args)
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 object *self;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 object *args;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 char *name;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 int mode;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 ANY *handle;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 if (getargs(args, "z", &name))
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 mode = RTLD_LAZY;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 else {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 err_clear();
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 if (!getargs(args, "(zi)", &name, &mode))
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 #ifndef RTLD_NOW
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 if (mode != RTLD_LAZY) {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 err_setstr(ValueError, "mode must be 1");
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 #endif
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 handle = dlopen(name, mode);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 if (handle == NULL) {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 err_setstr(Dlerror, dlerror());
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 return NULL;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 return newdlobject(handle);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
211
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 static struct methodlist dl_methods[] = {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 {"open", dl_open},
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 {NULL, NULL} /* sentinel */
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 };
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
216
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 void
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 initdl()
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 {
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 object *m, *d, *x;
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
221
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 if (sizeof(int) != sizeof(long) ||
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 sizeof(long) != sizeof(char *))
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 fatal(
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 "module dl requires sizeof(int) == sizeof(long) == sizeof(char*)");
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
226
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 /* Create the module and add the functions */
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 m = initmodule("dl", dl_methods);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 /* Add some symbolic constants to the module */
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 d = getmoduledict(m);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 Dlerror = x = newstringobject("dl.error");
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 dictinsert(d, "error", x);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 x = newintobject((long)RTLD_LAZY);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 dictinsert(d, "RTLD_LAZY", x);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 #ifdef RTLD_NOW
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 x = newintobject((long)RTLD_NOW);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 dictinsert(d, "RTLD_NOW", x);
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 #endif
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
240
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 /* Check for errors */
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 if (err_occurred())
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 fatal("can't initialize module dl");
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 }