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
Kirill Smelkov
cython
Commits
6a99c289
Commit
6a99c289
authored
Aug 19, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split an inline helper function to reduce excessive inlining.
parent
524b5755
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
34 deletions
+44
-34
Cython/Utility/TypeConversion.c
Cython/Utility/TypeConversion.c
+44
-34
No files found.
Cython/Utility/TypeConversion.c
View file @
6a99c289
...
...
@@ -204,51 +204,61 @@ static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
return
__Pyx_PyObject_AsStringAndSize
(
o
,
&
ignore
);
}
// Py3.7 returns a "const char*" for unicode strings
static
CYTHON_INLINE
const
char
*
__Pyx_PyObject_AsStringAndSize
(
PyObject
*
o
,
Py_ssize_t
*
length
)
{
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
if
(
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
__Pyx_sys_getdefaultencoding_not_ascii
&&
#endif
PyUnicode_Check
(
o
))
{
#if PY_VERSION_HEX < 0x03030000
char
*
defenc_c
;
// borrowed reference, cached internally in 'o' by CPython
PyObject
*
defenc
=
_PyUnicode_AsDefaultEncodedString
(
o
,
NULL
);
if
(
!
defenc
)
return
NULL
;
defenc_c
=
PyBytes_AS_STRING
(
defenc
);
static
const
char
*
__Pyx_PyUnicode_AsStringAndSize
(
PyObject
*
o
,
Py_ssize_t
*
length
)
{
char
*
defenc_c
;
// borrowed reference, cached internally in 'o' by CPython
PyObject
*
defenc
=
_PyUnicode_AsDefaultEncodedString
(
o
,
NULL
);
if
(
!
defenc
)
return
NULL
;
defenc_c
=
PyBytes_AS_STRING
(
defenc
);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
{
char
*
end
=
defenc_c
+
PyBytes_GET_SIZE
(
defenc
);
char
*
c
;
for
(
c
=
defenc_c
;
c
<
end
;
c
++
)
{
if
((
unsigned
char
)
(
*
c
)
>=
128
)
{
// raise the error
PyUnicode_AsASCIIString
(
o
);
return
NULL
;
}
{
char
*
end
=
defenc_c
+
PyBytes_GET_SIZE
(
defenc
);
char
*
c
;
for
(
c
=
defenc_c
;
c
<
end
;
c
++
)
{
if
((
unsigned
char
)
(
*
c
)
>=
128
)
{
// raise the error
PyUnicode_AsASCIIString
(
o
);
return
NULL
;
}
}
}
#endif
/*__PYX_DEFAULT_STRING_ENCODING_IS_ASCII*/
*
length
=
PyBytes_GET_SIZE
(
defenc
);
return
defenc_c
;
*
length
=
PyBytes_GET_SIZE
(
defenc
);
return
defenc_c
;
}
#else
/* PY_VERSION_HEX < 0x03030000 */
if
(
__Pyx_PyUnicode_READY
(
o
)
==
-
1
)
return
NULL
;
static
CYTHON_INLINE
const
char
*
__Pyx_PyUnicode_AsStringAndSize
(
PyObject
*
o
,
Py_ssize_t
*
length
)
{
if
(
unlikely
(
__Pyx_PyUnicode_READY
(
o
)
==
-
1
))
return
NULL
;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
if
(
PyUnicode_IS_ASCII
(
o
))
{
// cached for the lifetime of the object
*
length
=
PyUnicode_GET_LENGTH
(
o
);
return
PyUnicode_AsUTF8
(
o
);
}
else
{
// raise the error
PyUnicode_AsASCIIString
(
o
);
return
NULL
;
}
if
(
likely
(
PyUnicode_IS_ASCII
(
o
)
))
{
// cached for the lifetime of the object
*
length
=
PyUnicode_GET_LENGTH
(
o
);
return
PyUnicode_AsUTF8
(
o
);
}
else
{
// raise the error
PyUnicode_AsASCIIString
(
o
);
return
NULL
;
}
#else
/* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
return
PyUnicode_AsUTF8AndSize
(
o
,
length
);
return
PyUnicode_AsUTF8AndSize
(
o
,
length
);
#endif
/* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
}
#endif
/* PY_VERSION_HEX < 0x03030000 */
#endif
// Py3.7 returns a "const char*" for unicode strings
static
CYTHON_INLINE
const
char
*
__Pyx_PyObject_AsStringAndSize
(
PyObject
*
o
,
Py_ssize_t
*
length
)
{
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
if
(
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
__Pyx_sys_getdefaultencoding_not_ascii
&&
#endif
PyUnicode_Check
(
o
))
{
return
__Pyx_PyUnicode_AsStringAndSize
(
o
,
length
);
}
else
#endif
/* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */
...
...
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