Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
9053c1e7
Commit
9053c1e7
authored
May 01, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move vtable get/set utility code into ExtensionTypes.c file
parent
dd57b2de
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
54 deletions
+53
-54
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+4
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+0
-52
Cython/Utility/ExtensionTypes.c
Cython/Utility/ExtensionTypes.c
+49
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
9053c1e7
...
...
@@ -2396,7 +2396,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_type_import_call
(
type
,
code
,
code
.
error_goto_if_null
(
type
.
typeptr_cname
,
pos
))
if
type
.
vtabptr_cname
:
env
.
use_utility_code
(
Nodes
.
get_vtable_utility_code
)
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
'GetVTable'
,
'ExtensionTypes.c'
))
code
.
putln
(
"%s = (struct %s*)__Pyx_GetVtable(%s->tp_dict); %s"
%
(
type
.
vtabptr_cname
,
type
.
vtabstruct_cname
,
...
...
@@ -2501,7 +2502,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
typeobj_cname
,
type
.
vtabptr_cname
,
code
.
error_goto
(
entry
.
pos
)))
env
.
use_utility_code
(
Nodes
.
set_vtable_utility_code
)
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
'SetVTable'
,
'ExtensionTypes.c'
))
if
not
type
.
scope
.
is_internal
and
not
type
.
scope
.
directives
[
'internal'
]:
# scope.is_internal is set for types defined by
# Cython (such as closures), the 'internal'
...
...
Cython/Compiler/Nodes.py
View file @
9053c1e7
...
...
@@ -8099,55 +8099,3 @@ static PyObject *__Pyx_GetExceptionTuple(void) {
}
"""
,
requires
=
[
get_exception_utility_code
])
#------------------------------------------------------------------------------------
set_vtable_utility_code
=
UtilityCode
(
proto
=
"""
static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
"""
,
impl
=
"""
static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
if (!ob)
goto bad;
if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
goto bad;
Py_DECREF(ob);
return 0;
bad:
Py_XDECREF(ob);
return -1;
}
"""
)
#------------------------------------------------------------------------------------
get_vtable_utility_code
=
UtilityCode
(
proto
=
"""
static void* __Pyx_GetVtable(PyObject *dict); /*proto*/
"""
,
impl
=
r"""
static void* __Pyx_GetVtable(PyObject *dict) {
void* ptr;
PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__");
if (!ob)
goto bad;
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
ptr = PyCapsule_GetPointer(ob, 0);
#else
ptr = PyCObject_AsVoidPtr(ob);
#endif
if (!ptr && !PyErr_Occurred())
PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
Py_DECREF(ob);
return ptr;
bad:
Py_XDECREF(ob);
return NULL;
}
"""
)
Cython/Utility/ExtensionTypes.c
View file @
9053c1e7
...
...
@@ -51,3 +51,52 @@ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) {
if
(
type
&&
type
->
tp_clear
)
type
->
tp_clear
(
obj
);
}
/////////////// SetVTable.proto ///////////////
static
int
__Pyx_SetVtable
(
PyObject
*
dict
,
void
*
vtable
);
/*proto*/
/////////////// SetVTable ///////////////
static
int
__Pyx_SetVtable
(
PyObject
*
dict
,
void
*
vtable
)
{
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
PyObject
*
ob
=
PyCapsule_New
(
vtable
,
0
,
0
);
#else
PyObject
*
ob
=
PyCObject_FromVoidPtr
(
vtable
,
0
);
#endif
if
(
!
ob
)
goto
bad
;
if
(
PyDict_SetItemString
(
dict
,
"__pyx_vtable__"
,
ob
)
<
0
)
goto
bad
;
Py_DECREF
(
ob
);
return
0
;
bad:
Py_XDECREF
(
ob
);
return
-
1
;
}
/////////////// GetVTable.proto ///////////////
static
void
*
__Pyx_GetVtable
(
PyObject
*
dict
);
/*proto*/
/////////////// GetVTable ///////////////
static
void
*
__Pyx_GetVtable
(
PyObject
*
dict
)
{
void
*
ptr
;
PyObject
*
ob
=
PyMapping_GetItemString
(
dict
,
(
char
*
)
"__pyx_vtable__"
);
if
(
!
ob
)
goto
bad
;
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
ptr
=
PyCapsule_GetPointer
(
ob
,
0
);
#else
ptr
=
PyCObject_AsVoidPtr
(
ob
);
#endif
if
(
!
ptr
&&
!
PyErr_Occurred
())
PyErr_SetString
(
PyExc_RuntimeError
,
"invalid vtable found for imported type"
);
Py_DECREF
(
ob
);
return
ptr
;
bad:
Py_XDECREF
(
ob
);
return
NULL
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment