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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
ec25a63e
Commit
ec25a63e
authored
Jan 17, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
7035d3e1
279557ca
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
126 additions
and
134 deletions
+126
-134
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-6
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+1
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+3
-3
Cython/Plex/Regexps.py
Cython/Plex/Regexps.py
+1
-1
pyximport/pyxbuild.py
pyximport/pyxbuild.py
+1
-1
pyximport/pyximport.py
pyximport/pyximport.py
+114
-122
No files found.
Cython/Compiler/ExprNodes.py
View file @
ec25a63e
...
@@ -2353,12 +2353,12 @@ class SimpleCallNode(CallNode):
...
@@ -2353,12 +2353,12 @@ class SimpleCallNode(CallNode):
"Python object cannot be passed as a varargs parameter"
)
"Python object cannot be passed as a varargs parameter"
)
# Calc result type and code fragment
# Calc result type and code fragment
self
.
type
=
func_type
.
return_type
self
.
type
=
func_type
.
return_type
if
self
.
type
.
is_pyobject
\
or
func_type
.
exception_value
is
not
None
\
or
func_type
.
exception_check
:
self
.
is_temp
=
1
if
self
.
type
.
is_pyobject
:
if
self
.
type
.
is_pyobject
:
self
.
result_ctype
=
py_object_type
self
.
result_ctype
=
py_object_type
self
.
is_temp
=
1
elif
func_type
.
exception_value
is
not
None
\
or
func_type
.
exception_check
:
self
.
is_temp
=
1
# C++ exception handler
# C++ exception handler
if
func_type
.
exception_check
==
'+'
:
if
func_type
.
exception_check
==
'+'
:
if
func_type
.
exception_value
is
None
:
if
func_type
.
exception_value
is
None
:
...
...
Cython/Compiler/PyrexTypes.py
View file @
ec25a63e
...
@@ -517,7 +517,7 @@ class CIntType(CNumericType):
...
@@ -517,7 +517,7 @@ class CIntType(CNumericType):
c_type
=
self
.
sign_and_name
()
c_type
=
self
.
sign_and_name
()
c_name
=
c_type
.
replace
(
' '
,
'_'
);
c_name
=
c_type
.
replace
(
' '
,
'_'
);
func_name
=
"__pyx_PyInt_%s"
%
c_name
;
func_name
=
"__pyx_PyInt_%s"
%
c_name
;
if
not
int_conversion_list
.
has_key
(
func_name
)
:
if
func_name
not
in
int_conversion_list
:
# no env to add utility code to
# no env to add utility code to
global
type_conversion_predeclarations
,
type_conversion_functions
global
type_conversion_predeclarations
,
type_conversion_functions
if
self
.
signed
:
if
self
.
signed
:
...
...
Cython/Compiler/Symtab.py
View file @
ec25a63e
...
@@ -282,8 +282,8 @@ class Scope:
...
@@ -282,8 +282,8 @@ class Scope:
if not self.in_cinclude and cname and re.match("
^
_
[
_A
-
Z
]
+
$
", cname):
if not self.in_cinclude and cname and re.match("
^
_
[
_A
-
Z
]
+
$
", cname):
# See http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html#Reserved-Names
# See http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html#Reserved-Names
warning(pos, "'%s'
is
a
reserved
name
in
C
.
" % cname, -1)
warning(pos, "'%s'
is
a
reserved
name
in
C
.
" % cname, -1)
dict
= self.entries
entries
= self.entries
if name and
dict.has_key(name)
:
if name and
name in entries
:
if visibility == 'extern':
if visibility == 'extern':
warning(pos, "'%s'
redeclared
" % name, 0)
warning(pos, "'%s'
redeclared
" % name, 0)
elif visibility != 'ignore':
elif visibility != 'ignore':
...
@@ -292,7 +292,7 @@ class Scope:
...
@@ -292,7 +292,7 @@ class Scope:
entry.in_cinclude = self.in_cinclude
entry.in_cinclude = self.in_cinclude
if name:
if name:
entry.qualified_name = self.qualify_name(name)
entry.qualified_name = self.qualify_name(name)
dict
[name] = entry
entries
[name] = entry
entry.scope = self
entry.scope = self
entry.visibility = visibility
entry.visibility = visibility
return entry
return entry
...
...
Cython/Plex/Regexps.py
View file @
ec25a63e
...
@@ -83,7 +83,7 @@ def CodeRanges(code_list):
...
@@ -83,7 +83,7 @@ def CodeRanges(code_list):
re_list
=
[]
re_list
=
[]
for
i
in
xrange
(
0
,
len
(
code_list
),
2
):
for
i
in
xrange
(
0
,
len
(
code_list
),
2
):
re_list
.
append
(
CodeRange
(
code_list
[
i
],
code_list
[
i
+
1
]))
re_list
.
append
(
CodeRange
(
code_list
[
i
],
code_list
[
i
+
1
]))
return
apply
(
Alt
,
tuple
(
re_list
)
)
return
Alt
(
*
re_list
)
def
CodeRange
(
code1
,
code2
):
def
CodeRange
(
code1
,
code2
):
"""
"""
...
...
pyximport/pyxbuild.py
View file @
ec25a63e
...
@@ -3,7 +3,7 @@ the installed distutils infrastructure. Call:
...
@@ -3,7 +3,7 @@ the installed distutils infrastructure. Call:
out_fname = pyx_to_dll("foo.pyx")
out_fname = pyx_to_dll("foo.pyx")
"""
"""
import
os
,
md5
import
os
import
distutils
import
distutils
from
distutils.dist
import
Distribution
from
distutils.dist
import
Distribution
...
...
pyximport/pyximport.py
View file @
ec25a63e
"""
"""
Import hooks; when installed
(with the install()
) function, these hooks
Import hooks; when installed
with the install(
) function, these hooks
allow importing .pyx files as if they were Python modules.
allow importing .pyx files as if they were Python modules.
If you want the hook installed every time you run Python
If you want the hook installed every time you run Python
you can add it to your Python version by adding these lines to
you can add it to your Python version by adding these lines to
sitecustomize.py (which you can create from scratch in site-packages
sitecustomize.py (which you can create from scratch in site-packages
if it doesn't exist there
are somewhere else on your python path)
if it doesn't exist there
or somewhere else on your python path)::
import pyximport
import pyximport
pyximport.install()
pyximport.install()
For instance on
the Mac with Python 2.3 built from CVS, you could
For instance on
the Mac with a non-system Python 2.3, you could create
create
sitecustomize.py with only those two lines at
sitecustomize.py with only those two lines at
/usr/local/lib/python2.3/site-packages/sitecustomize.py .
/usr/local/lib/python2.3/site-packages/sitecustomize.py .
Running this module as a top-level script will run a test and then print
Running this module as a top-level script will run a test and then print
the documentation.
the documentation.
This code
was modeled on Quixote's ptl_import
.
This code
is based on the Py2.3+ import protocol as described in PEP 302
.
"""
"""
import
sys
,
os
,
shutil
import
sys
import
imp
,
ihooks
,
glob
import
os
import
__builtin__
import
glob
import
imp
import
pyxbuild
import
pyxbuild
from
distutils.dep_util
import
newer
from
distutils.dep_util
import
newer
from
distutils.extension
import
Extension
from
distutils.extension
import
Extension
...
@@ -33,19 +34,11 @@ except ImportError:
...
@@ -33,19 +34,11 @@ except ImportError:
mod_name
=
"pyximport"
mod_name
=
"pyximport"
assert
sys
.
hexversion
>=
0x20
000b1
,
"need Python 2.0b1
or later"
assert
sys
.
hexversion
>=
0x20
30000
,
"need Python 2.3
or later"
PYX_FILE_TYPE
=
1011
PYX_EXT
=
".pyx"
PYX_EXT
=
".pyx"
PYXDEP_EXT
=
".pyxdep"
PYXDEP_EXT
=
".pyxdep"
PYXBLD_EXT
=
".pyxbld"
PYXBLD_EXT
=
".pyxbld"
_test_files
=
[]
class
PyxHooks
(
ihooks
.
Hooks
):
"""Import hook that declares our suffixes. Let install() install it."""
def
get_suffixes
(
self
):
# add our suffixes
return
imp
.
get_suffixes
()
+
[(
PYX_EXT
,
"r"
,
PYX_FILE_TYPE
)]
# Performance problem: for every PYX file that is imported, we will
# Performance problem: for every PYX file that is imported, we will
# invoke the whole distutils infrastructure even if the module is
# invoke the whole distutils infrastructure even if the module is
...
@@ -58,15 +51,11 @@ def _load_pyrex(name, filename):
...
@@ -58,15 +51,11 @@ def _load_pyrex(name, filename):
"Load a pyrex file given a name and filename."
"Load a pyrex file given a name and filename."
def
get_distutils_extension
(
modname
,
pyxfilename
):
def
get_distutils_extension
(
modname
,
pyxfilename
):
extra
=
"_"
+
hashlib
.
md5
(
open
(
pyxfilename
).
read
()).
hexdigest
()
extra
=
"_"
+
hashlib
.
md5
(
open
(
pyxfilename
).
read
()).
hexdigest
()
# modname = modname + extra
# modname = modname + extra
extension_mod
=
handle_special_build
(
modname
,
pyxfilename
)
extension_mod
=
handle_special_build
(
modname
,
pyxfilename
)
if
not
extension_mod
:
if
not
extension_mod
:
extension_mod
=
Extension
(
name
=
modname
,
sources
=
[
pyxfilename
])
extension_mod
=
Extension
(
name
=
modname
,
sources
=
[
pyxfilename
])
return
extension_mod
return
extension_mod
def
handle_special_build
(
modname
,
pyxfilename
):
def
handle_special_build
(
modname
,
pyxfilename
):
...
@@ -147,53 +136,64 @@ def load_module(name, pyxfilename):
...
@@ -147,53 +136,64 @@ def load_module(name, pyxfilename):
assert
mod
.
__file__
==
so_path
,
(
mod
.
__file__
,
so_path
)
assert
mod
.
__file__
==
so_path
,
(
mod
.
__file__
,
so_path
)
return
mod
return
mod
class
PyxLoader
(
ihooks
.
ModuleLoader
):
"""Load a module. It checks whether a file is a .pyx and returns it.
Otherwise it lets the ihooks base class handle it. Let install()
install it."""
def
load_module
(
self
,
name
,
stuff
):
# If it's a Pyrex file, load it specially.
if
stuff
[
2
][
2
]
==
PYX_FILE_TYPE
:
file
,
pyxfilename
,
info
=
stuff
(
suff
,
mode
,
type
)
=
info
if
file
:
file
.
close
()
return
load_module
(
name
,
pyxfilename
)
else
:
# Otherwise, use the default handler for loading
return
ihooks
.
ModuleLoader
.
load_module
(
self
,
name
,
stuff
)
try
:
# import hooks
import
cimport
except
ImportError
:
class
PyxImporter
(
object
):
cimport
=
None
def
__init__
(
self
,
so_cache_dir
):
self
.
so_cache_dir
=
so_cache_dir
class
cModuleImporter
(
ihooks
.
ModuleImporter
):
self
.
so_name_cache
=
{}
"""This was just left in from the Quixote implementation. I think
it allows a performance enhancement if you have the cimport module
def
find_module
(
self
,
fullname
,
package_path
=
None
):
from Quixote. Let install() install it."""
print
"SEARCHING"
,
fullname
,
package_path
def
__init__
(
self
,
loader
=
None
):
if
'.'
in
fullname
:
self
.
loader
=
loader
or
ihooks
.
ModuleLoader
()
mod_parts
=
fullname
.
split
(
'.'
)
cimport
.
set_loader
(
self
.
find_import_module
)
package
=
'.'
.
join
(
mod_parts
[:
-
1
])
module_name
=
mod_parts
[
-
1
]
def
find_import_module
(
self
,
fullname
,
subname
,
path
):
else
:
stuff
=
self
.
loader
.
find_module
(
subname
,
path
)
package
=
None
if
not
stuff
:
module_name
=
fullname
pyx_module_name
=
module_name
+
PYX_EXT
# this may work, but it returns the file content, not its path
#import pkgutil
#pyx_source = pkgutil.get_data(package, pyx_module_name)
if
package_path
:
paths
=
package_path
else
:
paths
=
sys
.
path
join_path
=
os
.
path
.
join
is_file
=
os
.
path
.
isfile
for
path
in
filter
(
os
.
path
.
isdir
,
paths
):
for
filename
in
os
.
listdir
(
path
):
if
filename
==
pyx_module_name
:
return
PyxLoader
(
fullname
,
join_path
(
path
,
filename
))
elif
filename
==
module_name
:
package_path
=
join_path
(
path
,
filename
)
init_path
=
join_path
(
package_path
,
'__init__'
+
PYX_EXT
)
if
is_file
(
init_path
):
return
PyxLoader
(
fullname
,
package_path
,
init_path
)
# not found, normal package, not a .pyx file, none of our business
return
None
return
None
return
self
.
loader
.
load_module
(
fullname
,
stuff
)
def
install
(
self
):
class
PyxLoader
(
object
):
self
.
save_import_module
=
__builtin__
.
__import__
def
__init__
(
self
,
fullname
,
path
,
init_path
=
None
):
self
.
save_reload
=
__builtin__
.
reload
self
.
fullname
,
self
.
path
,
self
.
init_path
=
fullname
,
path
,
init_path
if
not
hasattr
(
__builtin__
,
'unload'
):
__builtin__
.
unload
=
None
def
load_module
(
self
,
fullname
):
self
.
save_unload
=
__builtin__
.
unload
assert
self
.
fullname
==
fullname
,
(
__builtin__
.
__import__
=
cimport
.
import_module
"invalid module, expected %s, got %s"
%
(
__builtin__
.
reload
=
cimport
.
reload_module
self
.
fullname
,
fullname
))
__builtin__
.
unload
=
self
.
unload
if
self
.
init_path
:
# package
print
"PACKAGE"
,
fullname
module
=
load_module
(
fullname
,
self
.
init_path
)
module
.
__path__
=
[
self
.
path
]
else
:
print
"MODULE"
,
fullname
module
=
load_module
(
fullname
,
self
.
path
)
return
module
_installed
=
0
def
install
():
def
install
():
"""Main entry point. call this to install the import hook in your
"""Main entry point. call this to install the import hook in your
...
@@ -201,22 +201,14 @@ def install():
...
@@ -201,22 +201,14 @@ def install():
you use Python, add it to your sitecustomize (as described above).
you use Python, add it to your sitecustomize (as described above).
"""
"""
global
_installed
for
importer
in
sys
.
meta_path
:
if
not
_installed
:
if
isinstance
(
importer
,
PyxImporter
):
hooks
=
PyxHooks
()
return
loader
=
PyxLoader
(
hooks
)
importer
=
PyxImporter
(
'~/.pyxbuild'
)
if
cimport
is
not
None
:
sys
.
meta_path
.
append
(
importer
)
importer
=
cModuleImporter
(
loader
)
else
:
importer
=
ihooks
.
ModuleImporter
(
loader
)
# MAIN
ihooks
.
install
(
importer
)
_installed
=
1
def
on_remove_file_error
(
func
,
path
,
excinfo
):
print
"Sorry! Could not remove a temp file:"
,
path
print
"Extra information."
print
func
,
excinfo
print
"You may want to delete this yourself when you get a chance."
def
show_docs
():
def
show_docs
():
import
__main__
import
__main__
...
...
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