Enrico Granata | 2c3f140 | 2013-12-12 00:02:05 +0000 | [diff] [blame] | 1 | /****************************************************************************** |
| 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 Granata | 2c3f140 | 2013-12-12 00:02:05 +0000 | [diff] [blame] | 13 | ******************************************************************************/ |
| 14 | |
| 15 | #include <Python/Python.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <string.h> |
| 18 | #include <stdio.h> |
| 19 | |
Enrico Granata | 601ec50 | 2013-12-12 01:47:35 +0000 | [diff] [blame^] | 20 | void *__crashreporter_info__ = NULL; |
Enrico Granata | 2c3f140 | 2013-12-12 00:02:05 +0000 | [diff] [blame] | 21 | |
| 22 | asm(".desc ___crashreporter_info__, 0x10"); |
| 23 | |
| 24 | static 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 | |
| 46 | static PyObject* testCrashReporterDescription(PyObject*self, PyObject* arg) |
| 47 | { |
| 48 | int* ptr = 0; |
| 49 | *ptr = 1; |
| 50 | return Py_None; |
| 51 | } |
| 52 | |
| 53 | static PyMethodDef crashinfo_methods[] = { |
| 54 | {"setCrashReporterDescription", setCrashReporterDescription, METH_O}, |
| 55 | {"testCrashReporterDescription", testCrashReporterDescription, METH_O}, |
| 56 | {NULL, NULL} |
| 57 | }; |
| 58 | |
| 59 | void initcrashinfo() |
| 60 | { |
| 61 | (void) Py_InitModule("crashinfo", crashinfo_methods); |
| 62 | } |
| 63 | |