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
89ec7f3e
Commit
89ec7f3e
authored
Aug 13, 2016
by
Ivan Smirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add (const char *, size_t) ctors for str/bytes
parent
1e121781
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
example/example-python-types.cpp
+2
-2
include/pybind11/pytypes.h
+8
-4
No files found.
example/example-python-types.cpp
View file @
89ec7f3e
...
@@ -144,7 +144,7 @@ public:
...
@@ -144,7 +144,7 @@ public:
}
}
py
::
bytes
get_bytes_from_str
()
{
py
::
bytes
get_bytes_from_str
()
{
return
(
py
::
bytes
)
py
::
str
(
std
::
string
(
"bar"
)
);
return
(
py
::
bytes
)
py
::
str
(
"bar"
,
3
);
}
}
py
::
str
get_str_from_string
()
{
py
::
str
get_str_from_string
()
{
...
@@ -152,7 +152,7 @@ public:
...
@@ -152,7 +152,7 @@ public:
}
}
py
::
str
get_str_from_bytes
()
{
py
::
str
get_str_from_bytes
()
{
return
(
py
::
str
)
py
::
bytes
(
std
::
string
(
"boo"
)
);
return
(
py
::
str
)
py
::
bytes
(
"boo"
,
3
);
}
}
static
int
value
;
static
int
value
;
...
...
include/pybind11/pytypes.h
View file @
89ec7f3e
...
@@ -345,8 +345,8 @@ class str : public object {
...
@@ -345,8 +345,8 @@ class str : public object {
public
:
public
:
PYBIND11_OBJECT_DEFAULT
(
str
,
object
,
detail
::
PyUnicode_Check_Permissive
)
PYBIND11_OBJECT_DEFAULT
(
str
,
object
,
detail
::
PyUnicode_Check_Permissive
)
str
(
const
std
::
string
&
s
)
str
(
const
char
*
c
,
size_t
n
)
:
object
(
PyUnicode_FromStringAndSize
(
s
.
c_str
(),
(
ssize_t
)
s
.
length
()
),
false
)
{
:
object
(
PyUnicode_FromStringAndSize
(
c
,
(
ssize_t
)
n
),
false
)
{
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate string object!"
);
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate string object!"
);
}
}
...
@@ -355,6 +355,8 @@ public:
...
@@ -355,6 +355,8 @@ public:
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate string object!"
);
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate string object!"
);
}
}
str
(
const
std
::
string
&
s
)
:
str
(
s
.
data
(),
s
.
size
())
{
}
operator
std
::
string
()
const
{
operator
std
::
string
()
const
{
object
temp
=
*
this
;
object
temp
=
*
this
;
if
(
PyUnicode_Check
(
m_ptr
))
{
if
(
PyUnicode_Check
(
m_ptr
))
{
...
@@ -385,11 +387,13 @@ class bytes : public object {
...
@@ -385,11 +387,13 @@ class bytes : public object {
public
:
public
:
PYBIND11_OBJECT_DEFAULT
(
bytes
,
object
,
PYBIND11_BYTES_CHECK
)
PYBIND11_OBJECT_DEFAULT
(
bytes
,
object
,
PYBIND11_BYTES_CHECK
)
bytes
(
const
std
::
string
&
s
)
bytes
(
const
char
*
c
,
size_t
n
)
:
object
(
PYBIND11_BYTES_FROM_STRING_AND_SIZE
(
s
.
data
(),
(
ssize_t
)
s
.
size
()
),
false
)
{
:
object
(
PYBIND11_BYTES_FROM_STRING_AND_SIZE
(
c
,
(
ssize_t
)
n
),
false
)
{
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate bytes object!"
);
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate bytes object!"
);
}
}
bytes
(
const
std
::
string
&
s
)
:
bytes
(
s
.
data
(),
s
.
size
())
{
}
operator
std
::
string
()
const
{
operator
std
::
string
()
const
{
char
*
buffer
;
char
*
buffer
;
ssize_t
length
;
ssize_t
length
;
...
...
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