-
Notifications
You must be signed in to change notification settings - Fork 2
/
nxppy.c
86 lines (71 loc) · 1.91 KB
/
nxppy.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
#include <Python.h>
#include "Mifare.h"
PyObject *InitError;
PyObject *SelectError;
PyObject *ReadError;
PyObject *WriteError;
PyObject *AuthError;
/*
* ########################################################### # Python Extension definitions
* ###########################################################
*/
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"nxppy",
NULL,
0,
NULL,
NULL,
NULL,
NULL,
NULL
};
#define INITERROR return NULL
PyObject *PyInit_nxppy(void)
#else
#define INITERROR return
PyMethodDef nxppy_methods[] = {
{NULL, NULL}
,
};
void initnxppy(void)
#endif
{
PyObject *module;
MifareType.tp_new = PyType_GenericNew;
if (PyType_Ready(&MifareType) < 0) {
#if PY_MAJOR_VERSION >= 3
return NULL;
#else
return;
#endif
}
#if PY_MAJOR_VERSION >= 3
module = PyModule_Create(&moduledef);
#else
module = Py_InitModule("nxppy", nxppy_methods);
#endif
if (module == NULL)
INITERROR;
Py_INCREF(&MifareType);
PyModule_AddObject(module, "Mifare", (PyObject *) & MifareType);
InitError = PyErr_NewException("nxppy.InitError", NULL, NULL);
Py_INCREF(InitError);
PyModule_AddObject(module, "InitError", InitError);
SelectError = PyErr_NewException("nxppy.SelectError", NULL, NULL);
Py_INCREF(SelectError);
PyModule_AddObject(module, "SelectError", SelectError);
ReadError = PyErr_NewException("nxppy.ReadError", NULL, NULL);
Py_INCREF(ReadError);
PyModule_AddObject(module, "ReadError", ReadError);
WriteError = PyErr_NewException("nxppy.WriteError", NULL, NULL);
Py_INCREF(WriteError);
PyModule_AddObject(module, "WriteError", WriteError);
AuthError = PyErr_NewException("nxppy.AuthError", NULL, NULL);
Py_INCREF(AuthError);
PyModule_AddObject(module, "AuthError", AuthError);
#if PY_MAJOR_VERSION >= 3
return module;
#endif
}