Mercurial > cpython-lru_cache-weakref
annotate Objects/capsule.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 | d11fbc796499 |
| children |
| rev | line source |
|---|---|
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
1 /* Wrap void * pointers to be passed between C modules */ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
2 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
3 #include "Python.h" |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
4 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
5 /* Internal structure of PyCapsule */ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
6 typedef struct { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
7 PyObject_HEAD |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
8 void *pointer; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
9 const char *name; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
10 void *context; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
11 PyCapsule_Destructor destructor; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
12 } PyCapsule; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
13 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
14 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
15 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
16 static int |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
17 _is_legal_capsule(PyCapsule *capsule, const char *invalid_capsule) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
18 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
19 if (!capsule || !PyCapsule_CheckExact(capsule) || capsule->pointer == NULL) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
20 PyErr_SetString(PyExc_ValueError, invalid_capsule); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
21 return 0; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
22 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
23 return 1; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
24 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
25 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
26 #define is_legal_capsule(capsule, name) \ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
27 (_is_legal_capsule(capsule, \ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
28 name " called with invalid PyCapsule object")) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
29 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
30 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
31 static int |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
32 name_matches(const char *name1, const char *name2) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
33 /* if either is NULL, */ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
34 if (!name1 || !name2) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
35 /* they're only the same if they're both NULL. */ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
36 return name1 == name2; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
37 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
38 return !strcmp(name1, name2); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
39 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
40 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
41 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
42 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
43 PyObject * |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
44 PyCapsule_New(void *pointer, const char *name, PyCapsule_Destructor destructor) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
45 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
46 PyCapsule *capsule; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
47 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
48 if (!pointer) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
49 PyErr_SetString(PyExc_ValueError, "PyCapsule_New called with null pointer"); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
50 return NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
51 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
52 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
53 capsule = PyObject_NEW(PyCapsule, &PyCapsule_Type); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
54 if (capsule == NULL) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
55 return NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
56 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
57 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
58 capsule->pointer = pointer; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
59 capsule->name = name; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
60 capsule->context = NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
61 capsule->destructor = destructor; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
62 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
63 return (PyObject *)capsule; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
64 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
65 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
66 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
67 int |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
68 PyCapsule_IsValid(PyObject *o, const char *name) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
69 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
70 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
71 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
72 return (capsule != NULL && |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
73 PyCapsule_CheckExact(capsule) && |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
74 capsule->pointer != NULL && |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
75 name_matches(capsule->name, name)); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
76 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
77 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
78 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
79 void * |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
80 PyCapsule_GetPointer(PyObject *o, const char *name) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
81 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
82 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
83 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
84 if (!is_legal_capsule(capsule, "PyCapsule_GetPointer")) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
85 return NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
86 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
87 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
88 if (!name_matches(name, capsule->name)) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
89 PyErr_SetString(PyExc_ValueError, "PyCapsule_GetPointer called with incorrect name"); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
90 return NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
91 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
92 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
93 return capsule->pointer; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
94 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
95 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
96 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
97 const char * |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
98 PyCapsule_GetName(PyObject *o) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
99 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
100 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
101 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
102 if (!is_legal_capsule(capsule, "PyCapsule_GetName")) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
103 return NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
104 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
105 return capsule->name; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
106 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
107 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
108 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
109 PyCapsule_Destructor |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
110 PyCapsule_GetDestructor(PyObject *o) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
111 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
112 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
113 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
114 if (!is_legal_capsule(capsule, "PyCapsule_GetDestructor")) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
115 return NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
116 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
117 return capsule->destructor; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
118 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
119 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
120 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
121 void * |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
122 PyCapsule_GetContext(PyObject *o) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
123 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
124 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
125 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
126 if (!is_legal_capsule(capsule, "PyCapsule_GetContext")) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
127 return NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
128 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
129 return capsule->context; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
130 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
131 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
132 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
133 int |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
134 PyCapsule_SetPointer(PyObject *o, void *pointer) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
135 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
136 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
137 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
138 if (!pointer) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
139 PyErr_SetString(PyExc_ValueError, "PyCapsule_SetPointer called with null pointer"); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
140 return -1; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
141 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
142 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
143 if (!is_legal_capsule(capsule, "PyCapsule_SetPointer")) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
144 return -1; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
145 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
146 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
147 capsule->pointer = pointer; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
148 return 0; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
149 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
150 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
151 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
152 int |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
153 PyCapsule_SetName(PyObject *o, const char *name) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
154 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
155 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
156 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
157 if (!is_legal_capsule(capsule, "PyCapsule_SetName")) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
158 return -1; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
159 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
160 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
161 capsule->name = name; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
162 return 0; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
163 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
164 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
165 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
166 int |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
167 PyCapsule_SetDestructor(PyObject *o, PyCapsule_Destructor destructor) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
168 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
169 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
170 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
171 if (!is_legal_capsule(capsule, "PyCapsule_SetDestructor")) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
172 return -1; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
173 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
174 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
175 capsule->destructor = destructor; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
176 return 0; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
177 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
178 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
179 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
180 int |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
181 PyCapsule_SetContext(PyObject *o, void *context) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
182 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
183 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
184 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
185 if (!is_legal_capsule(capsule, "PyCapsule_SetContext")) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
186 return -1; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
187 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
188 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
189 capsule->context = context; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
190 return 0; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
191 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
192 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
193 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
194 void * |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
195 PyCapsule_Import(const char *name, int no_block) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
196 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
197 PyObject *object = NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
198 void *return_value = NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
199 char *trace; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
200 size_t name_length = (strlen(name) + 1) * sizeof(char); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
201 char *name_dup = (char *)PyMem_MALLOC(name_length); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
202 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
203 if (!name_dup) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
204 return NULL; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
205 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
206 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
207 memcpy(name_dup, name, name_length); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
208 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
209 trace = name_dup; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
210 while (trace) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
211 char *dot = strchr(trace, '.'); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
212 if (dot) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
213 *dot++ = '\0'; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
214 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
215 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
216 if (object == NULL) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
217 if (no_block) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
218 object = PyImport_ImportModuleNoBlock(trace); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
219 } else { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
220 object = PyImport_ImportModule(trace); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
221 if (!object) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
222 PyErr_Format(PyExc_ImportError, "PyCapsule_Import could not import module \"%s\"", trace); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
223 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
224 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
225 } else { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
226 PyObject *object2 = PyObject_GetAttrString(object, trace); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
227 Py_DECREF(object); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
228 object = object2; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
229 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
230 if (!object) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
231 goto EXIT; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
232 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
233 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
234 trace = dot; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
235 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
236 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
237 /* compare attribute name to module.name by hand */ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
238 if (PyCapsule_IsValid(object, name)) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
239 PyCapsule *capsule = (PyCapsule *)object; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
240 return_value = capsule->pointer; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
241 } else { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
242 PyErr_Format(PyExc_AttributeError, |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
243 "PyCapsule_Import \"%s\" is not valid", |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
244 name); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
245 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
246 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
247 EXIT: |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
248 Py_XDECREF(object); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
249 if (name_dup) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
250 PyMem_FREE(name_dup); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
251 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
252 return return_value; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
253 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
254 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
255 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
256 static void |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
257 capsule_dealloc(PyObject *o) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
258 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
259 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
260 if (capsule->destructor) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
261 capsule->destructor(o); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
262 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
263 PyObject_DEL(o); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
264 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
265 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
266 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
267 static PyObject * |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
268 capsule_repr(PyObject *o) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
269 { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
270 PyCapsule *capsule = (PyCapsule *)o; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
271 const char *name; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
272 const char *quote; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
273 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
274 if (capsule->name) { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
275 quote = "\""; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
276 name = capsule->name; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
277 } else { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
278 quote = ""; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
279 name = "NULL"; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
280 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
281 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
282 return PyString_FromFormat("<capsule object %s%s%s at %p>", |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
283 quote, name, quote, capsule); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
284 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
285 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
286 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
287 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
288 PyDoc_STRVAR(PyCapsule_Type__doc__, |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
289 "Capsule objects let you wrap a C \"void *\" pointer in a Python\n\ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
290 object. They're a way of passing data through the Python interpreter\n\ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
291 without creating your own custom type.\n\ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
292 \n\ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
293 Capsules are used for communication between extension modules.\n\ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
294 They provide a way for an extension module to export a C interface\n\ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
295 to other extension modules, so that extension modules can use the\n\ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
296 Python import mechanism to link to one another.\n\ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
297 "); |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
298 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
299 PyTypeObject PyCapsule_Type = { |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
300 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
301 "PyCapsule", /*tp_name*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
302 sizeof(PyCapsule), /*tp_basicsize*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
303 0, /*tp_itemsize*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
304 /* methods */ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
305 capsule_dealloc, /*tp_dealloc*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
306 0, /*tp_print*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
307 0, /*tp_getattr*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
308 0, /*tp_setattr*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
309 0, /*tp_reserved*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
310 capsule_repr, /*tp_repr*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
311 0, /*tp_as_number*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
312 0, /*tp_as_sequence*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
313 0, /*tp_as_mapping*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
314 0, /*tp_hash*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
315 0, /*tp_call*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
316 0, /*tp_str*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
317 0, /*tp_getattro*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
318 0, /*tp_setattro*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
319 0, /*tp_as_buffer*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
320 0, /*tp_flags*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
321 PyCapsule_Type__doc__ /*tp_doc*/ |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
322 }; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
323 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
diff
changeset
|
324 |
