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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
b722d04f
Commit
b722d04f
authored
Dec 08, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify common type sharing code and fix ref-count inconsistency
parent
6ebb4a99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
29 deletions
+10
-29
Cython/Utility/CommonTypes.c
Cython/Utility/CommonTypes.c
+10
-29
No files found.
Cython/Utility/CommonTypes.c
View file @
b722d04f
...
...
@@ -6,44 +6,25 @@ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
static
PyTypeObject
*
__Pyx_FetchCommonType
(
PyTypeObject
*
type
)
{
static
PyObject
*
fake_module
=
NULL
;
PyObject
*
args
=
NULL
;
PyTypeObject
*
cached_type
=
NULL
;
const
char
*
cython_module
=
"_cython_"
CYTHON_ABI
;
if
(
fake_module
==
NULL
)
{
PyObject
*
sys_modules
=
PyImport_GetModuleDict
();
// borrowed
fake_module
=
PyDict_GetItemString
(
sys_modules
,
cython_module
);
// borrowed
if
(
fake_module
!=
NULL
)
{
Py_INCREF
(
fake_module
);
}
else
{
PyObject
*
py_cython_module
;
args
=
PyTuple_New
(
1
);
if
(
args
==
NULL
)
goto
bad
;
#if PY_MAJOR_VERSION >= 3
py_cython_module
=
PyUnicode_DecodeUTF8
(
cython_module
,
strlen
(
cython_module
),
NULL
);
#else
py_cython_module
=
PyBytes_FromString
(
cython_module
);
#endif
if
(
py_cython_module
==
NULL
)
goto
bad
;
PyTuple_SET_ITEM
(
args
,
0
,
py_cython_module
);
fake_module
=
PyObject_Call
((
PyObject
*
)
&
PyModule_Type
,
args
,
NULL
);
if
(
PyDict_SetItemString
(
sys_modules
,
cython_module
,
fake_module
)
<
0
)
goto
bad
;
}
if
(
!
fake_module
)
{
fake_module
=
PyImport_AddModule
(
cython_module
);
if
(
!
fake_module
)
goto
bad
;
}
if
(
PyObject_HasAttrString
(
fake_module
,
type
->
tp_name
))
{
cached_type
=
(
PyTypeObject
*
)
PyObject_GetAttrString
(
fake_module
,
type
->
tp_name
);
}
else
{
cached_type
=
(
PyTypeObject
*
)
PyObject_GetAttrString
(
fake_module
,
type
->
tp_name
);
if
(
!
cached_type
)
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
goto
bad
;
PyErr_Clear
();
if
(
PyType_Ready
(
type
)
<
0
)
goto
bad
;
if
(
PyObject_SetAttrString
(
fake_module
,
type
->
tp_name
,
(
PyObject
*
)
type
)
<
0
)
goto
bad
;
Py_INCREF
(
type
);
cached_type
=
type
;
}
cleanup:
Py_XDECREF
(
args
);
return
cached_type
;
bad:
cached_type
=
NULL
;
goto
cleanup
;
// NOTE: always returns owned reference, or NULL on error
return
cached_type
;
}
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