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
Gwenaël Samain
cython
Commits
9f057897
Commit
9f057897
authored
Feb 09, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
externalise some utility code functions
parent
854219a4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
49 deletions
+44
-49
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+4
-49
Cython/Utility/Builtins.c
Cython/Utility/Builtins.c
+40
-0
No files found.
Cython/Compiler/Builtin.py
View file @
9f057897
...
...
@@ -6,56 +6,11 @@ from Symtab import BuiltinScope, StructOrUnionScope
from
Code
import
UtilityCode
from
TypeSlots
import
Signature
import
PyrexTypes
import
Naming
import
Options
# C-level implementations of builtin types, functions and methods
pow2_utility_code
=
UtilityCode
(
proto
=
"""
#define __Pyx_PyNumber_Power2(a, b) PyNumber_Power(a, b, Py_None)
"""
)
abs_int_utility_code
=
UtilityCode
(
proto
=
'''
static CYTHON_INLINE unsigned int __Pyx_abs_int(int x) {
if (unlikely(x == -INT_MAX-1))
return ((unsigned int)INT_MAX) + 1U;
return (unsigned int) abs(x);
}
'''
)
abs_long_utility_code
=
UtilityCode
(
proto
=
'''
static CYTHON_INLINE unsigned long __Pyx_abs_long(long x) {
if (unlikely(x == -LONG_MAX-1))
return ((unsigned long)LONG_MAX) + 1U;
return (unsigned long) labs(x);
}
'''
)
abs_longlong_utility_code
=
UtilityCode
(
proto
=
'''
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_abs_longlong(PY_LONG_LONG x) {
#ifndef PY_LLONG_MAX
#ifdef LLONG_MAX
const PY_LONG_LONG PY_LLONG_MAX = LLONG_MAX;
#else
// copied from pyport.h in CPython 3.3, missing in 2.4
const PY_LONG_LONG PY_LLONG_MAX = (1 + 2 * ((1LL << (CHAR_BIT * sizeof(PY_LONG_LONG) - 2)) - 1));
#endif
#endif
if (unlikely(x == -PY_LLONG_MAX-1))
return ((unsigned PY_LONG_LONG)PY_LLONG_MAX) + 1U;
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
return (unsigned PY_LONG_LONG) llabs(x);
#else
return (x<0) ? (unsigned PY_LONG_LONG)-x : (unsigned PY_LONG_LONG)x;
#endif
}
'''
)
iter_next_utility_code
=
UtilityCode
.
load_cached
(
"IterNext"
,
"ObjectHandling.c"
)
getattr3_utility_code
=
UtilityCode
.
load_cached
(
"GetAttr3"
,
"Builtins.c"
)
pyexec_utility_code
=
UtilityCode
.
load_cached
(
"PyExec"
,
"Builtins.c"
)
...
...
@@ -178,21 +133,21 @@ builtin_function_table = [
BuiltinFunction
(
'abs'
,
"f"
,
"f"
,
"fabsf"
,
is_strict_signature
=
True
),
BuiltinFunction
(
'abs'
,
None
,
None
,
"__Pyx_abs_int"
,
utility_code
=
abs_int_utility_code
,
utility_code
=
UtilityCode
.
load
(
"abs_int"
,
"Builtins.c"
)
,
func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_uint_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"arg"
,
PyrexTypes
.
c_int_type
,
None
)
],
is_strict_signature
=
True
)),
BuiltinFunction
(
'abs'
,
None
,
None
,
"__Pyx_abs_long"
,
utility_code
=
abs_long_utility_code
,
utility_code
=
UtilityCode
.
load
(
"abs_long"
,
"Builtins.c"
)
,
func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_ulong_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"arg"
,
PyrexTypes
.
c_long_type
,
None
)
],
is_strict_signature
=
True
)),
BuiltinFunction
(
'abs'
,
None
,
None
,
"__Pyx_abs_longlong"
,
utility_code
=
abs_longlong_utility_code
,
utility_code
=
UtilityCode
.
load
(
"abs_longlong"
,
"Builtins.c"
)
,
func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_ulonglong_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"arg"
,
PyrexTypes
.
c_longlong_type
,
None
)
...
...
@@ -246,7 +201,7 @@ builtin_function_table = [
#('ord', "", "", ""),
BuiltinFunction
(
'pow'
,
"OOO"
,
"O"
,
"PyNumber_Power"
),
BuiltinFunction
(
'pow'
,
"OO"
,
"O"
,
"__Pyx_PyNumber_Power2"
,
utility_code
=
pow2_utility_code
),
utility_code
=
UtilityCode
.
load
(
"pow2"
,
"Builtins.c"
)
),
#('range', "", "", ""),
#('raw_input', "", "", ""),
#('reduce', "", "", ""),
...
...
Cython/Utility/Builtins.c
View file @
9f057897
...
...
@@ -203,3 +203,43 @@ static PyObject* __Pyx_Intern(PyObject* s) {
#endif
return
s
;
}
//////////////////// abs_int.proto ////////////////////
static
CYTHON_INLINE
unsigned
int
__Pyx_abs_int
(
int
x
)
{
if
(
unlikely
(
x
==
-
INT_MAX
-
1
))
return
((
unsigned
int
)
INT_MAX
)
+
1U
;
return
(
unsigned
int
)
abs
(
x
);
}
//////////////////// abs_long.proto ////////////////////
static
CYTHON_INLINE
unsigned
long
__Pyx_abs_long
(
long
x
)
{
if
(
unlikely
(
x
==
-
LONG_MAX
-
1
))
return
((
unsigned
long
)
LONG_MAX
)
+
1U
;
return
(
unsigned
long
)
labs
(
x
);
}
//////////////////// abs_longlong.proto ////////////////////
static
CYTHON_INLINE
unsigned
PY_LONG_LONG
__Pyx_abs_longlong
(
PY_LONG_LONG
x
)
{
#ifndef PY_LLONG_MAX
#ifdef LLONG_MAX
const
PY_LONG_LONG
PY_LLONG_MAX
=
LLONG_MAX
;
#else
// copied from pyport.h in CPython 3.3, missing in 2.4
const
PY_LONG_LONG
PY_LLONG_MAX
=
(
1
+
2
*
((
1LL
<<
(
CHAR_BIT
*
sizeof
(
PY_LONG_LONG
)
-
2
))
-
1
));
#endif
#endif
if
(
unlikely
(
x
==
-
PY_LLONG_MAX
-
1
))
return
((
unsigned
PY_LONG_LONG
)
PY_LLONG_MAX
)
+
1U
;
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
return
(
unsigned
PY_LONG_LONG
)
llabs
(
x
);
#else
return
(
x
<
0
)
?
(
unsigned
PY_LONG_LONG
)
-
x
:
(
unsigned
PY_LONG_LONG
)
x
;
#endif
}
//////////////////// pow2.proto ////////////////////
#define __Pyx_PyNumber_Power2(a, b) PyNumber_Power(a, b, Py_None)
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