/Modules/puremodule.c

http://unladen-swallow.googlecode.com/ · C · 992 lines · 755 code · 96 blank · 141 comment · 32 complexity · b9ac993dd4cad6f71aaea3a8a4bb72aa MD5 · raw file

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