Debian Codegraph @

native/common/jp_primitivetype.cpp

raw symbols SCIP
1 /*****************************************************************************
2 Licensed under the Apache License, Version 2.0 (the "License");
3 you may not use this file except in compliance with the License.
4 You may obtain a copy of the License at
5
6 http://www.apache.org/licenses/LICENSE-2.0
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13
14 See NOTICE file for details.
15 *****************************************************************************/
16 #include "jpype.h"
17
18 JPPrimitiveType::JPPrimitiveType(const string& name)
19 : JPClass(name, 0x411)
20 {
21 }
22
23 JPPrimitiveType::~JPPrimitiveType()
24 = default;
25
26 bool JPPrimitiveType::isPrimitive() const
27 {
28 return true;
29 }
30
31 extern "C" Py_ssize_t PyJPValue_getJavaSlotOffset(PyObject* self);
32
33 // equivalent of long_subtype_new as it isn't exposed
34
35 PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp)
36 {
37 if (wrapper == nullptr)
38 JP_RAISE(PyExc_SystemError, "bad wrapper");
39
40 #if PY_VERSION_HEX<0x030c0000
41 // Determine number of digits to copy
42 Py_ssize_t n = Py_SIZE(tmp);
43 if (n < 0)
44 n = -n;
45
46 auto *newobj = (PyLongObject *) wrapper->tp_alloc(wrapper, n);
47 if (newobj == nullptr)
48 return nullptr;
49
50 // Size is in units of digits
51 ((PyVarObject*) newobj)->ob_size = Py_SIZE(tmp);
52 for (Py_ssize_t i = 0; i < n; i++)
53 {
54 newobj->ob_digit[i] = tmp->ob_digit[i];
55 }
56
57 #else
58 // 3.12 completely does away with ob_size field and repurposes it
59
60 // Determine the number of digits to copy
61 int n = (tmp->long_value.lv_tag >> 3);
62
63 PyLongObject *newobj = (PyLongObject *) wrapper->tp_alloc(wrapper, n);
64 if (newobj == NULL)
65 return NULL;
66
67 newobj->long_value.lv_tag = tmp->long_value.lv_tag;
68 memcpy(&newobj->long_value.ob_digit, &tmp->long_value.ob_digit, n*sizeof(digit));
69 #endif
70 return (PyObject*) newobj;
71 }
72