Debian Codegraph @

src/main/c/jpy_jfield.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 "jpy_module.h"
18 #include "jpy_diag.h"
19 #include "jpy_jtype.h"
20 #include "jpy_jobj.h"
21 #include "jpy_jfield.h"
22 #include "jpy_conv.h"
23 #include "jpy_compat.h"
24
25
26 JPy_JField* JField_New(JPy_JType* declaringClass, PyObject* fieldName, JPy_JType* fieldType, jboolean isStatic, jboolean isFinal, jfieldID fid)
27 {
28 PyTypeObject* type = &JField_Type;
29 JPy_JField* field;
30
31 field = (JPy_JField*) type->tp_alloc(type, 0);
32 field->declaringClass = declaringClass;
33 field->name = fieldName;
34 field->type = fieldType;
35 field->isStatic = isStatic;
36 field->isFinal = isFinal;
37 field->fid = fid;
38
39 JPy_INCREF(field->name);
40 JPy_INCREF(field->type);
41
42 return field;
43 }
44
45 /**
46 * The JField type's tp_dealloc slot.
47 */
48 void JField_dealloc(JPy_JField* self)
49 {
50 JPy_DECREF(self->name);
51 JPy_DECREF(self->type);
52 Py_TYPE(self)->tp_free((PyObject*) self);
53 }
54
55 void JField_Del(JPy_JField* field)
56 {
57 JField_dealloc(field);
58 }
59
60
61 /**
62 * The JField type's tp_repr slot.
63 */
64 PyObject* JField_repr(JPy_JField* self)
65 {
66 const char* name = JPy_AS_UTF8(self->name);
67 return JPy_FROM_FORMAT("%s(name='%s', is_static=%d, is_final=%d, fid=%p)",
68 ((PyObject*)self)->ob_type->tp_name,
69 name,
70 self->isStatic,
71 self->isFinal,
72 self->fid);
73 }
74
75 /**
76 * The JField type's tp_str slot.
77 */
78 PyObject* JField_str(JPy_JField* self)
79 {
80 JPy_INCREF(self->name);
81 return self->name;
82 }
83
84
85 static PyMemberDef JField_members[] =
86 {
87 {"name", T_OBJECT_EX, offsetof(JPy_JField, name), READONLY, "Field name"},
88 {"is_static", T_BOOL, offsetof(JPy_JField, isStatic), READONLY, "Tests if this is a static field"},
89 {"is_final", T_BOOL, offsetof(JPy_JField, isFinal), READONLY, "Tests if this is a final field"},
90 {NULL} /* Sentinel */
91 };
92
93
94 /**
95 * Implements the BeamPy_JObjectType class singleton.
96 */
97 PyTypeObject JField_Type = {
98 PyVarObject_HEAD_INIT(NULL, 0)
99 "jpy.JField", /* tp_name */
100 sizeof (JPy_JField), /* tp_basicsize */
101 0, /* tp_itemsize */
102 (destructor)JField_dealloc, /* tp_dealloc */
103 0, /* tp_print */
104 NULL, /* tp_getattr */
105 NULL, /* tp_setattr */
106 NULL, /* tp_reserved */
107 (reprfunc)JField_repr, /* tp_repr */
108 NULL, /* tp_as_number */
109 NULL, /* tp_as_sequence */
110 NULL, /* tp_as_mapping */
111 NULL, /* tp_hash */
112 NULL, /* tp_call */
113 (reprfunc)JField_str, /* tp_str */
114 NULL, /* tp_getattro */
115 NULL, /* tp_setattro */
116 NULL, /* tp_as_buffer */
117 Py_TPFLAGS_DEFAULT, /* tp_flags */
118 "Java Field Wrapper", /* tp_doc */
119 NULL, /* tp_traverse */
120 NULL, /* tp_clear */
121 NULL, /* tp_richcompare */
122 0, /* tp_weaklistoffset */
123 NULL, /* tp_iter */
124 NULL, /* tp_iternext */
125 NULL, /* tp_methods */
126 JField_members, /* tp_members */
127 NULL, /* tp_getset */
128 NULL, /* tp_base */
129 NULL, /* tp_dict */
130 NULL, /* tp_descr_get */
131 NULL, /* tp_descr_set */
132 0, /* tp_dictoffset */
133 NULL, /* tp_init */
134 NULL, /* tp_alloc */
135 NULL, /* tp_new */
136 };