Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
dc4d7493
Commit
dc4d7493
authored
Jul 11, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix rare GC issue during type creation (fixes #277)
parent
c0759976
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
34 deletions
+47
-34
docs/changelog.rst
+3
-2
include/pybind11/pybind11.h
+44
-32
No files found.
docs/changelog.rst
View file @
dc4d7493
...
@@ -13,9 +13,10 @@ Breaking changes queued for v2.0.0 (Not yet released)
...
@@ -13,9 +13,10 @@ Breaking changes queued for v2.0.0 (Not yet released)
* Remove ``handle.call()`` method
* Remove ``handle.call()`` method
1.
9.0 (Not yet released
)
1.
8.1 (July 12, 2016
)
----------------------
----------------------
* Queued changes: ``py::eval*``, map indexing suite, documentation for indexing suites.
* Fixed a rare but potentially very severe issue when the garbage collector ran
during pybind11 type creation.
1.8.0 (June 14, 2016)
1.8.0 (June 14, 2016)
----------------------
----------------------
...
...
include/pybind11/pybind11.h
View file @
dc4d7493
...
@@ -525,8 +525,40 @@ protected:
...
@@ -525,8 +525,40 @@ protected:
pybind11_fail
(
"generic_type: type
\"
"
+
std
::
string
(
rec
->
name
)
+
pybind11_fail
(
"generic_type: type
\"
"
+
std
::
string
(
rec
->
name
)
+
"
\"
is already registered!"
);
"
\"
is already registered!"
);
object
type_holder
(
PyType_Type
.
tp_alloc
(
&
PyType_Type
,
0
),
false
);
object
name
(
PYBIND11_FROM_STRING
(
rec
->
name
),
false
);
object
name
(
PYBIND11_FROM_STRING
(
rec
->
name
),
false
);
object
scope_module
;
if
(
rec
->
scope
)
{
scope_module
=
(
object
)
rec
->
scope
.
attr
(
"__module__"
);
if
(
!
scope_module
)
scope_module
=
(
object
)
rec
->
scope
.
attr
(
"__name__"
);
}
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
/* Qualified names for Python >= 3.3 */
object
scope_qualname
;
if
(
rec
->
scope
)
scope_qualname
=
(
object
)
rec
->
scope
.
attr
(
"__qualname__"
);
object
ht_qualname
;
if
(
scope_qualname
)
{
ht_qualname
=
object
(
PyUnicode_FromFormat
(
"%U.%U"
,
scope_qualname
.
ptr
(),
name
.
ptr
()),
false
);
}
else
{
ht_qualname
=
name
;
}
#endif
std
::
string
full_name
=
(
scope_module
?
((
std
::
string
)
scope_module
.
str
()
+
"."
+
rec
->
name
)
:
std
::
string
(
rec
->
name
));
char
*
tp_doc
=
nullptr
;
if
(
rec
->
doc
)
{
/* Allocate memory for docstring (using PyObject_MALLOC, since
Python will free this later on) */
size_t
size
=
strlen
(
rec
->
doc
)
+
1
;
tp_doc
=
(
char
*
)
PyObject_MALLOC
(
size
);
memcpy
((
void
*
)
tp_doc
,
rec
->
doc
,
size
);
}
object
type_holder
(
PyType_Type
.
tp_alloc
(
&
PyType_Type
,
0
),
false
);
auto
type
=
(
PyHeapTypeObject
*
)
type_holder
.
ptr
();
auto
type
=
(
PyHeapTypeObject
*
)
type_holder
.
ptr
();
if
(
!
type_holder
||
!
name
)
if
(
!
type_holder
||
!
name
)
...
@@ -540,35 +572,17 @@ protected:
...
@@ -540,35 +572,17 @@ protected:
internals
.
registered_types_cpp
[
tindex
]
=
tinfo
;
internals
.
registered_types_cpp
[
tindex
]
=
tinfo
;
internals
.
registered_types_py
[
type
]
=
tinfo
;
internals
.
registered_types_py
[
type
]
=
tinfo
;
object
scope_module
;
if
(
rec
->
scope
)
{
scope_module
=
(
object
)
rec
->
scope
.
attr
(
"__module__"
);
if
(
!
scope_module
)
scope_module
=
(
object
)
rec
->
scope
.
attr
(
"__name__"
);
}
std
::
string
full_name
=
(
scope_module
?
((
std
::
string
)
scope_module
.
str
()
+
"."
+
rec
->
name
)
:
std
::
string
(
rec
->
name
));
/* Basic type attributes */
/* Basic type attributes */
type
->
ht_type
.
tp_name
=
strdup
(
full_name
.
c_str
());
type
->
ht_type
.
tp_name
=
strdup
(
full_name
.
c_str
());
type
->
ht_type
.
tp_basicsize
=
(
ssize_t
)
rec
->
instance_size
;
type
->
ht_type
.
tp_basicsize
=
(
ssize_t
)
rec
->
instance_size
;
type
->
ht_type
.
tp_base
=
(
PyTypeObject
*
)
rec
->
base_handle
.
ptr
();
type
->
ht_type
.
tp_base
=
(
PyTypeObject
*
)
rec
->
base_handle
.
ptr
();
rec
->
base_handle
.
inc_ref
();
rec
->
base_handle
.
inc_ref
();
type
->
ht_name
=
name
.
release
().
ptr
();
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
/* Qualified names for Python >= 3.3 */
type
->
ht_qualname
=
ht_qualname
.
release
().
ptr
();
object
scope_qualname
;
if
(
rec
->
scope
)
scope_qualname
=
(
object
)
rec
->
scope
.
attr
(
"__qualname__"
);
if
(
scope_qualname
)
{
type
->
ht_qualname
=
PyUnicode_FromFormat
(
"%U.%U"
,
scope_qualname
.
ptr
(),
name
.
ptr
());
}
else
{
type
->
ht_qualname
=
name
.
ptr
();
name
.
inc_ref
();
}
#endif
#endif
type
->
ht_name
=
name
.
release
().
ptr
();
/* Supported protocols */
/* Supported protocols */
type
->
ht_type
.
tp_as_number
=
&
type
->
as_number
;
type
->
ht_type
.
tp_as_number
=
&
type
->
as_number
;
...
@@ -590,13 +604,7 @@ protected:
...
@@ -590,13 +604,7 @@ protected:
#endif
#endif
type
->
ht_type
.
tp_flags
&=
~
Py_TPFLAGS_HAVE_GC
;
type
->
ht_type
.
tp_flags
&=
~
Py_TPFLAGS_HAVE_GC
;
if
(
rec
->
doc
)
{
type
->
ht_type
.
tp_doc
=
tp_doc
;
/* Allocate memory for docstring (using PyObject_MALLOC, since
Python will free this later on) */
size_t
size
=
strlen
(
rec
->
doc
)
+
1
;
type
->
ht_type
.
tp_doc
=
(
char
*
)
PyObject_MALLOC
(
size
);
memcpy
((
void
*
)
type
->
ht_type
.
tp_doc
,
rec
->
doc
,
size
);
}
if
(
PyType_Ready
(
&
type
->
ht_type
)
<
0
)
if
(
PyType_Ready
(
&
type
->
ht_type
)
<
0
)
pybind11_fail
(
"generic_type: PyType_Ready failed!"
);
pybind11_fail
(
"generic_type: PyType_Ready failed!"
);
...
@@ -620,17 +628,21 @@ protected:
...
@@ -620,17 +628,21 @@ protected:
if
(
ob_type
==
&
PyType_Type
)
{
if
(
ob_type
==
&
PyType_Type
)
{
std
::
string
name_
=
std
::
string
(
ht_type
.
tp_name
)
+
"__Meta"
;
std
::
string
name_
=
std
::
string
(
ht_type
.
tp_name
)
+
"__Meta"
;
object
type_holder
(
PyType_Type
.
tp_alloc
(
&
PyType_Type
,
0
),
false
);
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
object
ht_qualname
(
PyUnicode_FromFormat
(
"%U__Meta"
,
((
object
)
attr
(
"__qualname__"
)).
ptr
()),
false
);
#endif
object
name
(
PYBIND11_FROM_STRING
(
name_
.
c_str
()),
false
);
object
name
(
PYBIND11_FROM_STRING
(
name_
.
c_str
()),
false
);
object
type_holder
(
PyType_Type
.
tp_alloc
(
&
PyType_Type
,
0
),
false
);
if
(
!
type_holder
||
!
name
)
if
(
!
type_holder
||
!
name
)
pybind11_fail
(
"generic_type::metaclass(): unable to create type object!"
);
pybind11_fail
(
"generic_type::metaclass(): unable to create type object!"
);
auto
type
=
(
PyHeapTypeObject
*
)
type_holder
.
ptr
();
auto
type
=
(
PyHeapTypeObject
*
)
type_holder
.
ptr
();
type
->
ht_name
=
name
.
release
().
ptr
();
type
->
ht_name
=
name
.
release
().
ptr
();
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
/* Qualified names for Python >= 3.3 */
/* Qualified names for Python >= 3.3 */
type
->
ht_qualname
=
PyUnicode_FromFormat
(
type
->
ht_qualname
=
ht_qualname
.
release
().
ptr
();
"%U__Meta"
,
((
object
)
attr
(
"__qualname__"
)).
ptr
());
#endif
#endif
type
->
ht_type
.
tp_name
=
strdup
(
name_
.
c_str
());
type
->
ht_type
.
tp_name
=
strdup
(
name_
.
c_str
());
type
->
ht_type
.
tp_base
=
ob_type
;
type
->
ht_type
.
tp_base
=
ob_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