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
c22fe428
Commit
c22fe428
authored
Aug 13, 2016
by
Ivan Smirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change str/bytes cast operators to ctors
parent
89ec7f3e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
include/pybind11/pytypes.h
+12
-12
No files found.
include/pybind11/pytypes.h
View file @
c22fe428
...
@@ -357,6 +357,8 @@ public:
...
@@ -357,6 +357,8 @@ public:
str
(
const
std
::
string
&
s
)
:
str
(
s
.
data
(),
s
.
size
())
{
}
str
(
const
std
::
string
&
s
)
:
str
(
s
.
data
(),
s
.
size
())
{
}
str
(
const
bytes
&
b
);
operator
std
::
string
()
const
{
operator
std
::
string
()
const
{
object
temp
=
*
this
;
object
temp
=
*
this
;
if
(
PyUnicode_Check
(
m_ptr
))
{
if
(
PyUnicode_Check
(
m_ptr
))
{
...
@@ -370,8 +372,6 @@ public:
...
@@ -370,8 +372,6 @@ public:
pybind11_fail
(
"Unable to extract string contents! (invalid type)"
);
pybind11_fail
(
"Unable to extract string contents! (invalid type)"
);
return
std
::
string
(
buffer
,
(
size_t
)
length
);
return
std
::
string
(
buffer
,
(
size_t
)
length
);
}
}
operator
bytes
()
const
;
};
};
inline
pybind11
::
str
handle
::
str
()
const
{
inline
pybind11
::
str
handle
::
str
()
const
{
...
@@ -394,6 +394,8 @@ public:
...
@@ -394,6 +394,8 @@ public:
bytes
(
const
std
::
string
&
s
)
:
bytes
(
s
.
data
(),
s
.
size
())
{
}
bytes
(
const
std
::
string
&
s
)
:
bytes
(
s
.
data
(),
s
.
size
())
{
}
bytes
(
const
pybind11
::
str
&
s
);
operator
std
::
string
()
const
{
operator
std
::
string
()
const
{
char
*
buffer
;
char
*
buffer
;
ssize_t
length
;
ssize_t
length
;
...
@@ -401,14 +403,12 @@ public:
...
@@ -401,14 +403,12 @@ public:
pybind11_fail
(
"Unable to extract bytes contents!"
);
pybind11_fail
(
"Unable to extract bytes contents!"
);
return
std
::
string
(
buffer
,
(
size_t
)
length
);
return
std
::
string
(
buffer
,
(
size_t
)
length
);
}
}
operator
pybind11
::
str
()
const
;
};
};
inline
str
::
operator
bytes
()
const
{
inline
bytes
::
bytes
(
const
pybind11
::
str
&
s
)
{
object
temp
=
*
thi
s
;
object
temp
=
s
;
if
(
PyUnicode_Check
(
m_ptr
))
{
if
(
PyUnicode_Check
(
s
.
ptr
()
))
{
temp
=
object
(
PyUnicode_AsUTF8String
(
m_ptr
),
false
);
temp
=
object
(
PyUnicode_AsUTF8String
(
s
.
ptr
()
),
false
);
if
(
!
temp
)
if
(
!
temp
)
pybind11_fail
(
"Unable to extract string contents! (encoding issue)"
);
pybind11_fail
(
"Unable to extract string contents! (encoding issue)"
);
}
}
...
@@ -419,18 +419,18 @@ inline str::operator bytes() const {
...
@@ -419,18 +419,18 @@ inline str::operator bytes() const {
auto
obj
=
object
(
PYBIND11_BYTES_FROM_STRING_AND_SIZE
(
buffer
,
length
),
false
);
auto
obj
=
object
(
PYBIND11_BYTES_FROM_STRING_AND_SIZE
(
buffer
,
length
),
false
);
if
(
!
obj
)
if
(
!
obj
)
pybind11_fail
(
"Could not allocate bytes object!"
);
pybind11_fail
(
"Could not allocate bytes object!"
);
return
obj
;
m_ptr
=
obj
.
release
().
ptr
()
;
}
}
inline
bytes
::
operator
pybind11
::
str
()
const
{
inline
str
::
str
(
const
bytes
&
b
)
{
char
*
buffer
;
char
*
buffer
;
ssize_t
length
;
ssize_t
length
;
if
(
PYBIND11_BYTES_AS_STRING_AND_SIZE
(
m_ptr
,
&
buffer
,
&
length
))
if
(
PYBIND11_BYTES_AS_STRING_AND_SIZE
(
b
.
ptr
()
,
&
buffer
,
&
length
))
pybind11_fail
(
"Unable to extract bytes contents!"
);
pybind11_fail
(
"Unable to extract bytes contents!"
);
auto
obj
=
object
(
PyUnicode_FromStringAndSize
(
buffer
,
(
ssize_t
)
length
),
false
);
auto
obj
=
object
(
PyUnicode_FromStringAndSize
(
buffer
,
(
ssize_t
)
length
),
false
);
if
(
!
obj
)
if
(
!
obj
)
pybind11_fail
(
"Could not allocate string object!"
);
pybind11_fail
(
"Could not allocate string object!"
);
return
obj
;
m_ptr
=
obj
.
release
().
ptr
()
;
}
}
class
none
:
public
object
{
class
none
:
public
object
{
...
...
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