puremodule.c 29.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/* This module exports the C API to such Pure Software Inc. (tm) (now
 * called Pure Atria Corporation) products as Purify (tm) and Quantify
 * (tm).  Other packages could be added, but I didn't have those products
 * and thus lack the API documentation.
 *
 * Currently supported: Quantify 2.x, Purify 3.x
 *
 * You need to decide which products you want to incorporate into the
 * module when you compile this file.  The way to do this is to edit
 * <Python>/Modules/Setup to pass the appropriate flags to the compiler.
 * -DWITH_PURIFY compiles in the Purify support, and -DWITH_QUANTIFY
 * compiles in the Quantify support.  -DWITH_ALL_PURE compiles in both.
 * You can also build a Purify'd or Quantify'd interpreter by passing in
 * the LINKCC variable to make.  E.g. if you want to build a Purify'd
 * interpreter and are using gcc, build Python with this command:
 *
 * make LINKCC='purify gcc'
 *
 * It would be nice (and probably easy) to provide this file as a shared
 * library, however since it doesn't appear that Pure gives us shared
 * libraries of the stubs, it doesn't really matter.  For now, you have to
 * link this file in statically.
 *
 * Major bogosity.  The purify.h header file exports purify_exit(), but
 * guess what?  It is not defined in the libpurify_stubs.a file!  I tried
 * to fake one here, hoping the Pure linker would Do The Right Thing when
 * instrumented for Purify, but it doesn't seem to, so I don't export
 * purify_exit() to the Python layer.  In Python you should raise a
 * SystemExit exception anyway.
 *
 * The actual purify.h and quantify.h files which embody the APIs are
 * copyrighted by Pure Software, Inc. and are only attainable through them.
 * This module assumes you have legally installed licenses of their
 * software.  Contact them on the Web via <http://www.pureatria.com/>
 *
 * Author: Barry Warsaw <bwarsaw@python.org>
 *                      <bwarsaw@cnri.reston.va.us>
 */

#include "Python.h"

#if defined(WITH_PURIFY) || defined(WITH_ALL_PURE)
#    include <purify.h>
#    define HAS_PURIFY_EXIT 0                /* See note at top of file */
#    define PURE_PURIFY_VERSION 3            /* not provided by purify.h */
#endif
#if defined(WITH_QUANTIFY) || defined(WITH_ALL_PURE)
#    include <quantify.h>
#    define PURE_QUANTIFY_VERSION 2          /* not provided by quantify.h */
#endif
#if defined(PURIFY_H) || defined(QUANTIFY_H)
#    define COMMON_PURE_FUNCTIONS
#endif /* PURIFY_H || QUANTIFY_H */

typedef int (*VoidArgFunc)(void);
typedef int (*StringArgFunc)(char*);
typedef int (*PrintfishFunc)(const char*, ...);
typedef int (*StringIntArgFunc)(const char*, int);



static PyObject*
63
call_voidarg_function(VoidArgFunc func, PyObject *self, PyObject *args)
64 65 66 67 68 69 70 71 72 73 74
{
	int status;

	if (!PyArg_ParseTuple(args, ""))
		return NULL;

	status = func();
	return Py_BuildValue("i", status);
}

static PyObject*
75
call_stringarg_function(StringArgFunc func, PyObject *self, PyObject *args)
76 77 78 79 80 81 82 83 84 85 86 87
{
	int status;
	char* stringarg;

	if (!PyArg_ParseTuple(args, "s", &stringarg))
		return NULL;

	status = func(stringarg);
	return Py_BuildValue("i", status);
}

static PyObject*
88
call_stringorint_function(StringArgFunc func, PyObject *self, PyObject *args)
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
{
	int status;
	int intarg;
	char* stringarg;

        /* according to the quantify.h file, the argument to
         * quantify_*_recording_system_call can be an integer or a string,
	 * but the functions are prototyped as taking a single char*
	 * argument. Yikes!
         */
	if (PyArg_ParseTuple(args, "i", &intarg))
		/* func is prototyped as int(*)(char*)
		 * better shut up the compiler
		 */
		status = func((char*)intarg);

	else {
		PyErr_Clear();
		if (!PyArg_ParseTuple(args, "s", &stringarg))
			return NULL;
		else
			status = func(stringarg);
	}
	return Py_BuildValue("i", status);
}

static PyObject*
116
call_printfish_function(PrintfishFunc func, PyObject *self, PyObject *args)
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
{
	/* we support the printf() style vararg functions by requiring the
         * formatting be done in Python.  At the C level we pass just a string
         * to the printf() style function.
         */
	int status;
	char* argstring;

	if (!PyArg_ParseTuple(args, "s", &argstring))
		return NULL;

	status = func("%s", argstring);
	return Py_BuildValue("i", status);
}

static PyObject*
133
call_intasaddr_function(StringArgFunc func, PyObject *self, PyObject *args)
134 135 136 137 138 139 140 141 142 143 144 145
{
	long memrep;
	int id;

	if (!PyArg_ParseTuple(args, "l", &memrep))
		return NULL;

	id = func((char*)memrep);
	return Py_BuildValue("i", id);
}

static PyObject*
146 147
call_stringandint_function(StringIntArgFunc func, PyObject *self,
			   PyObject *args)
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
{
	long srcrep;
	int size;
	int status;

	if (!PyArg_ParseTuple(args, "li", &srcrep, &size))
		return NULL;

	status = func((char*)srcrep, size);
	return Py_BuildValue("i", status);
}



/* functions common to all products
 *
 * N.B. These printf() style functions are a bit of a kludge.  Since the
 * API doesn't provide vprintf versions of them, we can't call them
 * directly.  They don't support all the standard printf % modifiers
 * anyway.  The way to use these is to use Python's % string operator to do
 * the formatting.  By the time these functions get the thing to print,
 * it's already a string, and they just use "%s" as the format string.
 */

#ifdef COMMON_PURE_FUNCTIONS

static PyObject*
pure_pure_logfile_printf(PyObject* self, PyObject* args)
{
	return call_printfish_function(pure_logfile_printf, self, args);
}

static PyObject*
pure_pure_printf(PyObject* self, PyObject* args)
{
	return call_printfish_function(pure_printf, self, args);
}

static PyObject*
pure_pure_printf_with_banner(PyObject* self, PyObject* args)
{
	return call_printfish_function(pure_printf_with_banner, self, args);
}


#endif /* COMMON_PURE_FUNCTIONS */



/* Purify functions
 *
 * N.B. There are some interfaces described in the purify.h file that are
 * not described in the manual.
 *
 * Unsigned longs purify_report_{address,number,type,result} are not
 * accessible from the Python layer since they seem mostly useful when
 * purify_stop_here() is called by the (C) debugger.  The same is true of
 * the purify_stop_here_internal() function so it isn't exported either.
 * And purify_stop_here() should never be called directly.
 *
 * The header file says purify_{new,all,clear_new}_reports() are obsolete
 * so they aren't exported.
 *
 * None of the custom dynamic loader functions are exported.
 *
 * purify_unsafe_memcpy() isn't exported.
 *
 * purify_{start,size}_of_block() aren't exported.
 *
 * The manual that I have says that the prototype for the second argument
 * to purify_map_pool is:
 *
 *    void (*fn)(char*)
 *
 * but the purify.h file declares it as:
 *
 *    void (*fn)(char*, int, void*)
 *
 * and does not explain what the other arguments are for.  I support the
 * latter but I don't know if I do it right or usefully.
 *
 * The header file says that purify_describe() returns a char* which is the
 * pointer passed to it.  The manual says it returns an int, but I believe
 * that is a typo.
 */
#ifdef PURIFY_H

static PyObject*
236
pure_purify_all_inuse(PyObject *self, PyObject *args)
237 238 239 240
{
	return call_voidarg_function(purify_all_inuse, self, args);
}
static PyObject*
241
pure_purify_all_leaks(PyObject *self, PyObject *args)
242 243 244 245
{
	return call_voidarg_function(purify_all_leaks, self, args);
}
static PyObject*
246
pure_purify_new_inuse(PyObject *self, PyObject *args)
247 248 249 250
{
	return call_voidarg_function(purify_new_inuse, self, args);
}
static PyObject*
251
pure_purify_new_leaks(PyObject *self, PyObject *args)
252 253 254 255
{
	return call_voidarg_function(purify_new_leaks, self, args);
}
static PyObject*
256
pure_purify_clear_inuse(PyObject *self, PyObject *args)
257 258 259 260
{
	return call_voidarg_function(purify_clear_inuse, self, args);
}
static PyObject*
261
pure_purify_clear_leaks(PyObject *self, PyObject *args)
262 263 264 265
{
	return call_voidarg_function(purify_clear_leaks, self, args);
}
static PyObject*
266
pure_purify_all_fds_inuse(PyObject *self, PyObject *args)
267 268 269 270
{
	return call_voidarg_function(purify_all_fds_inuse, self, args);
}
static PyObject*
271
pure_purify_new_fds_inuse(PyObject *self, PyObject *args)
272 273 274 275
{
	return call_voidarg_function(purify_new_fds_inuse, self, args);
}
static PyObject*
276
pure_purify_printf_with_call_chain(PyObject *self, PyObject *args)
277 278 279 280 281
{
	return call_printfish_function(purify_printf_with_call_chain,
				       self, args);
}
static PyObject*
282
pure_purify_set_pool_id(PyObject *self, PyObject *args)
283 284 285 286
{
	long memrep;
	int id;

287
	if (!PyArg_ParseTuple(args, "li:purify_set_pool_id", &memrep, &id))
288 289 290 291 292 293 294
		return NULL;

	purify_set_pool_id((char*)memrep, id);
	Py_INCREF(Py_None);
	return Py_None;
}
static PyObject*
295
pure_purify_get_pool_id(PyObject *self, PyObject *args)
296 297 298 299
{
	return call_intasaddr_function(purify_get_pool_id, self, args);
}
static PyObject*
300
pure_purify_set_user_data(PyObject *self, PyObject *args)
301 302 303 304
{
	long memrep;
	long datarep;

305
	if (!PyArg_ParseTuple(args, "ll:purify_set_user_data", &memrep, &datarep))
306 307 308 309 310 311 312
		return NULL;

	purify_set_user_data((char*)memrep, (void*)datarep);
	Py_INCREF(Py_None);
	return Py_None;
}
static PyObject*
313
pure_purify_get_user_data(PyObject *self, PyObject *args)
314 315 316 317 318 319 320
{
        /* can't use call_intasaddr_function() since purify_get_user_data()
         * returns a void*
         */
	long memrep;
	void* data;

321
	if (!PyArg_ParseTuple(args, "l:purify_get_user_data", &memrep))
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
		return NULL;

	data = purify_get_user_data((char*)memrep);
	return Py_BuildValue("l", (long)data);
}


/* this global variable is shared by both mapping functions:
 * pure_purify_map_pool() and pure_purify_map_pool_id().  Since they cache
 * this variable it should be safe in the face of recursion or cross
 * calling.
 *
 * Further note that the prototype for the callback function is wrong in
 * the Purify manual.  The manual says the function takes a single char*,
 * but the header file says it takes an additional int and void*.  I have
 * no idea what these are for!
 */
static PyObject* MapCallable = NULL;

static void
342
map_pool_callback(char* mem, int user_size, void *user_aux_data)
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
{
	long memrep = (long)mem;
	long user_aux_data_rep = (long)user_aux_data;
	PyObject* result;
	PyObject* memobj = Py_BuildValue("lil", memrep, user_size,
					 user_aux_data_rep);

	if (memobj == NULL)
		return;

	result = PyEval_CallObject(MapCallable, memobj);
	Py_DECREF(result);
	Py_DECREF(memobj);
}

static PyObject*
359
pure_purify_map_pool(PyObject *self, PyObject *args)
360 361 362 363 364 365
{
        /* cache global variable in case of recursion */
	PyObject* saved_callable = MapCallable;
	PyObject* arg_callable;
	int id;

366
	if (!PyArg_ParseTuple(args, "iO:purify_map_pool", &id, &arg_callable))
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
		return NULL;

	if (!PyCallable_Check(arg_callable)) {
		PyErr_SetString(PyExc_TypeError,
				"Second argument must be callable");
		return NULL;
	}
	MapCallable = arg_callable;
	purify_map_pool(id, map_pool_callback);
	MapCallable = saved_callable;

	Py_INCREF(Py_None);
	return Py_None;
}

static void
383
PurifyMapPoolIdCallback(int id)
384 385 386 387 388 389 390 391 392 393 394 395 396
{
	PyObject* result;
	PyObject* intobj = Py_BuildValue("i", id);

	if (intobj == NULL)
		return;

	result = PyEval_CallObject(MapCallable, intobj);
	Py_DECREF(result);
	Py_DECREF(intobj);
}

static PyObject*
397
pure_purify_map_pool_id(PyObject *self, PyObject *args)
398 399 400 401 402
{
        /* cache global variable in case of recursion */
	PyObject* saved_callable = MapCallable;
	PyObject* arg_callable;

403
	if (!PyArg_ParseTuple(args, "O:purify_map_pool_id", &arg_callable))
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
		return NULL;

	if (!PyCallable_Check(arg_callable)) {
		PyErr_SetString(PyExc_TypeError, "Argument must be callable.");
		return NULL;
	}

	MapCallable = arg_callable;
	purify_map_pool_id(PurifyMapPoolIdCallback);
	MapCallable = saved_callable;

	Py_INCREF(Py_None);
	return Py_None;
}



static PyObject*
422
pure_purify_new_messages(PyObject *self, PyObject *args)
423 424 425 426
{
	return call_voidarg_function(purify_new_messages, self, args);
}
static PyObject*
427
pure_purify_all_messages(PyObject *self, PyObject *args)
428 429 430 431
{
	return call_voidarg_function(purify_all_messages, self, args);
}
static PyObject*
432
pure_purify_clear_messages(PyObject *self, PyObject *args)
433 434 435 436
{
	return call_voidarg_function(purify_clear_messages, self, args);
}
static PyObject*
437
pure_purify_clear_new_messages(PyObject *self, PyObject *args)
438 439 440 441
{
	return call_voidarg_function(purify_clear_new_messages, self, args);
}
static PyObject*
442
pure_purify_start_batch(PyObject *self, PyObject *args)
443 444 445 446
{
	return call_voidarg_function(purify_start_batch, self, args);
}
static PyObject*
447
pure_purify_start_batch_show_first(PyObject *self, PyObject *args)
448 449 450 451 452
{
	return call_voidarg_function(purify_start_batch_show_first,
				     self, args);
}
static PyObject*
453
pure_purify_stop_batch(PyObject *self, PyObject *args)
454 455 456 457
{
	return call_voidarg_function(purify_stop_batch, self, args);
}
static PyObject*
458
pure_purify_name_thread(PyObject *self, PyObject *args)
459 460 461 462 463 464 465
{
        /* can't strictly use call_stringarg_function since
         * purify_name_thread takes a const char*, not a char*
         */
	int status;
	char* stringarg;

466
	if (!PyArg_ParseTuple(args, "s:purify_name_thread", &stringarg))
467 468 469 470 471 472
		return NULL;

	status = purify_name_thread(stringarg);
	return Py_BuildValue("i", status);
}
static PyObject*
473
pure_purify_watch(PyObject *self, PyObject *args)
474 475 476 477
{
	return call_intasaddr_function(purify_watch, self, args);
}
static PyObject*
478
pure_purify_watch_1(PyObject *self, PyObject *args)
479 480 481 482
{
	return call_intasaddr_function(purify_watch_1, self, args);
}
static PyObject*
483
pure_purify_watch_2(PyObject *self, PyObject *args)
484 485 486 487
{
	return call_intasaddr_function(purify_watch_2, self, args);
}
static PyObject*
488
pure_purify_watch_4(PyObject *self, PyObject *args)
489 490 491 492
{
	return call_intasaddr_function(purify_watch_4, self, args);
}
static PyObject*
493
pure_purify_watch_8(PyObject *self, PyObject *args)
494 495 496 497
{
	return call_intasaddr_function(purify_watch_8, self, args);
}
static PyObject*
498
pure_purify_watch_w_1(PyObject *self, PyObject *args)
499 500 501 502
{
	return call_intasaddr_function(purify_watch_w_1, self, args);
}
static PyObject*
503
pure_purify_watch_w_2(PyObject *self, PyObject *args)
504 505 506 507
{
	return call_intasaddr_function(purify_watch_w_2, self, args);
}
static PyObject*
508
pure_purify_watch_w_4(PyObject *self, PyObject *args)
509 510 511 512
{
	return call_intasaddr_function(purify_watch_w_4, self, args);
}
static PyObject*
513
pure_purify_watch_w_8(PyObject *self, PyObject *args)
514 515 516 517
{
	return call_intasaddr_function(purify_watch_w_8, self, args);
}
static PyObject*
518
pure_purify_watch_r_1(PyObject *self, PyObject *args)
519 520 521 522
{
	return call_intasaddr_function(purify_watch_r_1, self, args);
}
static PyObject*
523
pure_purify_watch_r_2(PyObject *self, PyObject *args)
524 525 526 527
{
	return call_intasaddr_function(purify_watch_r_2, self, args);
}
static PyObject*
528
pure_purify_watch_r_4(PyObject *self, PyObject *args)
529 530 531 532
{
	return call_intasaddr_function(purify_watch_r_4, self, args);
}
static PyObject*
533
pure_purify_watch_r_8(PyObject *self, PyObject *args)
534 535 536 537
{
	return call_intasaddr_function(purify_watch_r_8, self, args);
}
static PyObject*
538
pure_purify_watch_rw_1(PyObject *self, PyObject *args)
539 540 541 542
{
	return call_intasaddr_function(purify_watch_rw_1, self, args);
}
static PyObject*
543
pure_purify_watch_rw_2(PyObject *self, PyObject *args)
544 545 546 547
{
	return call_intasaddr_function(purify_watch_rw_2, self, args);
}
static PyObject*
548
pure_purify_watch_rw_4(PyObject *self, PyObject *args)
549 550 551 552
{
	return call_intasaddr_function(purify_watch_rw_4, self, args);
}
static PyObject*
553
pure_purify_watch_rw_8(PyObject *self, PyObject *args)
554 555 556 557 558
{
	return call_intasaddr_function(purify_watch_rw_8, self, args);
}

static PyObject*
559
pure_purify_watch_n(PyObject *self, PyObject *args)
560 561 562 563 564 565
{
	long addrrep;
	unsigned int size;
	char* type;
	int status;

566
	if (!PyArg_ParseTuple(args, "lis:purify_watch_n", &addrrep, &size, &type))
567 568 569 570 571 572 573
		return NULL;

	status = purify_watch_n((char*)addrrep, size, type);
	return Py_BuildValue("i", status);
}

static PyObject*
574
pure_purify_watch_info(PyObject *self, PyObject *args)
575 576 577 578 579
{
	return call_voidarg_function(purify_watch_info, self, args);
}

static PyObject*
580
pure_purify_watch_remove(PyObject *self, PyObject *args)
581 582 583 584
{
	int watchno;
	int status;

585
	if (!PyArg_ParseTuple(args, "i:purify_watch_remove", &watchno))
586 587 588 589 590 591 592
		return NULL;

	status = purify_watch_remove(watchno);
	return Py_BuildValue("i", status);
}

static PyObject*
593
pure_purify_watch_remove_all(PyObject *self, PyObject *args)
594 595 596 597
{
	return call_voidarg_function(purify_watch_remove_all, self, args);
}
static PyObject*
598
pure_purify_describe(PyObject *self, PyObject *args)
599 600 601 602
{
	long addrrep;
	char* rtn;

603
	if (!PyArg_ParseTuple(args, "l:purify_describe", &addrrep))
604 605 606 607 608 609 610
		return NULL;

	rtn = purify_describe((char*)addrrep);
	return Py_BuildValue("l", (long)rtn);
}

static PyObject*
611
pure_purify_what_colors(PyObject *self, PyObject *args)
612 613 614 615 616
{
	long addrrep;
	unsigned int size;
	int status;
    
617
	if (!PyArg_ParseTuple(args, "li:purify_what_colors", &addrrep, &size))
618 619 620 621 622 623 624
		return NULL;

	status = purify_what_colors((char*)addrrep, size);
	return Py_BuildValue("i", status);
}

static PyObject*
625
pure_purify_is_running(PyObject *self, PyObject *args)
626 627 628 629 630
{
	return call_voidarg_function(purify_is_running, self, args);
}

static PyObject*
631
pure_purify_assert_is_readable(PyObject *self, PyObject *args)
632 633 634 635 636
{
	return call_stringandint_function(purify_assert_is_readable,
					  self, args);
}
static PyObject*
637
pure_purify_assert_is_writable(PyObject *self, PyObject *args)
638 639 640 641 642 643 644 645 646 647 648 649
{
	return call_stringandint_function(purify_assert_is_writable,
					  self, args);
}

#if HAS_PURIFY_EXIT

/* I wish I could include this, but I can't.  See the notes at the top of
 * the file.
 */

static PyObject*
650
pure_purify_exit(PyObject *self, PyObject *args)
651 652 653
{
	int status;

654
	if (!PyArg_ParseTuple(args, "i:purify_exit", &status))
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
		return NULL;

        /* purify_exit doesn't always act like exit(). See the manual */
	purify_exit(status);
	Py_INCREF(Py_None);
	return Py_None;
}
#endif /* HAS_PURIFY_EXIT */

#endif /* PURIFY_H */



/* Quantify functions
 *
 * N.B. Some of these functions are only described in the quantify.h file,
 * not in the version of the hardcopy manual that I had.  If you're not
 * sure what some of these do, check the header file, it is documented
 * fairly well.
 *
 * None of the custom dynamic loader functions are exported.
 *
 */
#ifdef QUANTIFY_H

static PyObject*
681
pure_quantify_is_running(PyObject *self, PyObject *args)
682 683 684 685
{
	return call_voidarg_function(quantify_is_running, self, args);
}
static PyObject*
686
pure_quantify_help(PyObject *self, PyObject *args)
687 688 689 690
{
	return call_voidarg_function(quantify_help, self, args);
}
static PyObject*
691
pure_quantify_print_recording_state(PyObject *self, PyObject *args)
692 693 694 695 696
{
	return call_voidarg_function(quantify_print_recording_state,
				     self, args);
}
static PyObject*
697
pure_quantify_start_recording_data(PyObject *self, PyObject *args)
698 699 700 701 702
{
	return call_voidarg_function(quantify_start_recording_data,
				     self, args);
}
static PyObject*
703
pure_quantify_stop_recording_data(PyObject *self, PyObject *args)
704 705 706 707
{
	return call_voidarg_function(quantify_stop_recording_data, self, args);
}
static PyObject*
708
pure_quantify_is_recording_data(PyObject *self, PyObject *args)
709 710 711 712
{
	return call_voidarg_function(quantify_is_recording_data, self, args);
}
static PyObject*
713
pure_quantify_start_recording_system_calls(PyObject *self, PyObject *args)
714 715 716 717 718
{
	return call_voidarg_function(quantify_start_recording_system_calls,
				     self, args);
}
static PyObject*
719
pure_quantify_stop_recording_system_calls(PyObject *self, PyObject *args)
720 721 722 723 724
{
	return call_voidarg_function(quantify_stop_recording_system_calls,
				     self, args);
}
static PyObject*
725
pure_quantify_is_recording_system_calls(PyObject *self, PyObject *args)
726 727 728 729 730
{
	return call_voidarg_function(quantify_is_recording_system_calls,
				     self, args);
}
static PyObject*
731
pure_quantify_start_recording_system_call(PyObject *self, PyObject *args)
732 733 734 735 736
{
	return call_stringorint_function(quantify_start_recording_system_call,
					   self, args);
}
static PyObject*
737
pure_quantify_stop_recording_system_call(PyObject *self, PyObject *args)
738 739 740 741 742
{
	return call_stringorint_function(quantify_stop_recording_system_call,
					 self, args);
}
static PyObject*
743
pure_quantify_is_recording_system_call(PyObject *self, PyObject *args)
744 745 746 747 748
{
	return call_stringorint_function(quantify_is_recording_system_call,
					 self, args);
}
static PyObject*
749
pure_quantify_start_recording_dynamic_library_data(PyObject *self, PyObject *args)
750 751 752 753 754 755
{
	return call_voidarg_function(
		quantify_start_recording_dynamic_library_data,
		self, args);
}
static PyObject*
756
pure_quantify_stop_recording_dynamic_library_data(PyObject *self, PyObject *args)
757 758 759 760 761 762
{
	return call_voidarg_function(
		quantify_stop_recording_dynamic_library_data,
		self, args);
}
static PyObject*
763
pure_quantify_is_recording_dynamic_library_data(PyObject *self, PyObject *args)
764 765 766 767 768 769
{
	return call_voidarg_function(
		quantify_is_recording_dynamic_library_data,
		self, args);
}
static PyObject*
770
pure_quantify_start_recording_register_window_traps(PyObject *self, PyObject *args)
771 772 773 774 775 776
{
	return call_voidarg_function(
		quantify_start_recording_register_window_traps,
		self, args);
}
static PyObject*
777
pure_quantify_stop_recording_register_window_traps(PyObject *self, PyObject *args)
778 779 780 781 782 783
{
	return call_voidarg_function(
		quantify_stop_recording_register_window_traps,
		self, args);
}
static PyObject*
784
pure_quantify_is_recording_register_window_traps(PyObject *self, PyObject *args)
785 786 787 788 789 790
{
	return call_voidarg_function(
		quantify_is_recording_register_window_traps,
		self, args);
}
static PyObject*
791
pure_quantify_disable_recording_data(PyObject *self, PyObject *args)
792 793 794 795 796
{
	return call_voidarg_function(quantify_disable_recording_data,
				     self, args);
}
static PyObject*
797
pure_quantify_clear_data(PyObject *self, PyObject *args)
798 799 800 801
{
	return call_voidarg_function(quantify_clear_data, self, args);
}
static PyObject*
802
pure_quantify_save_data(PyObject *self, PyObject *args)
803 804 805 806
{
	return call_voidarg_function(quantify_save_data, self, args);
}
static PyObject*
807
pure_quantify_save_data_to_file(PyObject *self, PyObject *args)
808 809 810 811
{
	return call_stringarg_function(quantify_save_data_to_file, self, args);
}
static PyObject*
812
pure_quantify_add_annotation(PyObject *self, PyObject *args)
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
{
	return call_stringarg_function(quantify_add_annotation, self, args);
}

#endif /* QUANTIFY_H */



/* external interface
 */
static struct PyMethodDef
pure_methods[] = {
#ifdef COMMON_PURE_FUNCTIONS
    {"pure_logfile_printf",            pure_pure_logfile_printf,            1},
    {"pure_printf",                    pure_pure_printf,                    1},
    {"pure_printf_with_banner",        pure_pure_printf_with_banner,        1},
#endif /* COMMON_PURE_FUNCTIONS */
#ifdef PURIFY_H
    {"purify_all_inuse",               pure_purify_all_inuse,               1},
    {"purify_all_leaks",               pure_purify_all_leaks,               1},
    {"purify_new_inuse",               pure_purify_new_inuse,               1},
    {"purify_new_leaks",               pure_purify_new_leaks,               1},
    {"purify_clear_inuse",             pure_purify_clear_inuse,             1},
    {"purify_clear_leaks",             pure_purify_clear_leaks,             1},
    {"purify_all_fds_inuse",           pure_purify_all_fds_inuse,           1},
    {"purify_new_fds_inuse",           pure_purify_new_fds_inuse,           1},
    /* see purify.h */
    {"purify_logfile_printf",          pure_pure_logfile_printf,            1},
    {"purify_printf",                  pure_pure_printf,                    1},
    {"purify_printf_with_banner",      pure_pure_printf_with_banner,        1},
    /**/
    {"purify_printf_with_call_chain",  pure_purify_printf_with_call_chain,  1},
    {"purify_set_pool_id",             pure_purify_set_pool_id,             1},
    {"purify_get_pool_id",             pure_purify_get_pool_id,             1},
    {"purify_set_user_data",           pure_purify_set_user_data,           1},
    {"purify_get_user_data",           pure_purify_get_user_data,           1},
    {"purify_map_pool",                pure_purify_map_pool,                1},
    {"purify_map_pool_id",             pure_purify_map_pool_id,             1},
    {"purify_new_messages",            pure_purify_new_messages,            1},
    {"purify_all_messages",            pure_purify_all_messages,            1},
    {"purify_clear_messages",          pure_purify_clear_messages,          1},
    {"purify_clear_new_messages",      pure_purify_clear_new_messages,      1},
    {"purify_start_batch",             pure_purify_start_batch,             1},
    {"purify_start_batch_show_first",  pure_purify_start_batch_show_first,  1},
    {"purify_stop_batch",              pure_purify_stop_batch,              1},
    {"purify_name_thread",             pure_purify_name_thread,             1},
    {"purify_watch",                   pure_purify_watch,                   1},
    {"purify_watch_1",                 pure_purify_watch_1,                 1},
    {"purify_watch_2",                 pure_purify_watch_2,                 1},
    {"purify_watch_4",                 pure_purify_watch_4,                 1},
    {"purify_watch_8",                 pure_purify_watch_8,                 1},
    {"purify_watch_w_1",               pure_purify_watch_w_1,               1},
    {"purify_watch_w_2",               pure_purify_watch_w_2,               1},
    {"purify_watch_w_4",               pure_purify_watch_w_4,               1},
    {"purify_watch_w_8",               pure_purify_watch_w_8,               1},
    {"purify_watch_r_1",               pure_purify_watch_r_1,               1},
    {"purify_watch_r_2",               pure_purify_watch_r_2,               1},
    {"purify_watch_r_4",               pure_purify_watch_r_4,               1},
    {"purify_watch_r_8",               pure_purify_watch_r_8,               1},
    {"purify_watch_rw_1",              pure_purify_watch_rw_1,              1},
    {"purify_watch_rw_2",              pure_purify_watch_rw_2,              1},
    {"purify_watch_rw_4",              pure_purify_watch_rw_4,              1},
    {"purify_watch_rw_8",              pure_purify_watch_rw_8,              1},
    {"purify_watch_n",                 pure_purify_watch_n,                 1},
    {"purify_watch_info",              pure_purify_watch_info,              1},
    {"purify_watch_remove",            pure_purify_watch_remove,            1},
    {"purify_watch_remove_all",        pure_purify_watch_remove_all,        1},
    {"purify_describe",                pure_purify_describe,                1},
    {"purify_what_colors",             pure_purify_what_colors,             1},
    {"purify_is_running",              pure_purify_is_running,              1},
    {"purify_assert_is_readable",      pure_purify_assert_is_readable,      1},
    {"purify_assert_is_writable",      pure_purify_assert_is_writable,      1},
#if HAS_PURIFY_EXIT
    /* I wish I could include this, but I can't.  See the notes at the
     * top of the file.
     */
    {"purify_exit",                    pure_purify_exit,                    1},
#endif /* HAS_PURIFY_EXIT */
#endif /* PURIFY_H */
#ifdef QUANTIFY_H
    {"quantify_is_running",            pure_quantify_is_running,            1},
    {"quantify_help",                  pure_quantify_help,                  1},
    {"quantify_print_recording_state", pure_quantify_print_recording_state, 1},
    {"quantify_start_recording_data",  pure_quantify_start_recording_data,  1},
    {"quantify_stop_recording_data",   pure_quantify_stop_recording_data,   1},
    {"quantify_is_recording_data",     pure_quantify_is_recording_data,  1},
    {"quantify_start_recording_system_calls",
     pure_quantify_start_recording_system_calls, 1},
    {"quantify_stop_recording_system_calls",
     pure_quantify_stop_recording_system_calls, 1},
    {"quantify_is_recording_system_calls",
     pure_quantify_is_recording_system_calls, 1},
    {"quantify_start_recording_system_call",
     pure_quantify_start_recording_system_call, 1},
    {"quantify_stop_recording_system_call",
     pure_quantify_stop_recording_system_call, 1},
    {"quantify_is_recording_system_call",
     pure_quantify_is_recording_system_call, 1},
    {"quantify_start_recording_dynamic_library_data",
     pure_quantify_start_recording_dynamic_library_data, 1},
    {"quantify_stop_recording_dynamic_library_data",
     pure_quantify_stop_recording_dynamic_library_data, 1},
    {"quantify_is_recording_dynamic_library_data",
     pure_quantify_is_recording_dynamic_library_data, 1},
    {"quantify_start_recording_register_window_traps",
     pure_quantify_start_recording_register_window_traps, 1},
    {"quantify_stop_recording_register_window_traps",
     pure_quantify_stop_recording_register_window_traps, 1},
    {"quantify_is_recording_register_window_traps",
     pure_quantify_is_recording_register_window_traps, 1},
    {"quantify_disable_recording_data",
     pure_quantify_disable_recording_data, 1},
    {"quantify_clear_data",        pure_quantify_clear_data,        1},
    {"quantify_save_data",         pure_quantify_save_data,         1},
    {"quantify_save_data_to_file", pure_quantify_save_data_to_file, 1},
    {"quantify_add_annotation",    pure_quantify_add_annotation,    1},
#endif /* QUANTIFY_H */
    {NULL,  NULL}			     /* sentinel */
};



static void
ins(d, name, val)
	PyObject *d;
	char* name;
	long val;
{
	PyObject *v = PyInt_FromLong(val);
	if (v) {
		(void)PyDict_SetItemString(d, name, v);
		Py_DECREF(v);
	}
}


void
initpure()
{
	PyObject *m, *d;

	m = Py_InitModule("pure", pure_methods);
	d = PyModule_GetDict(m);

        /* this is bogus because we should be able to find this information
         * out from the header files.  Pure's current versions don't
         * include this information!
         */
#ifdef PURE_PURIFY_VERSION
	ins(d, "PURIFY_VERSION", PURE_PURIFY_VERSION);
#else
	PyDict_SetItemString(d, "PURIFY_VERSION", Py_None);
#endif

        /* these aren't terribly useful because purify_exit() isn't
         * exported correctly.  See the note at the top of the file.
         */
#ifdef PURIFY_EXIT_ERRORS
	ins(d, "PURIFY_EXIT_ERRORS", PURIFY_EXIT_ERRORS);
#endif
#ifdef PURIFY_EXIT_LEAKS
	ins(d, "PURIFY_EXIT_LEAKS",  PURIFY_EXIT_LEAKS);
#endif
#ifdef PURIFY_EXIT_PLEAKS
	ins(d, "PURIFY_EXIT_PLEAKS", PURIFY_EXIT_PLEAKS);
#endif


#ifdef PURE_QUANTIFY_VERSION
	ins(d, "QUANTIFY_VERSION", PURE_QUANTIFY_VERSION);
#else
	PyDict_SetItemString(d, "QUANTIFY_VERSION", Py_None);
#endif
}