Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VTK
VTK
Commits
5e9d9943
Commit
5e9d9943
authored
2 years ago
by
Ben Boeckel
Browse files
Options
Downloads
Patches
Plain Diff
Wrapping/PythonCore: use slots for number access
parent
3644d8c0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Wrapping/PythonCore/PyVTKReference.cxx
+14
-4
14 additions, 4 deletions
Wrapping/PythonCore/PyVTKReference.cxx
Wrapping/PythonCore/vtkPythonOverload.cxx
+6
-0
6 additions, 0 deletions
Wrapping/PythonCore/vtkPythonOverload.cxx
with
20 additions
and
4 deletions
Wrapping/PythonCore/PyVTKReference.cxx
+
14
−
4
View file @
5e9d9943
...
...
@@ -92,12 +92,18 @@ static PyObject* PyVTKReference_CompatibleObject(PyObject* self, PyObject* opn)
}
// check if it has number protocol and suitable methods
#if PY_VERSION_HEX < 0x030A0000
PyNumberMethods
*
nb
=
Py_TYPE
(
opn
)
->
tp_as_number
;
if
(
nb
)
#endif
{
if
(
nb
->
nb_index
)
#if PY_VERSION_HEX >= 0x030A0000
if
(
unaryfunc
nb_index
=
(
unaryfunc
)
PyType_GetSlot
(
Py_TYPE
(
opn
),
Py_nb_index
))
#else
if
(
unaryfunc
nb_index
=
nb
->
nb_index
)
#endif
{
opn
=
nb
->
nb_index
(
opn
);
opn
=
nb_index
(
opn
);
if
(
opn
==
nullptr
||
!
PyLong_Check
(
opn
))
{
PyErr_SetString
(
PyExc_TypeError
,
"nb_index should return integer object"
);
...
...
@@ -105,9 +111,13 @@ static PyObject* PyVTKReference_CompatibleObject(PyObject* self, PyObject* opn)
}
return
opn
;
}
else
if
(
nb
->
nb_float
)
#if PY_VERSION_HEX >= 0x030A0000
else
if
(
unaryfunc
nb_float
=
(
unaryfunc
)
PyType_GetSlot
(
Py_TYPE
(
opn
),
Py_nb_float
))
#else
else
if
(
unaryfunc
nb_float
=
nb
->
nb_float
)
#endif
{
opn
=
nb
->
nb_float
(
opn
);
opn
=
nb_float
(
opn
);
if
(
opn
==
nullptr
||
!
PyFloat_Check
(
opn
))
{
PyErr_SetString
(
PyExc_TypeError
,
"nb_float should return float object"
);
...
...
This diff is collapsed.
Click to expand it.
Wrapping/PythonCore/vtkPythonOverload.cxx
+
6
−
0
View file @
5e9d9943
...
...
@@ -249,6 +249,11 @@ static int vtkPythonIntPenalty(PY_LONG_LONG tmpi, int penalty, char format)
static
bool
vtkPythonCanConvertToInt
(
PyObject
*
arg
)
{
#if PY_VERSION_HEX >= 0x030A0000
unaryfunc
asint
=
(
unaryfunc
)
PyType_GetSlot
(
Py_TYPE
(
arg
),
Py_nb_int
);
unaryfunc
asindex
=
(
unaryfunc
)
PyType_GetSlot
(
Py_TYPE
(
arg
),
Py_nb_index
);
return
(
asint
||
asindex
);
#else
// Python 3.8 deprecated implicit conversions via __int__, so we must
// check for the existence of the __int__ and __index__ slots ourselves
// instead of simply attempting a conversion.
...
...
@@ -258,6 +263,7 @@ static bool vtkPythonCanConvertToInt(PyObject* arg)
#else
return
(
nb
&&
nb
->
nb_int
);
#endif
#endif
}
//------------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Ben Boeckel
@ben.boeckel
mentioned in commit
f3d96cb1
·
2 years ago
mentioned in commit
f3d96cb1
mentioned in commit f3d96cb18a4af4749381c4b00b9b0b98f389c007
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment