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
ad774681
Commit
ad774681
authored
Jul 08, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved GetItemInt_Unicode*() utility functions to StringTools.c
parent
56ce8fcb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
44 deletions
+47
-44
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+2
-44
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+45
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
ad774681
...
@@ -3099,7 +3099,8 @@ class IndexNode(ExprNode):
...
@@ -3099,7 +3099,8 @@ class IndexNode(ExprNode):
assert
self
.
index
.
type
.
is_int
assert
self
.
index
.
type
.
is_int
index_code
=
self
.
index
.
result
()
index_code
=
self
.
index
.
result
()
function
=
"__Pyx_GetItemInt_Unicode"
function
=
"__Pyx_GetItemInt_Unicode"
code
.
globalstate
.
use_utility_code
(
getitem_int_pyunicode_utility_code
)
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"GetItemIntUnicode"
,
"StringTools.c"
))
code
.
putln
(
code
.
putln
(
"%s = %s(%s, %s%s); if (unlikely(%s == (Py_UCS4)-1)) %s;"
%
(
"%s = %s(%s, %s%s); if (unlikely(%s == (Py_UCS4)-1)) %s;"
%
(
self
.
result
(),
self
.
result
(),
...
@@ -9931,49 +9932,6 @@ requires = [raise_unbound_local_error_utility_code])
...
@@ -9931,49 +9932,6 @@ requires = [raise_unbound_local_error_utility_code])
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
getitem_int_pyunicode_utility_code
=
UtilityCode
(
proto
=
'''
#define __Pyx_GetItemInt_Unicode(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ?
\
\
__Pyx_GetItemInt_Unicode_Fast(o, i) :
\
\
__Pyx_GetItemInt_Unicode_Generic(o, to_py_func(i)))
static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i) {
Py_ssize_t length;
#if CYTHON_PEP393_ENABLED
if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return (Py_UCS4)-1;
#endif
length = __Pyx_PyUnicode_GET_LENGTH(ustring);
if (likely((0 <= i) & (i < length))) {
return __Pyx_PyUnicode_READ_CHAR(ustring, i);
} else if ((-length <= i) & (i < 0)) {
return __Pyx_PyUnicode_READ_CHAR(ustring, i + length);
} else {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return (Py_UCS4)-1;
}
}
static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Generic(PyObject* ustring, PyObject* j) {
Py_UCS4 uchar;
PyObject *uchar_string;
if (!j) return (Py_UCS4)-1;
uchar_string = PyObject_GetItem(ustring, j);
Py_DECREF(j);
if (!uchar_string) return (Py_UCS4)-1;
#if CYTHON_PEP393_ENABLED
if (unlikely(__Pyx_PyUnicode_READY(uchar_string) < 0)) {
Py_DECREF(uchar_string);
return (Py_UCS4)-1;
}
#endif
uchar = __Pyx_PyUnicode_READ_CHAR(uchar_string, 0);
Py_DECREF(uchar_string);
return uchar;
}
'''
)
#------------------------------------------------------------------------------------
raise_too_many_values_to_unpack
=
UtilityCode
.
load_cached
(
"RaiseTooManyValuesToUnpack"
,
"ObjectHandling.c"
)
raise_too_many_values_to_unpack
=
UtilityCode
.
load_cached
(
"RaiseTooManyValuesToUnpack"
,
"ObjectHandling.c"
)
raise_need_more_values_to_unpack
=
UtilityCode
.
load_cached
(
"RaiseNeedMoreValuesToUnpack"
,
"ObjectHandling.c"
)
raise_need_more_values_to_unpack
=
UtilityCode
.
load_cached
(
"RaiseNeedMoreValuesToUnpack"
,
"ObjectHandling.c"
)
tuple_unpacking_error_code
=
UtilityCode
.
load_cached
(
"UnpackTupleError"
,
"ObjectHandling.c"
)
tuple_unpacking_error_code
=
UtilityCode
.
load_cached
(
"UnpackTupleError"
,
"ObjectHandling.c"
)
...
...
Cython/Utility/StringTools.c
View file @
ad774681
...
@@ -178,3 +178,48 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq
...
@@ -178,3 +178,48 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq
}
}
#endif
#endif
}
}
//////////////////// GetItemIntUnicode.proto ////////////////////
#define __Pyx_GetItemInt_Unicode(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
__Pyx_GetItemInt_Unicode_Fast(o, i) : \
__Pyx_GetItemInt_Unicode_Generic(o, to_py_func(i)))
static
CYTHON_INLINE
Py_UCS4
__Pyx_GetItemInt_Unicode_Fast
(
PyObject
*
ustring
,
Py_ssize_t
i
);
static
CYTHON_INLINE
Py_UCS4
__Pyx_GetItemInt_Unicode_Generic
(
PyObject
*
ustring
,
PyObject
*
j
);
//////////////////// GetItemIntUnicode ////////////////////
static
CYTHON_INLINE
Py_UCS4
__Pyx_GetItemInt_Unicode_Fast
(
PyObject
*
ustring
,
Py_ssize_t
i
)
{
Py_ssize_t
length
;
#if CYTHON_PEP393_ENABLED
if
(
unlikely
(
__Pyx_PyUnicode_READY
(
ustring
)
<
0
))
return
(
Py_UCS4
)
-
1
;
#endif
length
=
__Pyx_PyUnicode_GET_LENGTH
(
ustring
);
if
(
likely
((
0
<=
i
)
&
(
i
<
length
)))
{
return
__Pyx_PyUnicode_READ_CHAR
(
ustring
,
i
);
}
else
if
((
-
length
<=
i
)
&
(
i
<
0
))
{
return
__Pyx_PyUnicode_READ_CHAR
(
ustring
,
i
+
length
);
}
else
{
PyErr_SetString
(
PyExc_IndexError
,
"string index out of range"
);
return
(
Py_UCS4
)
-
1
;
}
}
static
CYTHON_INLINE
Py_UCS4
__Pyx_GetItemInt_Unicode_Generic
(
PyObject
*
ustring
,
PyObject
*
j
)
{
Py_UCS4
uchar
;
PyObject
*
uchar_string
;
if
(
!
j
)
return
(
Py_UCS4
)
-
1
;
uchar_string
=
PyObject_GetItem
(
ustring
,
j
);
Py_DECREF
(
j
);
if
(
!
uchar_string
)
return
(
Py_UCS4
)
-
1
;
#if CYTHON_PEP393_ENABLED
if
(
unlikely
(
__Pyx_PyUnicode_READY
(
uchar_string
)
<
0
))
{
Py_DECREF
(
uchar_string
);
return
(
Py_UCS4
)
-
1
;
}
#endif
uchar
=
__Pyx_PyUnicode_READ_CHAR
(
uchar_string
,
0
);
Py_DECREF
(
uchar_string
);
return
uchar
;
}
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