Debian Codegraph @

src/main/c/jpy_diag.c

raw symbols SCIP
1 /*
2 * Copyright 2015 Brockmann Consult GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <Python.h>
18 #include "structmember.h"
19 #include "jpy_diag.h"
20 #include "jpy_compat.h"
21
22 int JPy_DiagFlags = JPy_DIAG_F_OFF;
23
24
25 void JPy_DiagPrint(int diagFlags, const char * format, ...)
26 {
27 if ((JPy_DiagFlags & diagFlags) != 0) {
28 va_list args;
29 va_start(args, format);
30 vfprintf(stdout, format, args);
31 fflush(stdout);
32 va_end(args);
33 }
34 }
35
36
37 PyObject* Diag_New(void)
38 {
39 JPy_Diag* self;
40
41 self = (JPy_Diag*) PyObject_New(PyObject, &Diag_Type);
42
43 self->F_OFF = JPy_DIAG_F_OFF;
44 self->F_TYPE = JPy_DIAG_F_TYPE;
45 self->F_METH = JPy_DIAG_F_METH;
46 self->F_EXEC = JPy_DIAG_F_EXEC;
47 self->F_MEM = JPy_DIAG_F_MEM;
48 self->F_JVM = JPy_DIAG_F_JVM;
49 self->F_ERR = JPy_DIAG_F_ERR;
50 self->F_ALL = JPy_DIAG_F_ALL;
51
52 return (PyObject*) self;
53 }
54
55
56 PyObject* Diag_getattro(JPy_Diag* self, PyObject *attr_name)
57 {
58 //printf("Diag_getattro: attr_name=%s\n", JPy_AS_UTF8(attr_name));
59 if (strcmp(JPy_AS_UTF8(attr_name), "flags") == 0) {
60 return JPy_FROM_CLONG(JPy_DiagFlags);
61 } else {
62 return PyObject_GenericGetAttr((PyObject*) self, attr_name);
63 }
64 }
65
66
67 int Diag_setattro(JPy_Diag* self, PyObject *attr_name, PyObject *v)
68 {
69 //printf("Diag_setattro: attr_name=%s\n", JPy_AS_UTF8(attr_name));
70 if (strcmp(JPy_AS_UTF8(attr_name), "flags") == 0) {
71 if (JPy_IS_CLONG(v)) {
72 JPy_DiagFlags = self->flags = (int) JPy_AS_CLONG(v);
73 } else {
74 PyErr_SetString(PyExc_ValueError, "value for 'flags' must be an integer number");
75 return -1;
76 }
77 return 0;
78 } else {
79 return PyObject_GenericSetAttr((PyObject*) self, attr_name, v);
80 }
81 }
82
83
84 static PyMemberDef Diag_members[] =
85 {
86 {"flags", T_INT, offsetof(JPy_Diag, flags), READONLY, "Combination of diagnostic flags (F_* constants). If != 0, diagnostic messages are printed out."},
87 {"F_OFF", T_INT, offsetof(JPy_Diag, F_OFF), READONLY, "Don't print any diagnostic messages"},
88 {"F_TYPE", T_INT, offsetof(JPy_Diag, F_TYPE), READONLY, "Type resolution: print diagnostic messages while generating Python classes from Java classes"},
89 {"F_METH", T_INT, offsetof(JPy_Diag, F_METH), READONLY, "Method resolution: print diagnostic messages while resolving Java overloaded methods"},
90 {"F_EXEC", T_INT, offsetof(JPy_Diag, F_EXEC), READONLY, "Execution: print diagnostic messages when Java code is executed"},
91 {"F_MEM", T_INT, offsetof(JPy_Diag, F_MEM), READONLY, "Memory: print diagnostic messages when wrapped Java objects are allocated/deallocated"},
92 {"F_JVM", T_INT, offsetof(JPy_Diag, F_JVM), READONLY, "JVM: print diagnostic information usage of the Java VM Invocation API"},
93 {"F_ERR", T_INT, offsetof(JPy_Diag, F_ERR), READONLY, "Errors: print diagnostic information when erroneous states are detected"},
94 {"F_ALL", T_INT, offsetof(JPy_Diag, F_ALL), READONLY, "Print any diagnostic messages"},
95 {NULL} /* Sentinel */
96 };
97
98
99 PyTypeObject Diag_Type =
100 {
101 PyVarObject_HEAD_INIT(NULL, 0)
102 "jpy.Diag", /* tp_name */
103 sizeof (JPy_Diag), /* tp_basicsize */
104 0, /* tp_itemsize */
105 NULL, /* tp_dealloc */
106 0, /* tp_print */
107 NULL, /* tp_getattr */
108 NULL, /* tp_setattr */
109 NULL, /* tp_reserved */
110 NULL, /* tp_repr */
111 NULL, /* tp_as_number */
112 NULL, /* tp_as_sequence */
113 NULL, /* tp_as_mapping */
114 NULL, /* tp_hash */
115 NULL, /* tp_call */
116 NULL, /* tp_str */
117 (getattrofunc) Diag_getattro, /* tp_getattro */
118 (setattrofunc) Diag_setattro, /* tp_setattro */
119 NULL, /* tp_as_buffer */
120 Py_TPFLAGS_DEFAULT, /* tp_flags */
121 "Controls output of diagnostic information for debugging", /* tp_doc */
122 NULL, /* tp_traverse */
123 NULL, /* tp_clear */
124 NULL, /* tp_richcompare */
125 0, /* tp_weaklistoffset */
126 NULL, /* tp_iter */
127 NULL, /* tp_iternext */
128 NULL, /* tp_methods */
129 Diag_members, /* tp_members */
130 NULL, /* tp_getset */
131 NULL, /* tp_base */
132 NULL, /* tp_dict */
133 NULL, /* tp_descr_get */
134 NULL, /* tp_descr_set */
135 0, /* tp_dictoffset */
136 (initproc) NULL, /* tp_init */
137 NULL, /* tp_alloc */
138 NULL, /* tp_new */
139 };