blob: fb82b114b3c3c5e4b4331c84063c8c2052a0373a [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
20extern void *__crashreporter_info__;
21
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);
36 if (size && data)
37 {
38 __crashreporter_info__ = malloc(size);
39 memcpy(__crashreporter_info__,data,size+1);
40 return Py_True;
41 }
42 }
43 return Py_False;
44}
45
46static PyObject* testCrashReporterDescription(PyObject*self, PyObject* arg)
47{
48 int* ptr = 0;
49 *ptr = 1;
50 return Py_None;
51}
52
53static PyMethodDef crashinfo_methods[] = {
54 {"setCrashReporterDescription", setCrashReporterDescription, METH_O},
55 {"testCrashReporterDescription", testCrashReporterDescription, METH_O},
56 {NULL, NULL}
57};
58
59void initcrashinfo()
60{
61 (void) Py_InitModule("crashinfo", crashinfo_methods);
62}
63