blob: 19013468bb260e28c11ca72fad29aaf316b6d26f [file] [log] [blame]
Enrico Granata2c3f1402013-12-12 00:02:05 +00001/******************************************************************************
2 The LLVM Compiler Infrastructure
3
4 This file is distributed under the University of Illinois Open Source
5 License. See LICENSE.TXT for details.
6 ******************************************************************************
7
8* This C file vends a simple interface to set the Application Specific Info
9* on Mac OS X through Python. To use, compile as a dylib, import crashinfo
10* and call crashinfo.setCrashReporterDescription("hello world")
11* The testCrashReporterDescription() API is simply there to let you test that this
12* is doing what it is intended to do without having to actually cons up a crash
Enrico Granata2c3f1402013-12-12 00:02:05 +000013******************************************************************************/
14
15#include <Python/Python.h>
16#include <stdlib.h>
17#include <string.h>
18#include <stdio.h>
19
Enrico Granata601ec502013-12-12 01:47:35 +000020void *__crashreporter_info__ = NULL;
Enrico Granata2c3f1402013-12-12 00:02:05 +000021
22asm(".desc ___crashreporter_info__, 0x10");
23
24static PyObject* setCrashReporterDescription(PyObject* self, PyObject* string)
25{
26 if (__crashreporter_info__)
27 {
28 free(__crashreporter_info__);
29 __crashreporter_info__ = NULL;
30 }
31
32 if (string && PyString_Check(string))
33 {
34 Py_ssize_t size = PyString_Size(string);
35 char* data = PyString_AsString(string);
Greg Claytond3b16b32013-12-13 02:02:44 +000036 if (size > 0 && data)
Enrico Granata2c3f1402013-12-12 00:02:05 +000037 {
Enrico Granata29726a92014-01-08 03:14:18 +000038 ++size; // Include the NULL terminateor in allocation and memcpy()
Enrico Granata2c3f1402013-12-12 00:02:05 +000039 __crashreporter_info__ = malloc(size);
Greg Claytond3b16b32013-12-13 02:02:44 +000040 memcpy(__crashreporter_info__, data, size);
Enrico Granata2c3f1402013-12-12 00:02:05 +000041 return Py_True;
42 }
43 }
44 return Py_False;
45}
46
47static PyObject* testCrashReporterDescription(PyObject*self, PyObject* arg)
48{
49 int* ptr = 0;
50 *ptr = 1;
51 return Py_None;
52}
53
54static PyMethodDef crashinfo_methods[] = {
55 {"setCrashReporterDescription", setCrashReporterDescription, METH_O},
56 {"testCrashReporterDescription", testCrashReporterDescription, METH_O},
57 {NULL, NULL}
58};
59
60void initcrashinfo()
61{
62 (void) Py_InitModule("crashinfo", crashinfo_methods);
63}
64