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
Boxiang Sun
cython
Commits
b6fd9655
Commit
b6fd9655
authored
Aug 20, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move utility function to a a better suited source file
parent
2b3f99e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
89 deletions
+91
-89
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+89
-0
Cython/Utility/TypeConversion.c
Cython/Utility/TypeConversion.c
+2
-89
No files found.
Cython/Utility/StringTools.c
View file @
b6fd9655
...
...
@@ -732,6 +732,95 @@ static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* value
#endif
/////////////// BuildPyUnicode.proto ///////////////
static
PyObject
*
__Pyx_PyUnicode_BuildFromAscii
(
Py_ssize_t
ulength
,
char
*
chars
,
int
clength
,
int
prepend_sign
,
char
padding_char
);
/////////////// BuildPyUnicode ///////////////
// Create a PyUnicode object from an ASCII char*, e.g. a formatted number.
static
PyObject
*
__Pyx_PyUnicode_BuildFromAscii
(
Py_ssize_t
ulength
,
char
*
chars
,
int
clength
,
int
prepend_sign
,
char
padding_char
)
{
PyObject
*
uval
;
Py_ssize_t
uoffset
=
ulength
-
clength
;
#if CYTHON_USE_UNICODE_INTERNALS
Py_ssize_t
i
;
#if CYTHON_PEP393_ENABLED
// Py 3.3+ (post PEP-393)
void
*
udata
;
uval
=
PyUnicode_New
(
ulength
,
127
);
if
(
unlikely
(
!
uval
))
return
NULL
;
udata
=
PyUnicode_DATA
(
uval
);
#else
// Py 2.x/3.2 (pre PEP-393)
Py_UNICODE
*
udata
;
uval
=
PyUnicode_FromUnicode
(
NULL
,
ulength
);
if
(
unlikely
(
!
uval
))
return
NULL
;
udata
=
PyUnicode_AS_UNICODE
(
uval
);
#endif
if
(
uoffset
>
0
)
{
i
=
0
;
if
(
prepend_sign
)
{
__Pyx_PyUnicode_WRITE
(
PyUnicode_1BYTE_KIND
,
udata
,
0
,
'-'
);
i
++
;
}
for
(;
i
<
uoffset
;
i
++
)
{
__Pyx_PyUnicode_WRITE
(
PyUnicode_1BYTE_KIND
,
udata
,
i
,
padding_char
);
}
}
for
(
i
=
0
;
i
<
clength
;
i
++
)
{
__Pyx_PyUnicode_WRITE
(
PyUnicode_1BYTE_KIND
,
udata
,
uoffset
+
i
,
chars
[
i
]);
}
#else
// non-CPython
{
uval
=
NULL
;
PyObject
*
sign
=
NULL
,
*
padding
=
NULL
;
if
(
uoffset
>
0
)
{
prepend_sign
=
!!
prepend_sign
;
if
(
uoffset
>
prepend_sign
)
{
padding
=
PyUnicode_FromOrdinal
(
padding_char
);
if
(
likely
(
padding
)
&&
uoffset
>
prepend_sign
+
1
)
{
PyObject
*
tmp
;
PyObject
*
repeat
=
PyInt_FromSize_t
(
uoffset
-
prepend_sign
);
if
(
unlikely
(
!
repeat
))
goto
done_or_error
;
tmp
=
PyNumber_Multiply
(
padding
,
repeat
);
Py_DECREF
(
repeat
);
Py_DECREF
(
padding
);
padding
=
tmp
;
}
if
(
unlikely
(
!
padding
))
goto
done_or_error
;
}
if
(
prepend_sign
)
{
sign
=
PyUnicode_FromOrdinal
(
'-'
);
if
(
unlikely
(
!
sign
))
goto
done_or_error
;
}
}
uval
=
PyUnicode_DecodeASCII
(
chars
,
clength
,
NULL
);
if
(
likely
(
uval
)
&&
padding
)
{
PyObject
*
tmp
=
PyNumber_Add
(
padding
,
uval
);
Py_DECREF
(
uval
);
uval
=
tmp
;
}
if
(
likely
(
uval
)
&&
sign
)
{
PyObject
*
tmp
=
PyNumber_Add
(
sign
,
uval
);
Py_DECREF
(
uval
);
uval
=
tmp
;
}
done_or_error:
Py_XDECREF
(
padding
);
Py_XDECREF
(
sign
);
}
#endif
return
uval
;
}
//////////////////// ByteArrayAppendObject.proto ////////////////////
static
CYTHON_INLINE
int
__Pyx_PyByteArray_AppendObject
(
PyObject
*
bytearray
,
PyObject
*
value
);
...
...
Cython/Utility/TypeConversion.c
View file @
b6fd9655
...
...
@@ -579,7 +579,7 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value) {
static
CYTHON_INLINE
PyObject
*
{{
TO_PY_FUNCTION
}}({{
TYPE
}}
value
,
Py_ssize_t
width
,
char
padding_char
,
char
format_char
);
/////////////// CIntToPyUnicode ///////////////
//@requires: BuildPyUnicode
//@requires:
StringTools.c::
BuildPyUnicode
// NOTE: inlining because most arguments are constant, which collapses lots of code below
...
...
@@ -642,94 +642,7 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t wid
if
(
width
>
ulength
)
{
ulength
=
width
;
}
return
__Pyx_PyUnicode_Build
(
ulength
,
dpos
,
length
,
prepend_sign
,
padding_char
);
}
/////////////// BuildPyUnicode.proto ///////////////
static
PyObject
*
__Pyx_PyUnicode_Build
(
Py_ssize_t
ulength
,
char
*
chars
,
int
clength
,
int
prepend_sign
,
char
padding_char
);
/////////////// BuildPyUnicode ///////////////
static
PyObject
*
__Pyx_PyUnicode_Build
(
Py_ssize_t
ulength
,
char
*
chars
,
int
clength
,
int
prepend_sign
,
char
padding_char
)
{
PyObject
*
uval
;
Py_ssize_t
uoffset
=
ulength
-
clength
;
#if CYTHON_USE_UNICODE_INTERNALS
Py_ssize_t
i
;
#if CYTHON_PEP393_ENABLED
// Py 3.3+ (post PEP-393)
void
*
udata
;
uval
=
PyUnicode_New
(
ulength
,
127
);
if
(
unlikely
(
!
uval
))
return
NULL
;
udata
=
PyUnicode_DATA
(
uval
);
#else
// Py 2.x/3.2 (pre PEP-393)
Py_UNICODE
*
udata
;
uval
=
PyUnicode_FromUnicode
(
NULL
,
ulength
);
if
(
unlikely
(
!
uval
))
return
NULL
;
udata
=
PyUnicode_AS_UNICODE
(
uval
);
#endif
if
(
uoffset
>
0
)
{
i
=
0
;
if
(
prepend_sign
)
{
__Pyx_PyUnicode_WRITE
(
PyUnicode_1BYTE_KIND
,
udata
,
0
,
'-'
);
i
++
;
}
for
(;
i
<
uoffset
;
i
++
)
{
__Pyx_PyUnicode_WRITE
(
PyUnicode_1BYTE_KIND
,
udata
,
i
,
padding_char
);
}
}
for
(
i
=
0
;
i
<
clength
;
i
++
)
{
__Pyx_PyUnicode_WRITE
(
PyUnicode_1BYTE_KIND
,
udata
,
uoffset
+
i
,
chars
[
i
]);
}
#else
// non-CPython
{
uval
=
NULL
;
PyObject
*
sign
=
NULL
,
*
padding
=
NULL
;
if
(
uoffset
>
0
)
{
prepend_sign
=
!!
prepend_sign
;
if
(
uoffset
>
prepend_sign
)
{
padding
=
PyUnicode_FromOrdinal
(
padding_char
);
if
(
likely
(
padding
)
&&
uoffset
>
prepend_sign
+
1
)
{
PyObject
*
tmp
;
PyObject
*
repeat
=
PyInt_FromSize_t
(
uoffset
-
prepend_sign
);
if
(
unlikely
(
!
repeat
))
goto
done_or_error
;
tmp
=
PyNumber_Multiply
(
padding
,
repeat
);
Py_DECREF
(
repeat
);
Py_DECREF
(
padding
);
padding
=
tmp
;
}
if
(
unlikely
(
!
padding
))
goto
done_or_error
;
}
if
(
prepend_sign
)
{
sign
=
PyUnicode_FromOrdinal
(
'-'
);
if
(
unlikely
(
!
sign
))
goto
done_or_error
;
}
}
uval
=
PyUnicode_DecodeASCII
(
chars
,
clength
,
NULL
);
if
(
likely
(
uval
)
&&
padding
)
{
PyObject
*
tmp
=
PyNumber_Add
(
padding
,
uval
);
Py_DECREF
(
uval
);
uval
=
tmp
;
}
if
(
likely
(
uval
)
&&
sign
)
{
PyObject
*
tmp
=
PyNumber_Add
(
sign
,
uval
);
Py_DECREF
(
uval
);
uval
=
tmp
;
}
done_or_error:
Py_XDECREF
(
padding
);
Py_XDECREF
(
sign
);
}
#endif
return
uval
;
return
__Pyx_PyUnicode_BuildFromAscii
(
ulength
,
dpos
,
length
,
prepend_sign
,
padding_char
);
}
...
...
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