-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjstring.cpp
More file actions
35 lines (32 loc) · 1.05 KB
/
jstring.cpp
File metadata and controls
35 lines (32 loc) · 1.05 KB
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
#include "jstring.hpp"
static jstringObject* jstring_jstring(PyObject *x) {
if (jstring_CheckExact(x))
INC_RETURN_TYPE(x, jstringObject*);
else if (jobject_Check(x))
return jstring_FromValue(jstring_Val(x));
_BadArgument("jstring", "argument", "jstring", x);
return NULL;
}
static jstringObject* jstring_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) {
PyObject *x;
if (!PyArg_UnpackTuple(args, "jstring", 1, 1, &x))
return NULL;
return jstring_jstring(x);
}
PyTypeObject jstring_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "jstring",
.tp_basicsize = sizeof(jstringObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = "jstring type",
.tp_base = &jobject_Type,
.tp_new = (newfunc)jstring_new,
};
jstringObject* jstring_FromValue(jstring value) {
PyTypeObject *type = &jstring_Type;
jstringObject *self = (jstringObject*)type->tp_alloc(type, 0);
if (self != NULL)
jobject_Val(self) = value;
return self;
}