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
Xavier Thompson
cython
Commits
5578a9ea
Commit
5578a9ea
authored
Jul 19, 2019
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return Py_ssize_t instead of size_t for len(char*) and len(Py_UNICODE*).
Closes GH-2992.
parent
087070ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
7 deletions
+50
-7
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+16
-7
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+34
-0
No files found.
Cython/Compiler/Optimize.py
View file @
5578a9ea
...
...
@@ -2557,12 +2557,20 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
Pyx_strlen_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_size_t_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"bytes"
,
PyrexTypes
.
c_const_char_ptr_type
,
None
)
])
],
nogil
=
True
)
Pyx_ssize_strlen_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_py_ssize_t_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"bytes"
,
PyrexTypes
.
c_const_char_ptr_type
,
None
)
],
exception_value
=
"-1"
)
Pyx_Py_UNICODE_strlen_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_size_t_type
,
[
PyrexTypes
.
c_
py_s
size_t_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"unicode"
,
PyrexTypes
.
c_const_py_unicode_ptr_type
,
None
)
])
],
exception_value
=
"-1"
)
PyObject_Size_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_py_ssize_t_type
,
[
...
...
@@ -2596,15 +2604,16 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
arg
=
arg
.
arg
if
arg
.
type
.
is_string
:
new_node
=
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"
strlen"
,
self
.
Pyx
_strlen_func_type
,
node
.
pos
,
"
__Pyx_ssize_strlen"
,
self
.
Pyx_ssize
_strlen_func_type
,
args
=
[
arg
],
is_temp
=
node
.
is_temp
,
utility_code
=
UtilityCode
.
load_cached
(
"
IncludeStringH
"
,
"StringTools.c"
))
utility_code
=
UtilityCode
.
load_cached
(
"
ssize_strlen
"
,
"StringTools.c"
))
elif
arg
.
type
.
is_pyunicode_ptr
:
new_node
=
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"__Pyx_Py_UNICODE_strlen"
,
self
.
Pyx_Py_UNICODE_strlen_func_type
,
node
.
pos
,
"__Pyx_Py_UNICODE_s
size_s
trlen"
,
self
.
Pyx_Py_UNICODE_strlen_func_type
,
args
=
[
arg
],
is_temp
=
node
.
is_temp
)
is_temp
=
node
.
is_temp
,
utility_code
=
UtilityCode
.
load_cached
(
"ssize_pyunicode_strlen"
,
"StringTools.c"
))
elif
arg
.
type
.
is_memoryviewslice
:
func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_py_ssize_t_type
,
[
...
...
Cython/Utility/StringTools.c
View file @
5578a9ea
...
...
@@ -7,6 +7,40 @@
#include <string>
//////////////////// ssize_strlen.proto ////////////////////
static
CYTHON_INLINE
Py_ssize_t
__Pyx_ssize_strlen
(
const
char
*
s
);
/*proto*/
//////////////////// ssize_strlen ////////////////////
//@requires: IncludeStringH
static
CYTHON_INLINE
Py_ssize_t
__Pyx_ssize_strlen
(
const
char
*
s
)
{
size_t
len
=
strlen
(
s
);
if
(
unlikely
(
len
>
PY_SSIZE_T_MAX
))
{
PyErr_SetString
(
PyExc_OverflowError
,
"byte string is too long"
);
return
-
1
;
}
return
(
Py_ssize_t
)
len
;
}
//////////////////// ssize_pyunicode_strlen.proto ////////////////////
static
CYTHON_INLINE
Py_ssize_t
__Pyx_Py_UNICODE_ssize_strlen
(
const
Py_UNICODE
*
u
);
/*proto*/
//////////////////// ssize_pyunicode_strlen ////////////////////
static
CYTHON_INLINE
Py_ssize_t
__Pyx_Py_UNICODE_ssize_strlen
(
const
Py_UNICODE
*
u
)
{
size_t
len
=
__Pyx_Py_UNICODE_strlen
(
u
);
if
(
unlikely
(
len
>
PY_SSIZE_T_MAX
))
{
PyErr_SetString
(
PyExc_OverflowError
,
"Py_UNICODE string is too long"
);
return
-
1
;
}
return
(
Py_ssize_t
)
len
;
}
//////////////////// InitStrings.proto ////////////////////
static
int
__Pyx_InitStrings
(
__Pyx_StringTabEntry
*
t
);
/*proto*/
...
...
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