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
ba00ebef
Commit
ba00ebef
authored
Feb 12, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplicated file path handling code when generating file path tables.
parent
f03092b1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
49 deletions
+15
-49
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+3
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-9
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+5
-17
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+2
-20
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+4
-1
No files found.
Cython/Compiler/Code.py
View file @
ba00ebef
...
@@ -1437,12 +1437,13 @@ class GlobalState(object):
...
@@ -1437,12 +1437,13 @@ class GlobalState(object):
#
#
def
lookup_filename
(
self
,
source_desc
):
def
lookup_filename
(
self
,
source_desc
):
entry
=
source_desc
.
get_filenametable_entry
()
try
:
try
:
index
=
self
.
filename_table
[
source_desc
.
get_filenametable_entry
()
]
index
=
self
.
filename_table
[
entry
]
except
KeyError
:
except
KeyError
:
index
=
len
(
self
.
filename_list
)
index
=
len
(
self
.
filename_list
)
self
.
filename_list
.
append
(
source_desc
)
self
.
filename_list
.
append
(
source_desc
)
self
.
filename_table
[
source_desc
.
get_filenametable_entry
()
]
=
index
self
.
filename_table
[
entry
]
=
index
return
index
return
index
def
commented_file_contents
(
self
,
source_desc
):
def
commented_file_contents
(
self
,
source_desc
):
...
...
Cython/Compiler/ExprNodes.py
View file @
ba00ebef
...
@@ -9047,15 +9047,7 @@ class CodeObjectNode(ExprNode):
...
@@ -9047,15 +9047,7 @@ class CodeObjectNode(ExprNode):
func_name
=
code
.
get_py_string_const
(
func_name
=
code
.
get_py_string_const
(
func
.
name
,
identifier
=
True
,
is_str
=
False
,
unicode_value
=
func
.
name
)
func
.
name
,
identifier
=
True
,
is_str
=
False
,
unicode_value
=
func
.
name
)
# FIXME: better way to get the module file path at module init time? Encoding to use?
# FIXME: better way to get the module file path at module init time? Encoding to use?
file_abspath
=
func
.
pos
[
0
].
get_filenametable_entry
()
file_path
=
StringEncoding
.
bytes_literal
(
func
.
pos
[
0
].
get_filenametable_entry
().
encode
(
'utf8'
),
'utf8'
)
# Prefer relative paths to current directory (which is most likely the project root)
# over absolute paths.
workdir
=
os
.
getcwd
()
+
os
.
sep
if
file_abspath
.
startswith
(
workdir
):
file_path
=
file_abspath
[
len
(
workdir
):]
else
:
file_path
=
file_abspath
file_path
=
StringEncoding
.
bytes_literal
(
file_path
.
encode
(
'utf8'
),
'utf8'
)
file_path_const
=
code
.
get_py_string_const
(
file_path
,
identifier
=
False
,
is_str
=
True
)
file_path_const
=
code
.
get_py_string_const
(
file_path
,
identifier
=
False
,
is_str
=
True
)
flags
=
[]
flags
=
[]
...
...
Cython/Compiler/ModuleNode.py
View file @
ba00ebef
...
@@ -739,27 +739,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -739,27 +739,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln_openmp
(
"#include <omp.h>"
)
code
.
putln_openmp
(
"#include <omp.h>"
)
def
generate_filename_table
(
self
,
code
):
def
generate_filename_table
(
self
,
code
):
import
os.path
as
path
from
os.path
import
isabs
,
basename
full_module_path
=
path
.
join
(
*
self
.
full_module_name
.
split
(
'.'
))
module_abspath
=
path
.
splitext
(
path
.
abspath
(
self
.
compilation_source
.
source_desc
.
get_filenametable_entry
()))[
0
]
root_path
=
module_abspath
[:
-
len
(
full_module_path
)]
workdir
=
path
.
abspath
(
os
.
getcwd
())
+
os
.
sep
if
root_path
.
startswith
(
workdir
):
# prefer relative paths to current directory (which is most likely the project root)
root_path
=
workdir
code
.
putln
(
""
)
code
.
putln
(
""
)
code
.
putln
(
"static const char *%s[] = {"
%
Naming
.
filetable_cname
)
code
.
putln
(
"static const char *%s[] = {"
%
Naming
.
filetable_cname
)
if
code
.
globalstate
.
filename_list
:
if
code
.
globalstate
.
filename_list
:
for
source_desc
in
code
.
globalstate
.
filename_list
:
for
source_desc
in
code
.
globalstate
.
filename_list
:
file_abspath
=
path
.
abspath
(
source_desc
.
get_filenametable_entry
())
file_path
=
source_desc
.
get_filenametable_entry
()
if
file_abspath
.
startswith
(
root_path
):
if
isabs
(
file_path
):
filename
=
file_abspath
[
len
(
root_path
):]
file_path
=
basename
(
file_path
)
# never include absolute paths
else
:
escaped_filename
=
file_path
.
replace
(
"
\
\
"
,
"
\
\
\
\
"
).
replace
(
'"'
,
r'\"'
)
filename
=
path
.
basename
(
file_abspath
)
escaped_filename
=
filename
.
replace
(
"
\
\
"
,
"
\
\
\
\
"
).
replace
(
'"'
,
r'\"'
)
code
.
putln
(
'"%s",'
%
escaped_filename
)
code
.
putln
(
'"%s",'
%
escaped_filename
)
else
:
else
:
# Some C compilers don't like an empty array
# Some C compilers don't like an empty array
...
...
Cython/Compiler/Nodes.py
View file @
ba00ebef
...
@@ -10,7 +10,7 @@ cython.declare(sys=object, os=object, copy=object,
...
@@ -10,7 +10,7 @@ cython.declare(sys=object, os=object, copy=object,
py_object_type
=
object
,
ModuleScope
=
object
,
LocalScope
=
object
,
ClosureScope
=
object
,
py_object_type
=
object
,
ModuleScope
=
object
,
LocalScope
=
object
,
ClosureScope
=
object
,
StructOrUnionScope
=
object
,
PyClassScope
=
object
,
StructOrUnionScope
=
object
,
PyClassScope
=
object
,
CppClassScope
=
object
,
UtilityCode
=
object
,
EncodedString
=
object
,
CppClassScope
=
object
,
UtilityCode
=
object
,
EncodedString
=
object
,
absolute_path_length
=
cython
.
Py_ssize_t
,
error_type
=
object
,
_py_int_types
=
object
)
error_type
=
object
,
_py_int_types
=
object
)
import
sys
,
os
,
copy
import
sys
,
os
,
copy
from
itertools
import
chain
from
itertools
import
chain
...
@@ -30,7 +30,6 @@ from . import Options
...
@@ -30,7 +30,6 @@ from . import Options
from
.
import
DebugFlags
from
.
import
DebugFlags
from
..Utils
import
add_metaclass
from
..Utils
import
add_metaclass
absolute_path_length
=
0
if
sys
.
version_info
[
0
]
>=
3
:
if
sys
.
version_info
[
0
]
>=
3
:
_py_int_types
=
int
_py_int_types
=
int
...
@@ -39,25 +38,8 @@ else:
...
@@ -39,25 +38,8 @@ else:
def
relative_position
(
pos
):
def
relative_position
(
pos
):
"""
return
(
pos
[
0
].
get_filenametable_entry
(),
pos
[
1
])
We embed the relative filename in the generated C file, since we
don't want to have to regenerate and compile all the source code
whenever the Python install directory moves (which could happen,
e.g,. when distributing binaries.)
INPUT:
a position tuple -- (absolute filename, line number column position)
OUTPUT:
relative filename
line number
AUTHOR: William Stein
"""
global
absolute_path_length
if
absolute_path_length
==
0
:
absolute_path_length
=
len
(
os
.
path
.
abspath
(
os
.
getcwd
()))
return
(
pos
[
0
].
get_filenametable_entry
()[
absolute_path_length
+
1
:],
pos
[
1
])
def
embed_position
(
pos
,
docstring
):
def
embed_position
(
pos
,
docstring
):
if
not
Options
.
embed_pos_in_docstring
:
if
not
Options
.
embed_pos_in_docstring
:
...
...
Cython/Compiler/Scanning.py
View file @
ba00ebef
...
@@ -201,6 +201,9 @@ class FileSourceDescriptor(SourceDescriptor):
...
@@ -201,6 +201,9 @@ class FileSourceDescriptor(SourceDescriptor):
filename
=
Utils
.
decode_filename
(
filename
)
filename
=
Utils
.
decode_filename
(
filename
)
self
.
path_description
=
path_description
or
filename
self
.
path_description
=
path_description
or
filename
self
.
filename
=
filename
self
.
filename
=
filename
# Prefer relative paths to current directory (which is most likely the project root) over absolute paths.
workdir
=
os
.
path
.
abspath
(
'.'
)
+
os
.
sep
self
.
file_path
=
filename
[
len
(
workdir
):]
if
filename
.
startswith
(
workdir
)
else
filename
self
.
set_file_type_from_name
(
filename
)
self
.
set_file_type_from_name
(
filename
)
self
.
_cmp_name
=
filename
self
.
_cmp_name
=
filename
self
.
_lines
=
{}
self
.
_lines
=
{}
...
@@ -242,7 +245,7 @@ class FileSourceDescriptor(SourceDescriptor):
...
@@ -242,7 +245,7 @@ class FileSourceDescriptor(SourceDescriptor):
return
path
return
path
def
get_filenametable_entry
(
self
):
def
get_filenametable_entry
(
self
):
return
self
.
file
name
return
self
.
file
_path
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
isinstance
(
other
,
FileSourceDescriptor
)
and
self
.
filename
==
other
.
filename
return
isinstance
(
other
,
FileSourceDescriptor
)
and
self
.
filename
==
other
.
filename
...
...
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