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
5cf93a08
Commit
5cf93a08
authored
Feb 14, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Plain Diff
Restoring PYBIND11_USE_SMART_HOLDER_AS_DEFAULT define after merge conflict.
parents
e98fb2f3
724eede2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
4 deletions
+46
-4
.github/workflows/pip.yml
+2
-2
include/pybind11/pytypes.h
+28
-0
tests/CMakeLists.txt
+2
-1
tests/test_pytypes.cpp
+7
-0
tests/test_pytypes.py
+7
-1
No files found.
.github/workflows/pip.yml
View file @
5cf93a08
...
...
@@ -91,13 +91,13 @@ jobs:
-
uses
:
actions/download-artifact@v2
-
name
:
Publish standard package
uses
:
pypa/gh-action-pypi-publish@v1.4.
1
uses
:
pypa/gh-action-pypi-publish@v1.4.
2
with
:
password
:
${{ secrets.pypi_password }}
packages_dir
:
standard/
-
name
:
Publish global package
uses
:
pypa/gh-action-pypi-publish@v1.4.
1
uses
:
pypa/gh-action-pypi-publish@v1.4.
2
with
:
password
:
${{ secrets.pypi_password_global }}
packages_dir
:
global/
include/pybind11/pytypes.h
View file @
5cf93a08
...
...
@@ -1072,6 +1072,34 @@ inline str::str(const bytes& b) {
/// \addtogroup pytypes
/// @{
class
bytearray
:
public
object
{
public
:
PYBIND11_OBJECT_CVT
(
bytearray
,
object
,
PyByteArray_Check
,
PyByteArray_FromObject
)
bytearray
(
const
char
*
c
,
size_t
n
)
:
object
(
PyByteArray_FromStringAndSize
(
c
,
(
ssize_t
)
n
),
stolen_t
{})
{
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate bytearray object!"
);
}
bytearray
()
:
bytearray
(
""
,
0
)
{}
explicit
bytearray
(
const
std
::
string
&
s
)
:
bytearray
(
s
.
data
(),
s
.
size
())
{
}
size_t
size
()
const
{
return
static_cast
<
size_t
>
(
PyByteArray_Size
(
m_ptr
));
}
explicit
operator
std
::
string
()
const
{
char
*
buffer
=
PyByteArray_AS_STRING
(
m_ptr
);
ssize_t
size
=
PyByteArray_GET_SIZE
(
m_ptr
);
return
std
::
string
(
buffer
,
static_cast
<
size_t
>
(
size
));
}
};
// Note: breathe >= 4.17.0 will fail to build docs if the below two constructors
// are included in the doxygen group; close here and reopen after as a workaround
/// @} pytypes
/// \addtogroup pytypes
/// @{
class
none
:
public
object
{
public
:
PYBIND11_OBJECT
(
none
,
object
,
detail
::
PyNone_Check
)
...
...
tests/CMakeLists.txt
View file @
5cf93a08
...
...
@@ -233,7 +233,8 @@ if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
message
(
STATUS
"Building tests with Eigen v
${
EIGEN3_VERSION
}
"
)
else
()
list
(
REMOVE_AT PYBIND11_TEST_FILES
${
PYBIND11_TEST_FILES_EIGEN_I
}
)
message
(
STATUS
"Building tests WITHOUT Eigen, use -DDOWNLOAD_EIGEN on CMake 3.11+ to download"
)
message
(
STATUS
"Building tests WITHOUT Eigen, use -DDOWNLOAD_EIGEN=ON on CMake 3.11+ to download"
)
endif
()
endif
()
...
...
tests/test_pytypes.cpp
View file @
5cf93a08
...
...
@@ -92,6 +92,10 @@ TEST_SUBMODULE(pytypes, m) {
m
.
def
(
"bytes_from_string"
,
[]()
{
return
py
::
bytes
(
std
::
string
(
"foo"
));
});
m
.
def
(
"bytes_from_str"
,
[]()
{
return
py
::
bytes
(
py
::
str
(
"bar"
,
3
));
});
// test bytearray
m
.
def
(
"bytearray_from_string"
,
[]()
{
return
py
::
bytearray
(
std
::
string
(
"foo"
));
});
m
.
def
(
"bytearray_size"
,
[]()
{
return
py
::
bytearray
(
"foo"
).
size
();
});
// test_capsule
m
.
def
(
"return_capsule_with_destructor"
,
[]()
{
py
::
print
(
"creating capsule"
);
...
...
@@ -210,6 +214,7 @@ TEST_SUBMODULE(pytypes, m) {
m
.
def
(
"default_constructors"
,
[]()
{
return
py
::
dict
(
"bytes"
_a
=
py
::
bytes
(),
"bytearray"
_a
=
py
::
bytearray
(),
"str"
_a
=
py
::
str
(),
"bool"
_a
=
py
::
bool_
(),
"int"
_a
=
py
::
int_
(),
...
...
@@ -224,6 +229,7 @@ TEST_SUBMODULE(pytypes, m) {
m
.
def
(
"converting_constructors"
,
[](
py
::
dict
d
)
{
return
py
::
dict
(
"bytes"
_a
=
py
::
bytes
(
d
[
"bytes"
]),
"bytearray"
_a
=
py
::
bytearray
(
d
[
"bytearray"
]),
"str"
_a
=
py
::
str
(
d
[
"str"
]),
"bool"
_a
=
py
::
bool_
(
d
[
"bool"
]),
"int"
_a
=
py
::
int_
(
d
[
"int"
]),
...
...
@@ -240,6 +246,7 @@ TEST_SUBMODULE(pytypes, m) {
// When converting between Python types, obj.cast<T>() should be the same as T(obj)
return
py
::
dict
(
"bytes"
_a
=
d
[
"bytes"
].
cast
<
py
::
bytes
>
(),
"bytearray"
_a
=
d
[
"bytearray"
].
cast
<
py
::
bytearray
>
(),
"str"
_a
=
d
[
"str"
].
cast
<
py
::
str
>
(),
"bool"
_a
=
d
[
"bool"
].
cast
<
py
::
bool_
>
(),
"int"
_a
=
d
[
"int"
].
cast
<
py
::
int_
>
(),
...
...
tests/test_pytypes.py
View file @
5cf93a08
...
...
@@ -143,6 +143,11 @@ def test_bytes(doc):
)
def
test_bytearray
(
doc
):
assert
m
.
bytearray_from_string
()
.
decode
()
==
"foo"
assert
m
.
bytearray_size
()
==
len
(
"foo"
)
def
test_capsule
(
capture
):
pytest
.
gc_collect
()
with
capture
:
...
...
@@ -223,7 +228,7 @@ def test_accessors():
def
test_constructors
():
"""C++ default and converting constructors are equivalent to type calls in Python"""
types
=
[
bytes
,
str
,
bool
,
int
,
float
,
tuple
,
list
,
dict
,
set
]
types
=
[
bytes
,
bytearray
,
str
,
bool
,
int
,
float
,
tuple
,
list
,
dict
,
set
]
expected
=
{
t
.
__name__
:
t
()
for
t
in
types
}
if
env
.
PY2
:
# Note that bytes.__name__ == 'str' in Python 2.
...
...
@@ -234,6 +239,7 @@ def test_constructors():
data
=
{
bytes
:
b
"41"
,
# Currently no supported or working conversions.
bytearray
:
bytearray
(
b
"41"
),
str
:
42
,
bool
:
"Not empty"
,
int
:
"42"
,
...
...
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