This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ovm.c
122 lines (103 loc) · 2.48 KB
/
ovm.c
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
116
117
118
119
120
121
122
/* Print fatal error message and abort */
#include <stdio.h> // fprintf()
#include <stdlib.h> // abort()
#include "Python.h"
#include "pystate.h"
// from Python/pystate.c
PyThreadState *_PyThreadState_Current = NULL;
//
// from Python/ceval.c
//
int _Py_CheckInterval = 100;
volatile int _Py_Ticker = 0; /* so that we hit a "tick" first thing */
PyThreadState *
PyEval_SaveThread(void)
{
return _PyThreadState_Current;
}
void
PyEval_RestoreThread(PyThreadState *tstate)
{
}
#define Py_DEFAULT_RECURSION_LIMIT 1000
int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
int
_Py_CheckRecursiveCall(const char *where)
{
return 0;
}
// Copied from intobject.c, removed all but the long case.
PyObject *
PyInt_FromSsize_t(Py_ssize_t ival)
{
return _PyLong_FromSsize_t(ival);
}
//
// From Objects/typeobject.c
// Risky stub!!!
//
int
PyType_Ready(PyTypeObject *type)
{
return 0;
}
// from Python/_warnings.c
int
PyErr_WarnEx(PyObject *category, const char *text, Py_ssize_t stack_level)
{
return 0;
}
// from Python/sysmodule.c
static void
mywrite(char *name, FILE *fp, const char *format, va_list va)
{
PyObject *file;
PyObject *error_type, *error_value, *error_traceback;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
file = PySys_GetObject(name);
if (file == NULL || PyFile_AsFile(file) == fp)
vfprintf(fp, format, va);
else {
char buffer[1001];
const int written = PyOS_vsnprintf(buffer, sizeof(buffer),
format, va);
if (PyFile_WriteString(buffer, file) != 0) {
PyErr_Clear();
fputs(buffer, fp);
}
if (written < 0 || (size_t)written >= sizeof(buffer)) {
const char *truncated = "... truncated";
if (PyFile_WriteString(truncated, file) != 0) {
PyErr_Clear();
fputs(truncated, fp);
}
}
}
PyErr_Restore(error_type, error_value, error_traceback);
}
void
PySys_WriteStdout(const char *format, ...)
{
va_list va;
va_start(va, format);
mywrite("stdout", stdout, format, va);
va_end(va);
}
void
PySys_WriteStderr(const char *format, ...)
{
va_list va;
va_start(va, format);
mywrite("stderr", stderr, format, va);
va_end(va);
}
void
Py_FatalError(const char *msg)
{
fprintf(stderr, "Fatal Python error: %s\n", msg);
fflush(stderr); /* it helps in Windows debug build */
abort();
}
int main() {
fprintf(stderr, "Hello world");
}