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
33c46958
Commit
33c46958
authored
Apr 22, 2010
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom from_py converter for Py_UNICODE
parent
22894f9a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletion
+51
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+26
-1
tests/run/py_unicode_type.pyx
tests/run/py_unicode_type.pyx
+25
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
33c46958
...
...
@@ -828,7 +828,7 @@ class CIntType(CNumericType):
type_name
=
type_name
.
replace
(
"PY_LONG_LONG"
,
"long long"
)
SignWord
=
sign_word
.
title
()
TypeName
=
type_name
.
title
().
replace
(
" "
,
""
)
if
"Long"
in
TypeName
:
if
self
.
rank
>=
list
(
rank_to_type_name
).
index
(
'long'
)
:
utility_code
=
c_long_from_py_function
else
:
utility_code
=
c_int_from_py_function
...
...
@@ -874,6 +874,7 @@ class CPyUnicodeIntType(CIntType):
# 1114111, so PyInt_FromLong() will do just fine here.
to_py_function
=
"PyInt_FromLong"
from_py_function
=
"__Pyx_PyInt_AsPy_UNICODE"
def
sign_and_name
(
self
):
return
"Py_UNICODE"
...
...
@@ -2491,6 +2492,10 @@ type_conversion_predeclarations = """
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
#ifdef Py_USING_UNICODE
static CYTHON_INLINE Py_UNICODE __Pyx_PyInt_AsPy_UNICODE(PyObject*);
#endif
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
...
...
@@ -2555,6 +2560,26 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
return res;
}
#ifdef Py_USING_UNICODE
static CYTHON_INLINE Py_UNICODE __Pyx_PyInt_AsPy_UNICODE(PyObject* x) {
long ival = __Pyx_PyInt_AsLong(x);
static long maxval = 0;
if (unlikely(!maxval))
maxval = (long)PyUnicode_GetMax();
if (unlikely(ival < 0)) {
if (!PyErr_Occurred())
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to Py_UNICODE");
return (Py_UNICODE)-1;
} else if (unlikely(ival > maxval)) {
PyErr_SetString(PyExc_OverflowError,
"value too large to convert to Py_UNICODE");
return (Py_UNICODE)-1;
}
return (Py_UNICODE)ival;
}
#endif
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
Py_ssize_t ival;
PyObject* x = PyNumber_Index(b);
...
...
tests/run/py_unicode_type.pyx
View file @
33c46958
...
...
@@ -42,3 +42,28 @@ def index_literal(int i):
# runtime casts are not currently supported
#return <Py_UNICODE>(u"12345"[i])
return
u"12345"
[
i
]
def
unicode_cardinal
(
Py_UNICODE
i
):
"""
>>> import sys
>>> unicode_cardinal(0)
0
>>> unicode_cardinal(1)
1
>>> unicode_cardinal(sys.maxunicode) == sys.maxunicode
True
>>> unicode_cardinal(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> unicode_cardinal(sys.maxunicode+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
"""
return
i
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