/
_sleeper_agent_activation.c
38 lines (32 loc) · 1.03 KB
/
_sleeper_agent_activation.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
#include <Python.h>
/* Return result of sleeper_agent._get_state_info() as a C string */
char * sleeper_agent_state(void)
{
char *rv = NULL;
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
rv = PyString_AsString(
PyObject_Call(
PyObject_GetAttrString(
PyImport_ImportModule("sleeper_agent"),
"_get_state_info"),
Py_BuildValue("()"), NULL));
PyGILState_Release(gstate);
return rv;
}
/* Return sleeper_agent_state() as Python string, for testing and fun */
static PyObject *
sleeper_agent_state_pyobject(PyObject *self, PyObject *args)
{
return Py_BuildValue("s", sleeper_agent_state());
}
static PyMethodDef SleeperAgentMethods[] = {
{"sleeper_agent_state", sleeper_agent_state_pyobject, METH_VARARGS,
"Return the sleeper agent state as a Python string."},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
init_sleeper_agent_activation(void)
{
(void) Py_InitModule("_sleeper_agent_activation", SleeperAgentMethods);
}