]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | /* This module exports the C API to such Pure Software Inc. (tm) (now\r |
2 | * called Pure Atria Corporation) products as Purify (tm) and Quantify\r | |
3 | * (tm). Other packages could be added, but I didn't have those products\r | |
4 | * and thus lack the API documentation.\r | |
5 | *\r | |
6 | * Currently supported: Quantify 2.x, Purify 3.x\r | |
7 | *\r | |
8 | * You need to decide which products you want to incorporate into the\r | |
9 | * module when you compile this file. The way to do this is to edit\r | |
10 | * <Python>/Modules/Setup to pass the appropriate flags to the compiler.\r | |
11 | * -DWITH_PURIFY compiles in the Purify support, and -DWITH_QUANTIFY\r | |
12 | * compiles in the Quantify support. -DWITH_ALL_PURE compiles in both.\r | |
13 | * You can also build a Purify'd or Quantify'd interpreter by passing in\r | |
14 | * the LINKCC variable to make. E.g. if you want to build a Purify'd\r | |
15 | * interpreter and are using gcc, build Python with this command:\r | |
16 | *\r | |
17 | * make LINKCC='purify gcc'\r | |
18 | *\r | |
19 | * It would be nice (and probably easy) to provide this file as a shared\r | |
20 | * library, however since it doesn't appear that Pure gives us shared\r | |
21 | * libraries of the stubs, it doesn't really matter. For now, you have to\r | |
22 | * link this file in statically.\r | |
23 | *\r | |
24 | * Major bogosity. The purify.h header file exports purify_exit(), but\r | |
25 | * guess what? It is not defined in the libpurify_stubs.a file! I tried\r | |
26 | * to fake one here, hoping the Pure linker would Do The Right Thing when\r | |
27 | * instrumented for Purify, but it doesn't seem to, so I don't export\r | |
28 | * purify_exit() to the Python layer. In Python you should raise a\r | |
29 | * SystemExit exception anyway.\r | |
30 | *\r | |
31 | * The actual purify.h and quantify.h files which embody the APIs are\r | |
32 | * copyrighted by Pure Software, Inc. and are only attainable through them.\r | |
33 | * This module assumes you have legally installed licenses of their\r | |
34 | * software. Contact them on the Web via <http://www.pureatria.com/>\r | |
35 | *\r | |
36 | * Author: Barry Warsaw <bwarsaw@python.org>\r | |
37 | * <bwarsaw@cnri.reston.va.us>\r | |
38 | */\r | |
39 | \r | |
40 | #include "Python.h"\r | |
41 | \r | |
42 | #if defined(WITH_PURIFY) || defined(WITH_ALL_PURE)\r | |
43 | # include <purify.h>\r | |
44 | # define HAS_PURIFY_EXIT 0 /* See note at top of file */\r | |
45 | # define PURE_PURIFY_VERSION 3 /* not provided by purify.h */\r | |
46 | #endif\r | |
47 | #if defined(WITH_QUANTIFY) || defined(WITH_ALL_PURE)\r | |
48 | # include <quantify.h>\r | |
49 | # define PURE_QUANTIFY_VERSION 2 /* not provided by quantify.h */\r | |
50 | #endif\r | |
51 | #if defined(PURIFY_H) || defined(QUANTIFY_H)\r | |
52 | # define COMMON_PURE_FUNCTIONS\r | |
53 | #endif /* PURIFY_H || QUANTIFY_H */\r | |
54 | \r | |
55 | typedef int (*VoidArgFunc)(void);\r | |
56 | typedef int (*StringArgFunc)(char*);\r | |
57 | typedef int (*PrintfishFunc)(const char*, ...);\r | |
58 | typedef int (*StringIntArgFunc)(const char*, int);\r | |
59 | \r | |
60 | \r | |
61 | \r | |
62 | static PyObject*\r | |
63 | call_voidarg_function(VoidArgFunc func, PyObject *self, PyObject *args)\r | |
64 | {\r | |
65 | int status;\r | |
66 | \r | |
67 | if (!PyArg_ParseTuple(args, ""))\r | |
68 | return NULL;\r | |
69 | \r | |
70 | status = func();\r | |
71 | return Py_BuildValue("i", status);\r | |
72 | }\r | |
73 | \r | |
74 | static PyObject*\r | |
75 | call_stringarg_function(StringArgFunc func, PyObject *self, PyObject *args)\r | |
76 | {\r | |
77 | int status;\r | |
78 | char* stringarg;\r | |
79 | \r | |
80 | if (!PyArg_ParseTuple(args, "s", &stringarg))\r | |
81 | return NULL;\r | |
82 | \r | |
83 | status = func(stringarg);\r | |
84 | return Py_BuildValue("i", status);\r | |
85 | }\r | |
86 | \r | |
87 | static PyObject*\r | |
88 | call_stringorint_function(StringArgFunc func, PyObject *self, PyObject *args)\r | |
89 | {\r | |
90 | int status;\r | |
91 | int intarg;\r | |
92 | char* stringarg;\r | |
93 | \r | |
94 | /* according to the quantify.h file, the argument to\r | |
95 | * quantify_*_recording_system_call can be an integer or a string,\r | |
96 | * but the functions are prototyped as taking a single char*\r | |
97 | * argument. Yikes!\r | |
98 | */\r | |
99 | if (PyArg_ParseTuple(args, "i", &intarg))\r | |
100 | /* func is prototyped as int(*)(char*)\r | |
101 | * better shut up the compiler\r | |
102 | */\r | |
103 | status = func((char*)intarg);\r | |
104 | \r | |
105 | else {\r | |
106 | PyErr_Clear();\r | |
107 | if (!PyArg_ParseTuple(args, "s", &stringarg))\r | |
108 | return NULL;\r | |
109 | else\r | |
110 | status = func(stringarg);\r | |
111 | }\r | |
112 | return Py_BuildValue("i", status);\r | |
113 | }\r | |
114 | \r | |
115 | static PyObject*\r | |
116 | call_printfish_function(PrintfishFunc func, PyObject *self, PyObject *args)\r | |
117 | {\r | |
118 | /* we support the printf() style vararg functions by requiring the\r | |
119 | * formatting be done in Python. At the C level we pass just a string\r | |
120 | * to the printf() style function.\r | |
121 | */\r | |
122 | int status;\r | |
123 | char* argstring;\r | |
124 | \r | |
125 | if (!PyArg_ParseTuple(args, "s", &argstring))\r | |
126 | return NULL;\r | |
127 | \r | |
128 | status = func("%s", argstring);\r | |
129 | return Py_BuildValue("i", status);\r | |
130 | }\r | |
131 | \r | |
132 | static PyObject*\r | |
133 | call_intasaddr_function(StringArgFunc func, PyObject *self, PyObject *args)\r | |
134 | {\r | |
135 | long memrep;\r | |
136 | int id;\r | |
137 | \r | |
138 | if (!PyArg_ParseTuple(args, "l", &memrep))\r | |
139 | return NULL;\r | |
140 | \r | |
141 | id = func((char*)memrep);\r | |
142 | return Py_BuildValue("i", id);\r | |
143 | }\r | |
144 | \r | |
145 | static PyObject*\r | |
146 | call_stringandint_function(StringIntArgFunc func, PyObject *self,\r | |
147 | PyObject *args)\r | |
148 | {\r | |
149 | long srcrep;\r | |
150 | int size;\r | |
151 | int status;\r | |
152 | \r | |
153 | if (!PyArg_ParseTuple(args, "li", &srcrep, &size))\r | |
154 | return NULL;\r | |
155 | \r | |
156 | status = func((char*)srcrep, size);\r | |
157 | return Py_BuildValue("i", status);\r | |
158 | }\r | |
159 | \r | |
160 | \r | |
161 | \r | |
162 | /* functions common to all products\r | |
163 | *\r | |
164 | * N.B. These printf() style functions are a bit of a kludge. Since the\r | |
165 | * API doesn't provide vprintf versions of them, we can't call them\r | |
166 | * directly. They don't support all the standard printf % modifiers\r | |
167 | * anyway. The way to use these is to use Python's % string operator to do\r | |
168 | * the formatting. By the time these functions get the thing to print,\r | |
169 | * it's already a string, and they just use "%s" as the format string.\r | |
170 | */\r | |
171 | \r | |
172 | #ifdef COMMON_PURE_FUNCTIONS\r | |
173 | \r | |
174 | static PyObject*\r | |
175 | pure_pure_logfile_printf(PyObject* self, PyObject* args)\r | |
176 | {\r | |
177 | return call_printfish_function(pure_logfile_printf, self, args);\r | |
178 | }\r | |
179 | \r | |
180 | static PyObject*\r | |
181 | pure_pure_printf(PyObject* self, PyObject* args)\r | |
182 | {\r | |
183 | return call_printfish_function(pure_printf, self, args);\r | |
184 | }\r | |
185 | \r | |
186 | static PyObject*\r | |
187 | pure_pure_printf_with_banner(PyObject* self, PyObject* args)\r | |
188 | {\r | |
189 | return call_printfish_function(pure_printf_with_banner, self, args);\r | |
190 | }\r | |
191 | \r | |
192 | \r | |
193 | #endif /* COMMON_PURE_FUNCTIONS */\r | |
194 | \r | |
195 | \r | |
196 | \r | |
197 | /* Purify functions\r | |
198 | *\r | |
199 | * N.B. There are some interfaces described in the purify.h file that are\r | |
200 | * not described in the manual.\r | |
201 | *\r | |
202 | * Unsigned longs purify_report_{address,number,type,result} are not\r | |
203 | * accessible from the Python layer since they seem mostly useful when\r | |
204 | * purify_stop_here() is called by the (C) debugger. The same is true of\r | |
205 | * the purify_stop_here_internal() function so it isn't exported either.\r | |
206 | * And purify_stop_here() should never be called directly.\r | |
207 | *\r | |
208 | * The header file says purify_{new,all,clear_new}_reports() are obsolete\r | |
209 | * so they aren't exported.\r | |
210 | *\r | |
211 | * None of the custom dynamic loader functions are exported.\r | |
212 | *\r | |
213 | * purify_unsafe_memcpy() isn't exported.\r | |
214 | *\r | |
215 | * purify_{start,size}_of_block() aren't exported.\r | |
216 | *\r | |
217 | * The manual that I have says that the prototype for the second argument\r | |
218 | * to purify_map_pool is:\r | |
219 | *\r | |
220 | * void (*fn)(char*)\r | |
221 | *\r | |
222 | * but the purify.h file declares it as:\r | |
223 | *\r | |
224 | * void (*fn)(char*, int, void*)\r | |
225 | *\r | |
226 | * and does not explain what the other arguments are for. I support the\r | |
227 | * latter but I don't know if I do it right or usefully.\r | |
228 | *\r | |
229 | * The header file says that purify_describe() returns a char* which is the\r | |
230 | * pointer passed to it. The manual says it returns an int, but I believe\r | |
231 | * that is a typo.\r | |
232 | */\r | |
233 | #ifdef PURIFY_H\r | |
234 | \r | |
235 | static PyObject*\r | |
236 | pure_purify_all_inuse(PyObject *self, PyObject *args)\r | |
237 | {\r | |
238 | return call_voidarg_function(purify_all_inuse, self, args);\r | |
239 | }\r | |
240 | static PyObject*\r | |
241 | pure_purify_all_leaks(PyObject *self, PyObject *args)\r | |
242 | {\r | |
243 | return call_voidarg_function(purify_all_leaks, self, args);\r | |
244 | }\r | |
245 | static PyObject*\r | |
246 | pure_purify_new_inuse(PyObject *self, PyObject *args)\r | |
247 | {\r | |
248 | return call_voidarg_function(purify_new_inuse, self, args);\r | |
249 | }\r | |
250 | static PyObject*\r | |
251 | pure_purify_new_leaks(PyObject *self, PyObject *args)\r | |
252 | {\r | |
253 | return call_voidarg_function(purify_new_leaks, self, args);\r | |
254 | }\r | |
255 | static PyObject*\r | |
256 | pure_purify_clear_inuse(PyObject *self, PyObject *args)\r | |
257 | {\r | |
258 | return call_voidarg_function(purify_clear_inuse, self, args);\r | |
259 | }\r | |
260 | static PyObject*\r | |
261 | pure_purify_clear_leaks(PyObject *self, PyObject *args)\r | |
262 | {\r | |
263 | return call_voidarg_function(purify_clear_leaks, self, args);\r | |
264 | }\r | |
265 | static PyObject*\r | |
266 | pure_purify_all_fds_inuse(PyObject *self, PyObject *args)\r | |
267 | {\r | |
268 | return call_voidarg_function(purify_all_fds_inuse, self, args);\r | |
269 | }\r | |
270 | static PyObject*\r | |
271 | pure_purify_new_fds_inuse(PyObject *self, PyObject *args)\r | |
272 | {\r | |
273 | return call_voidarg_function(purify_new_fds_inuse, self, args);\r | |
274 | }\r | |
275 | static PyObject*\r | |
276 | pure_purify_printf_with_call_chain(PyObject *self, PyObject *args)\r | |
277 | {\r | |
278 | return call_printfish_function(purify_printf_with_call_chain,\r | |
279 | self, args);\r | |
280 | }\r | |
281 | static PyObject*\r | |
282 | pure_purify_set_pool_id(PyObject *self, PyObject *args)\r | |
283 | {\r | |
284 | long memrep;\r | |
285 | int id;\r | |
286 | \r | |
287 | if (!PyArg_ParseTuple(args, "li:purify_set_pool_id", &memrep, &id))\r | |
288 | return NULL;\r | |
289 | \r | |
290 | purify_set_pool_id((char*)memrep, id);\r | |
291 | Py_INCREF(Py_None);\r | |
292 | return Py_None;\r | |
293 | }\r | |
294 | static PyObject*\r | |
295 | pure_purify_get_pool_id(PyObject *self, PyObject *args)\r | |
296 | {\r | |
297 | return call_intasaddr_function(purify_get_pool_id, self, args);\r | |
298 | }\r | |
299 | static PyObject*\r | |
300 | pure_purify_set_user_data(PyObject *self, PyObject *args)\r | |
301 | {\r | |
302 | long memrep;\r | |
303 | long datarep;\r | |
304 | \r | |
305 | if (!PyArg_ParseTuple(args, "ll:purify_set_user_data", &memrep, &datarep))\r | |
306 | return NULL;\r | |
307 | \r | |
308 | purify_set_user_data((char*)memrep, (void*)datarep);\r | |
309 | Py_INCREF(Py_None);\r | |
310 | return Py_None;\r | |
311 | }\r | |
312 | static PyObject*\r | |
313 | pure_purify_get_user_data(PyObject *self, PyObject *args)\r | |
314 | {\r | |
315 | /* can't use call_intasaddr_function() since purify_get_user_data()\r | |
316 | * returns a void*\r | |
317 | */\r | |
318 | long memrep;\r | |
319 | void* data;\r | |
320 | \r | |
321 | if (!PyArg_ParseTuple(args, "l:purify_get_user_data", &memrep))\r | |
322 | return NULL;\r | |
323 | \r | |
324 | data = purify_get_user_data((char*)memrep);\r | |
325 | return Py_BuildValue("l", (long)data);\r | |
326 | }\r | |
327 | \r | |
328 | \r | |
329 | /* this global variable is shared by both mapping functions:\r | |
330 | * pure_purify_map_pool() and pure_purify_map_pool_id(). Since they cache\r | |
331 | * this variable it should be safe in the face of recursion or cross\r | |
332 | * calling.\r | |
333 | *\r | |
334 | * Further note that the prototype for the callback function is wrong in\r | |
335 | * the Purify manual. The manual says the function takes a single char*,\r | |
336 | * but the header file says it takes an additional int and void*. I have\r | |
337 | * no idea what these are for!\r | |
338 | */\r | |
339 | static PyObject* MapCallable = NULL;\r | |
340 | \r | |
341 | static void\r | |
342 | map_pool_callback(char* mem, int user_size, void *user_aux_data)\r | |
343 | {\r | |
344 | long memrep = (long)mem;\r | |
345 | long user_aux_data_rep = (long)user_aux_data;\r | |
346 | PyObject* result;\r | |
347 | PyObject* memobj = Py_BuildValue("lil", memrep, user_size,\r | |
348 | user_aux_data_rep);\r | |
349 | \r | |
350 | if (memobj == NULL)\r | |
351 | return;\r | |
352 | \r | |
353 | result = PyEval_CallObject(MapCallable, memobj);\r | |
354 | Py_DECREF(result);\r | |
355 | Py_DECREF(memobj);\r | |
356 | }\r | |
357 | \r | |
358 | static PyObject*\r | |
359 | pure_purify_map_pool(PyObject *self, PyObject *args)\r | |
360 | {\r | |
361 | /* cache global variable in case of recursion */\r | |
362 | PyObject* saved_callable = MapCallable;\r | |
363 | PyObject* arg_callable;\r | |
364 | int id;\r | |
365 | \r | |
366 | if (!PyArg_ParseTuple(args, "iO:purify_map_pool", &id, &arg_callable))\r | |
367 | return NULL;\r | |
368 | \r | |
369 | if (!PyCallable_Check(arg_callable)) {\r | |
370 | PyErr_SetString(PyExc_TypeError,\r | |
371 | "Second argument must be callable");\r | |
372 | return NULL;\r | |
373 | }\r | |
374 | MapCallable = arg_callable;\r | |
375 | purify_map_pool(id, map_pool_callback);\r | |
376 | MapCallable = saved_callable;\r | |
377 | \r | |
378 | Py_INCREF(Py_None);\r | |
379 | return Py_None;\r | |
380 | }\r | |
381 | \r | |
382 | static void\r | |
383 | PurifyMapPoolIdCallback(int id)\r | |
384 | {\r | |
385 | PyObject* result;\r | |
386 | PyObject* intobj = Py_BuildValue("i", id);\r | |
387 | \r | |
388 | if (intobj == NULL)\r | |
389 | return;\r | |
390 | \r | |
391 | result = PyEval_CallObject(MapCallable, intobj);\r | |
392 | Py_DECREF(result);\r | |
393 | Py_DECREF(intobj);\r | |
394 | }\r | |
395 | \r | |
396 | static PyObject*\r | |
397 | pure_purify_map_pool_id(PyObject *self, PyObject *args)\r | |
398 | {\r | |
399 | /* cache global variable in case of recursion */\r | |
400 | PyObject* saved_callable = MapCallable;\r | |
401 | PyObject* arg_callable;\r | |
402 | \r | |
403 | if (!PyArg_ParseTuple(args, "O:purify_map_pool_id", &arg_callable))\r | |
404 | return NULL;\r | |
405 | \r | |
406 | if (!PyCallable_Check(arg_callable)) {\r | |
407 | PyErr_SetString(PyExc_TypeError, "Argument must be callable.");\r | |
408 | return NULL;\r | |
409 | }\r | |
410 | \r | |
411 | MapCallable = arg_callable;\r | |
412 | purify_map_pool_id(PurifyMapPoolIdCallback);\r | |
413 | MapCallable = saved_callable;\r | |
414 | \r | |
415 | Py_INCREF(Py_None);\r | |
416 | return Py_None;\r | |
417 | }\r | |
418 | \r | |
419 | \r | |
420 | \r | |
421 | static PyObject*\r | |
422 | pure_purify_new_messages(PyObject *self, PyObject *args)\r | |
423 | {\r | |
424 | return call_voidarg_function(purify_new_messages, self, args);\r | |
425 | }\r | |
426 | static PyObject*\r | |
427 | pure_purify_all_messages(PyObject *self, PyObject *args)\r | |
428 | {\r | |
429 | return call_voidarg_function(purify_all_messages, self, args);\r | |
430 | }\r | |
431 | static PyObject*\r | |
432 | pure_purify_clear_messages(PyObject *self, PyObject *args)\r | |
433 | {\r | |
434 | return call_voidarg_function(purify_clear_messages, self, args);\r | |
435 | }\r | |
436 | static PyObject*\r | |
437 | pure_purify_clear_new_messages(PyObject *self, PyObject *args)\r | |
438 | {\r | |
439 | return call_voidarg_function(purify_clear_new_messages, self, args);\r | |
440 | }\r | |
441 | static PyObject*\r | |
442 | pure_purify_start_batch(PyObject *self, PyObject *args)\r | |
443 | {\r | |
444 | return call_voidarg_function(purify_start_batch, self, args);\r | |
445 | }\r | |
446 | static PyObject*\r | |
447 | pure_purify_start_batch_show_first(PyObject *self, PyObject *args)\r | |
448 | {\r | |
449 | return call_voidarg_function(purify_start_batch_show_first,\r | |
450 | self, args);\r | |
451 | }\r | |
452 | static PyObject*\r | |
453 | pure_purify_stop_batch(PyObject *self, PyObject *args)\r | |
454 | {\r | |
455 | return call_voidarg_function(purify_stop_batch, self, args);\r | |
456 | }\r | |
457 | static PyObject*\r | |
458 | pure_purify_name_thread(PyObject *self, PyObject *args)\r | |
459 | {\r | |
460 | /* can't strictly use call_stringarg_function since\r | |
461 | * purify_name_thread takes a const char*, not a char*\r | |
462 | */\r | |
463 | int status;\r | |
464 | char* stringarg;\r | |
465 | \r | |
466 | if (!PyArg_ParseTuple(args, "s:purify_name_thread", &stringarg))\r | |
467 | return NULL;\r | |
468 | \r | |
469 | status = purify_name_thread(stringarg);\r | |
470 | return Py_BuildValue("i", status);\r | |
471 | }\r | |
472 | static PyObject*\r | |
473 | pure_purify_watch(PyObject *self, PyObject *args)\r | |
474 | {\r | |
475 | return call_intasaddr_function(purify_watch, self, args);\r | |
476 | }\r | |
477 | static PyObject*\r | |
478 | pure_purify_watch_1(PyObject *self, PyObject *args)\r | |
479 | {\r | |
480 | return call_intasaddr_function(purify_watch_1, self, args);\r | |
481 | }\r | |
482 | static PyObject*\r | |
483 | pure_purify_watch_2(PyObject *self, PyObject *args)\r | |
484 | {\r | |
485 | return call_intasaddr_function(purify_watch_2, self, args);\r | |
486 | }\r | |
487 | static PyObject*\r | |
488 | pure_purify_watch_4(PyObject *self, PyObject *args)\r | |
489 | {\r | |
490 | return call_intasaddr_function(purify_watch_4, self, args);\r | |
491 | }\r | |
492 | static PyObject*\r | |
493 | pure_purify_watch_8(PyObject *self, PyObject *args)\r | |
494 | {\r | |
495 | return call_intasaddr_function(purify_watch_8, self, args);\r | |
496 | }\r | |
497 | static PyObject*\r | |
498 | pure_purify_watch_w_1(PyObject *self, PyObject *args)\r | |
499 | {\r | |
500 | return call_intasaddr_function(purify_watch_w_1, self, args);\r | |
501 | }\r | |
502 | static PyObject*\r | |
503 | pure_purify_watch_w_2(PyObject *self, PyObject *args)\r | |
504 | {\r | |
505 | return call_intasaddr_function(purify_watch_w_2, self, args);\r | |
506 | }\r | |
507 | static PyObject*\r | |
508 | pure_purify_watch_w_4(PyObject *self, PyObject *args)\r | |
509 | {\r | |
510 | return call_intasaddr_function(purify_watch_w_4, self, args);\r | |
511 | }\r | |
512 | static PyObject*\r | |
513 | pure_purify_watch_w_8(PyObject *self, PyObject *args)\r | |
514 | {\r | |
515 | return call_intasaddr_function(purify_watch_w_8, self, args);\r | |
516 | }\r | |
517 | static PyObject*\r | |
518 | pure_purify_watch_r_1(PyObject *self, PyObject *args)\r | |
519 | {\r | |
520 | return call_intasaddr_function(purify_watch_r_1, self, args);\r | |
521 | }\r | |
522 | static PyObject*\r | |
523 | pure_purify_watch_r_2(PyObject *self, PyObject *args)\r | |
524 | {\r | |
525 | return call_intasaddr_function(purify_watch_r_2, self, args);\r | |
526 | }\r | |
527 | static PyObject*\r | |
528 | pure_purify_watch_r_4(PyObject *self, PyObject *args)\r | |
529 | {\r | |
530 | return call_intasaddr_function(purify_watch_r_4, self, args);\r | |
531 | }\r | |
532 | static PyObject*\r | |
533 | pure_purify_watch_r_8(PyObject *self, PyObject *args)\r | |
534 | {\r | |
535 | return call_intasaddr_function(purify_watch_r_8, self, args);\r | |
536 | }\r | |
537 | static PyObject*\r | |
538 | pure_purify_watch_rw_1(PyObject *self, PyObject *args)\r | |
539 | {\r | |
540 | return call_intasaddr_function(purify_watch_rw_1, self, args);\r | |
541 | }\r | |
542 | static PyObject*\r | |
543 | pure_purify_watch_rw_2(PyObject *self, PyObject *args)\r | |
544 | {\r | |
545 | return call_intasaddr_function(purify_watch_rw_2, self, args);\r | |
546 | }\r | |
547 | static PyObject*\r | |
548 | pure_purify_watch_rw_4(PyObject *self, PyObject *args)\r | |
549 | {\r | |
550 | return call_intasaddr_function(purify_watch_rw_4, self, args);\r | |
551 | }\r | |
552 | static PyObject*\r | |
553 | pure_purify_watch_rw_8(PyObject *self, PyObject *args)\r | |
554 | {\r | |
555 | return call_intasaddr_function(purify_watch_rw_8, self, args);\r | |
556 | }\r | |
557 | \r | |
558 | static PyObject*\r | |
559 | pure_purify_watch_n(PyObject *self, PyObject *args)\r | |
560 | {\r | |
561 | long addrrep;\r | |
562 | unsigned int size;\r | |
563 | char* type;\r | |
564 | int status;\r | |
565 | \r | |
566 | if (!PyArg_ParseTuple(args, "lis:purify_watch_n", &addrrep, &size, &type))\r | |
567 | return NULL;\r | |
568 | \r | |
569 | status = purify_watch_n((char*)addrrep, size, type);\r | |
570 | return Py_BuildValue("i", status);\r | |
571 | }\r | |
572 | \r | |
573 | static PyObject*\r | |
574 | pure_purify_watch_info(PyObject *self, PyObject *args)\r | |
575 | {\r | |
576 | return call_voidarg_function(purify_watch_info, self, args);\r | |
577 | }\r | |
578 | \r | |
579 | static PyObject*\r | |
580 | pure_purify_watch_remove(PyObject *self, PyObject *args)\r | |
581 | {\r | |
582 | int watchno;\r | |
583 | int status;\r | |
584 | \r | |
585 | if (!PyArg_ParseTuple(args, "i:purify_watch_remove", &watchno))\r | |
586 | return NULL;\r | |
587 | \r | |
588 | status = purify_watch_remove(watchno);\r | |
589 | return Py_BuildValue("i", status);\r | |
590 | }\r | |
591 | \r | |
592 | static PyObject*\r | |
593 | pure_purify_watch_remove_all(PyObject *self, PyObject *args)\r | |
594 | {\r | |
595 | return call_voidarg_function(purify_watch_remove_all, self, args);\r | |
596 | }\r | |
597 | static PyObject*\r | |
598 | pure_purify_describe(PyObject *self, PyObject *args)\r | |
599 | {\r | |
600 | long addrrep;\r | |
601 | char* rtn;\r | |
602 | \r | |
603 | if (!PyArg_ParseTuple(args, "l:purify_describe", &addrrep))\r | |
604 | return NULL;\r | |
605 | \r | |
606 | rtn = purify_describe((char*)addrrep);\r | |
607 | return Py_BuildValue("l", (long)rtn);\r | |
608 | }\r | |
609 | \r | |
610 | static PyObject*\r | |
611 | pure_purify_what_colors(PyObject *self, PyObject *args)\r | |
612 | {\r | |
613 | long addrrep;\r | |
614 | unsigned int size;\r | |
615 | int status;\r | |
616 | \r | |
617 | if (!PyArg_ParseTuple(args, "li:purify_what_colors", &addrrep, &size))\r | |
618 | return NULL;\r | |
619 | \r | |
620 | status = purify_what_colors((char*)addrrep, size);\r | |
621 | return Py_BuildValue("i", status);\r | |
622 | }\r | |
623 | \r | |
624 | static PyObject*\r | |
625 | pure_purify_is_running(PyObject *self, PyObject *args)\r | |
626 | {\r | |
627 | return call_voidarg_function(purify_is_running, self, args);\r | |
628 | }\r | |
629 | \r | |
630 | static PyObject*\r | |
631 | pure_purify_assert_is_readable(PyObject *self, PyObject *args)\r | |
632 | {\r | |
633 | return call_stringandint_function(purify_assert_is_readable,\r | |
634 | self, args);\r | |
635 | }\r | |
636 | static PyObject*\r | |
637 | pure_purify_assert_is_writable(PyObject *self, PyObject *args)\r | |
638 | {\r | |
639 | return call_stringandint_function(purify_assert_is_writable,\r | |
640 | self, args);\r | |
641 | }\r | |
642 | \r | |
643 | #if HAS_PURIFY_EXIT\r | |
644 | \r | |
645 | /* I wish I could include this, but I can't. See the notes at the top of\r | |
646 | * the file.\r | |
647 | */\r | |
648 | \r | |
649 | static PyObject*\r | |
650 | pure_purify_exit(PyObject *self, PyObject *args)\r | |
651 | {\r | |
652 | int status;\r | |
653 | \r | |
654 | if (!PyArg_ParseTuple(args, "i:purify_exit", &status))\r | |
655 | return NULL;\r | |
656 | \r | |
657 | /* purify_exit doesn't always act like exit(). See the manual */\r | |
658 | purify_exit(status);\r | |
659 | Py_INCREF(Py_None);\r | |
660 | return Py_None;\r | |
661 | }\r | |
662 | #endif /* HAS_PURIFY_EXIT */\r | |
663 | \r | |
664 | #endif /* PURIFY_H */\r | |
665 | \r | |
666 | \r | |
667 | \r | |
668 | /* Quantify functions\r | |
669 | *\r | |
670 | * N.B. Some of these functions are only described in the quantify.h file,\r | |
671 | * not in the version of the hardcopy manual that I had. If you're not\r | |
672 | * sure what some of these do, check the header file, it is documented\r | |
673 | * fairly well.\r | |
674 | *\r | |
675 | * None of the custom dynamic loader functions are exported.\r | |
676 | *\r | |
677 | */\r | |
678 | #ifdef QUANTIFY_H\r | |
679 | \r | |
680 | static PyObject*\r | |
681 | pure_quantify_is_running(PyObject *self, PyObject *args)\r | |
682 | {\r | |
683 | return call_voidarg_function(quantify_is_running, self, args);\r | |
684 | }\r | |
685 | static PyObject*\r | |
686 | pure_quantify_help(PyObject *self, PyObject *args)\r | |
687 | {\r | |
688 | return call_voidarg_function(quantify_help, self, args);\r | |
689 | }\r | |
690 | static PyObject*\r | |
691 | pure_quantify_print_recording_state(PyObject *self, PyObject *args)\r | |
692 | {\r | |
693 | return call_voidarg_function(quantify_print_recording_state,\r | |
694 | self, args);\r | |
695 | }\r | |
696 | static PyObject*\r | |
697 | pure_quantify_start_recording_data(PyObject *self, PyObject *args)\r | |
698 | {\r | |
699 | return call_voidarg_function(quantify_start_recording_data,\r | |
700 | self, args);\r | |
701 | }\r | |
702 | static PyObject*\r | |
703 | pure_quantify_stop_recording_data(PyObject *self, PyObject *args)\r | |
704 | {\r | |
705 | return call_voidarg_function(quantify_stop_recording_data, self, args);\r | |
706 | }\r | |
707 | static PyObject*\r | |
708 | pure_quantify_is_recording_data(PyObject *self, PyObject *args)\r | |
709 | {\r | |
710 | return call_voidarg_function(quantify_is_recording_data, self, args);\r | |
711 | }\r | |
712 | static PyObject*\r | |
713 | pure_quantify_start_recording_system_calls(PyObject *self, PyObject *args)\r | |
714 | {\r | |
715 | return call_voidarg_function(quantify_start_recording_system_calls,\r | |
716 | self, args);\r | |
717 | }\r | |
718 | static PyObject*\r | |
719 | pure_quantify_stop_recording_system_calls(PyObject *self, PyObject *args)\r | |
720 | {\r | |
721 | return call_voidarg_function(quantify_stop_recording_system_calls,\r | |
722 | self, args);\r | |
723 | }\r | |
724 | static PyObject*\r | |
725 | pure_quantify_is_recording_system_calls(PyObject *self, PyObject *args)\r | |
726 | {\r | |
727 | return call_voidarg_function(quantify_is_recording_system_calls,\r | |
728 | self, args);\r | |
729 | }\r | |
730 | static PyObject*\r | |
731 | pure_quantify_start_recording_system_call(PyObject *self, PyObject *args)\r | |
732 | {\r | |
733 | return call_stringorint_function(quantify_start_recording_system_call,\r | |
734 | self, args);\r | |
735 | }\r | |
736 | static PyObject*\r | |
737 | pure_quantify_stop_recording_system_call(PyObject *self, PyObject *args)\r | |
738 | {\r | |
739 | return call_stringorint_function(quantify_stop_recording_system_call,\r | |
740 | self, args);\r | |
741 | }\r | |
742 | static PyObject*\r | |
743 | pure_quantify_is_recording_system_call(PyObject *self, PyObject *args)\r | |
744 | {\r | |
745 | return call_stringorint_function(quantify_is_recording_system_call,\r | |
746 | self, args);\r | |
747 | }\r | |
748 | static PyObject*\r | |
749 | pure_quantify_start_recording_dynamic_library_data(PyObject *self, PyObject *args)\r | |
750 | {\r | |
751 | return call_voidarg_function(\r | |
752 | quantify_start_recording_dynamic_library_data,\r | |
753 | self, args);\r | |
754 | }\r | |
755 | static PyObject*\r | |
756 | pure_quantify_stop_recording_dynamic_library_data(PyObject *self, PyObject *args)\r | |
757 | {\r | |
758 | return call_voidarg_function(\r | |
759 | quantify_stop_recording_dynamic_library_data,\r | |
760 | self, args);\r | |
761 | }\r | |
762 | static PyObject*\r | |
763 | pure_quantify_is_recording_dynamic_library_data(PyObject *self, PyObject *args)\r | |
764 | {\r | |
765 | return call_voidarg_function(\r | |
766 | quantify_is_recording_dynamic_library_data,\r | |
767 | self, args);\r | |
768 | }\r | |
769 | static PyObject*\r | |
770 | pure_quantify_start_recording_register_window_traps(PyObject *self, PyObject *args)\r | |
771 | {\r | |
772 | return call_voidarg_function(\r | |
773 | quantify_start_recording_register_window_traps,\r | |
774 | self, args);\r | |
775 | }\r | |
776 | static PyObject*\r | |
777 | pure_quantify_stop_recording_register_window_traps(PyObject *self, PyObject *args)\r | |
778 | {\r | |
779 | return call_voidarg_function(\r | |
780 | quantify_stop_recording_register_window_traps,\r | |
781 | self, args);\r | |
782 | }\r | |
783 | static PyObject*\r | |
784 | pure_quantify_is_recording_register_window_traps(PyObject *self, PyObject *args)\r | |
785 | {\r | |
786 | return call_voidarg_function(\r | |
787 | quantify_is_recording_register_window_traps,\r | |
788 | self, args);\r | |
789 | }\r | |
790 | static PyObject*\r | |
791 | pure_quantify_disable_recording_data(PyObject *self, PyObject *args)\r | |
792 | {\r | |
793 | return call_voidarg_function(quantify_disable_recording_data,\r | |
794 | self, args);\r | |
795 | }\r | |
796 | static PyObject*\r | |
797 | pure_quantify_clear_data(PyObject *self, PyObject *args)\r | |
798 | {\r | |
799 | return call_voidarg_function(quantify_clear_data, self, args);\r | |
800 | }\r | |
801 | static PyObject*\r | |
802 | pure_quantify_save_data(PyObject *self, PyObject *args)\r | |
803 | {\r | |
804 | return call_voidarg_function(quantify_save_data, self, args);\r | |
805 | }\r | |
806 | static PyObject*\r | |
807 | pure_quantify_save_data_to_file(PyObject *self, PyObject *args)\r | |
808 | {\r | |
809 | return call_stringarg_function(quantify_save_data_to_file, self, args);\r | |
810 | }\r | |
811 | static PyObject*\r | |
812 | pure_quantify_add_annotation(PyObject *self, PyObject *args)\r | |
813 | {\r | |
814 | return call_stringarg_function(quantify_add_annotation, self, args);\r | |
815 | }\r | |
816 | \r | |
817 | #endif /* QUANTIFY_H */\r | |
818 | \r | |
819 | \r | |
820 | \r | |
821 | /* external interface\r | |
822 | */\r | |
823 | static struct PyMethodDef\r | |
824 | pure_methods[] = {\r | |
825 | #ifdef COMMON_PURE_FUNCTIONS\r | |
826 | {"pure_logfile_printf", pure_pure_logfile_printf, METH_VARARGS},\r | |
827 | {"pure_printf", pure_pure_printf, METH_VARARGS},\r | |
828 | {"pure_printf_with_banner", pure_pure_printf_with_banner, METH_VARARGS},\r | |
829 | #endif /* COMMON_PURE_FUNCTIONS */\r | |
830 | #ifdef PURIFY_H\r | |
831 | {"purify_all_inuse", pure_purify_all_inuse, METH_VARARGS},\r | |
832 | {"purify_all_leaks", pure_purify_all_leaks, METH_VARARGS},\r | |
833 | {"purify_new_inuse", pure_purify_new_inuse, METH_VARARGS},\r | |
834 | {"purify_new_leaks", pure_purify_new_leaks, METH_VARARGS},\r | |
835 | {"purify_clear_inuse", pure_purify_clear_inuse, METH_VARARGS},\r | |
836 | {"purify_clear_leaks", pure_purify_clear_leaks, METH_VARARGS},\r | |
837 | {"purify_all_fds_inuse", pure_purify_all_fds_inuse, METH_VARARGS},\r | |
838 | {"purify_new_fds_inuse", pure_purify_new_fds_inuse, METH_VARARGS},\r | |
839 | /* see purify.h */\r | |
840 | {"purify_logfile_printf", pure_pure_logfile_printf, METH_VARARGS},\r | |
841 | {"purify_printf", pure_pure_printf, METH_VARARGS},\r | |
842 | {"purify_printf_with_banner", pure_pure_printf_with_banner, METH_VARARGS},\r | |
843 | /**/\r | |
844 | {"purify_printf_with_call_chain", pure_purify_printf_with_call_chain, METH_VARARGS},\r | |
845 | {"purify_set_pool_id", pure_purify_set_pool_id, METH_VARARGS},\r | |
846 | {"purify_get_pool_id", pure_purify_get_pool_id, METH_VARARGS},\r | |
847 | {"purify_set_user_data", pure_purify_set_user_data, METH_VARARGS},\r | |
848 | {"purify_get_user_data", pure_purify_get_user_data, METH_VARARGS},\r | |
849 | {"purify_map_pool", pure_purify_map_pool, METH_VARARGS},\r | |
850 | {"purify_map_pool_id", pure_purify_map_pool_id, METH_VARARGS},\r | |
851 | {"purify_new_messages", pure_purify_new_messages, METH_VARARGS},\r | |
852 | {"purify_all_messages", pure_purify_all_messages, METH_VARARGS},\r | |
853 | {"purify_clear_messages", pure_purify_clear_messages, METH_VARARGS},\r | |
854 | {"purify_clear_new_messages", pure_purify_clear_new_messages, METH_VARARGS},\r | |
855 | {"purify_start_batch", pure_purify_start_batch, METH_VARARGS},\r | |
856 | {"purify_start_batch_show_first", pure_purify_start_batch_show_first, METH_VARARGS},\r | |
857 | {"purify_stop_batch", pure_purify_stop_batch, METH_VARARGS},\r | |
858 | {"purify_name_thread", pure_purify_name_thread, METH_VARARGS},\r | |
859 | {"purify_watch", pure_purify_watch, METH_VARARGS},\r | |
860 | {"purify_watch_1", pure_purify_watch_1, METH_VARARGS},\r | |
861 | {"purify_watch_2", pure_purify_watch_2, METH_VARARGS},\r | |
862 | {"purify_watch_4", pure_purify_watch_4, METH_VARARGS},\r | |
863 | {"purify_watch_8", pure_purify_watch_8, METH_VARARGS},\r | |
864 | {"purify_watch_w_1", pure_purify_watch_w_1, METH_VARARGS},\r | |
865 | {"purify_watch_w_2", pure_purify_watch_w_2, METH_VARARGS},\r | |
866 | {"purify_watch_w_4", pure_purify_watch_w_4, METH_VARARGS},\r | |
867 | {"purify_watch_w_8", pure_purify_watch_w_8, METH_VARARGS},\r | |
868 | {"purify_watch_r_1", pure_purify_watch_r_1, METH_VARARGS},\r | |
869 | {"purify_watch_r_2", pure_purify_watch_r_2, METH_VARARGS},\r | |
870 | {"purify_watch_r_4", pure_purify_watch_r_4, METH_VARARGS},\r | |
871 | {"purify_watch_r_8", pure_purify_watch_r_8, METH_VARARGS},\r | |
872 | {"purify_watch_rw_1", pure_purify_watch_rw_1, METH_VARARGS},\r | |
873 | {"purify_watch_rw_2", pure_purify_watch_rw_2, METH_VARARGS},\r | |
874 | {"purify_watch_rw_4", pure_purify_watch_rw_4, METH_VARARGS},\r | |
875 | {"purify_watch_rw_8", pure_purify_watch_rw_8, METH_VARARGS},\r | |
876 | {"purify_watch_n", pure_purify_watch_n, METH_VARARGS},\r | |
877 | {"purify_watch_info", pure_purify_watch_info, METH_VARARGS},\r | |
878 | {"purify_watch_remove", pure_purify_watch_remove, METH_VARARGS},\r | |
879 | {"purify_watch_remove_all", pure_purify_watch_remove_all, METH_VARARGS},\r | |
880 | {"purify_describe", pure_purify_describe, METH_VARARGS},\r | |
881 | {"purify_what_colors", pure_purify_what_colors, METH_VARARGS},\r | |
882 | {"purify_is_running", pure_purify_is_running, METH_VARARGS},\r | |
883 | {"purify_assert_is_readable", pure_purify_assert_is_readable, METH_VARARGS},\r | |
884 | {"purify_assert_is_writable", pure_purify_assert_is_writable, METH_VARARGS},\r | |
885 | #if HAS_PURIFY_EXIT\r | |
886 | /* I wish I could include this, but I can't. See the notes at the\r | |
887 | * top of the file.\r | |
888 | */\r | |
889 | {"purify_exit", pure_purify_exit, METH_VARARGS},\r | |
890 | #endif /* HAS_PURIFY_EXIT */\r | |
891 | #endif /* PURIFY_H */\r | |
892 | #ifdef QUANTIFY_H\r | |
893 | {"quantify_is_running", pure_quantify_is_running, METH_VARARGS},\r | |
894 | {"quantify_help", pure_quantify_help, METH_VARARGS},\r | |
895 | {"quantify_print_recording_state", pure_quantify_print_recording_state, METH_VARARGS},\r | |
896 | {"quantify_start_recording_data", pure_quantify_start_recording_data, METH_VARARGS},\r | |
897 | {"quantify_stop_recording_data", pure_quantify_stop_recording_data, METH_VARARGS},\r | |
898 | {"quantify_is_recording_data", pure_quantify_is_recording_data, METH_VARARGS},\r | |
899 | {"quantify_start_recording_system_calls",\r | |
900 | pure_quantify_start_recording_system_calls, METH_VARARGS},\r | |
901 | {"quantify_stop_recording_system_calls",\r | |
902 | pure_quantify_stop_recording_system_calls, METH_VARARGS},\r | |
903 | {"quantify_is_recording_system_calls",\r | |
904 | pure_quantify_is_recording_system_calls, METH_VARARGS},\r | |
905 | {"quantify_start_recording_system_call",\r | |
906 | pure_quantify_start_recording_system_call, METH_VARARGS},\r | |
907 | {"quantify_stop_recording_system_call",\r | |
908 | pure_quantify_stop_recording_system_call, METH_VARARGS},\r | |
909 | {"quantify_is_recording_system_call",\r | |
910 | pure_quantify_is_recording_system_call, METH_VARARGS},\r | |
911 | {"quantify_start_recording_dynamic_library_data",\r | |
912 | pure_quantify_start_recording_dynamic_library_data, METH_VARARGS},\r | |
913 | {"quantify_stop_recording_dynamic_library_data",\r | |
914 | pure_quantify_stop_recording_dynamic_library_data, METH_VARARGS},\r | |
915 | {"quantify_is_recording_dynamic_library_data",\r | |
916 | pure_quantify_is_recording_dynamic_library_data, METH_VARARGS},\r | |
917 | {"quantify_start_recording_register_window_traps",\r | |
918 | pure_quantify_start_recording_register_window_traps, METH_VARARGS},\r | |
919 | {"quantify_stop_recording_register_window_traps",\r | |
920 | pure_quantify_stop_recording_register_window_traps, METH_VARARGS},\r | |
921 | {"quantify_is_recording_register_window_traps",\r | |
922 | pure_quantify_is_recording_register_window_traps, METH_VARARGS},\r | |
923 | {"quantify_disable_recording_data",\r | |
924 | pure_quantify_disable_recording_data, METH_VARARGS},\r | |
925 | {"quantify_clear_data", pure_quantify_clear_data, METH_VARARGS},\r | |
926 | {"quantify_save_data", pure_quantify_save_data, METH_VARARGS},\r | |
927 | {"quantify_save_data_to_file", pure_quantify_save_data_to_file, METH_VARARGS},\r | |
928 | {"quantify_add_annotation", pure_quantify_add_annotation, METH_VARARGS},\r | |
929 | #endif /* QUANTIFY_H */\r | |
930 | {NULL, NULL} /* sentinel */\r | |
931 | };\r | |
932 | \r | |
933 | \r | |
934 | \r | |
935 | static void\r | |
936 | ins(d, name, val)\r | |
937 | PyObject *d;\r | |
938 | char* name;\r | |
939 | long val;\r | |
940 | {\r | |
941 | PyObject *v = PyInt_FromLong(val);\r | |
942 | if (v) {\r | |
943 | (void)PyDict_SetItemString(d, name, v);\r | |
944 | Py_DECREF(v);\r | |
945 | }\r | |
946 | }\r | |
947 | \r | |
948 | \r | |
949 | void\r | |
950 | initpure()\r | |
951 | {\r | |
952 | PyObject *m, *d;\r | |
953 | \r | |
954 | if (PyErr_WarnPy3k("the pure module has been removed in "\r | |
955 | "Python 3.0", 2) < 0)\r | |
956 | return;\r | |
957 | \r | |
958 | m = Py_InitModule("pure", pure_methods);\r | |
959 | if (m == NULL)\r | |
960 | return;\r | |
961 | d = PyModule_GetDict(m);\r | |
962 | \r | |
963 | /* this is bogus because we should be able to find this information\r | |
964 | * out from the header files. Pure's current versions don't\r | |
965 | * include this information!\r | |
966 | */\r | |
967 | #ifdef PURE_PURIFY_VERSION\r | |
968 | ins(d, "PURIFY_VERSION", PURE_PURIFY_VERSION);\r | |
969 | #else\r | |
970 | PyDict_SetItemString(d, "PURIFY_VERSION", Py_None);\r | |
971 | #endif\r | |
972 | \r | |
973 | /* these aren't terribly useful because purify_exit() isn't\r | |
974 | * exported correctly. See the note at the top of the file.\r | |
975 | */\r | |
976 | #ifdef PURIFY_EXIT_ERRORS\r | |
977 | ins(d, "PURIFY_EXIT_ERRORS", PURIFY_EXIT_ERRORS);\r | |
978 | #endif\r | |
979 | #ifdef PURIFY_EXIT_LEAKS\r | |
980 | ins(d, "PURIFY_EXIT_LEAKS", PURIFY_EXIT_LEAKS);\r | |
981 | #endif\r | |
982 | #ifdef PURIFY_EXIT_PLEAKS\r | |
983 | ins(d, "PURIFY_EXIT_PLEAKS", PURIFY_EXIT_PLEAKS);\r | |
984 | #endif\r | |
985 | \r | |
986 | \r | |
987 | #ifdef PURE_QUANTIFY_VERSION\r | |
988 | ins(d, "QUANTIFY_VERSION", PURE_QUANTIFY_VERSION);\r | |
989 | #else\r | |
990 | PyDict_SetItemString(d, "QUANTIFY_VERSION", Py_None);\r | |
991 | #endif\r | |
992 | }\r |