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
Boxiang Sun
cython
Commits
cc786153
Commit
cc786153
authored
Jul 06, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent utility code C-#include externalisation when it contains PYIDENT() place holders
parent
785da0f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+1
-1
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+22
-9
No files found.
Cython/Compiler/Buffer.py
View file @
cc786153
...
@@ -607,7 +607,7 @@ class GetAndReleaseBufferUtilityCode(object):
...
@@ -607,7 +607,7 @@ class GetAndReleaseBufferUtilityCode(object):
proto
=
util_code
.
format_code
(
util_code
.
proto
)
proto
=
util_code
.
format_code
(
util_code
.
proto
)
impl
=
util_code
.
format_code
(
impl
=
util_code
.
format_code
(
util_code
.
inject_string_constants
(
util_code
.
impl
,
output
))
util_code
.
inject_string_constants
(
util_code
.
impl
,
output
)
[
1
]
)
proto_code
.
putln
(
proto
)
proto_code
.
putln
(
proto
)
code
.
putln
(
impl
)
code
.
putln
(
impl
)
...
...
Cython/Compiler/Code.py
View file @
cc786153
...
@@ -385,11 +385,13 @@ class UtilityCode(UtilityCodeBase):
...
@@ -385,11 +385,13 @@ class UtilityCode(UtilityCodeBase):
"""Replace 'PYIDENT("xyz")' by a constant Python identifier cname.
"""Replace 'PYIDENT("xyz")' by a constant Python identifier cname.
"""
"""
pystrings
=
re
.
findall
(
'(PYIDENT
\
(
"
([^"]+)"
\
))
'
, impl)
pystrings
=
re
.
findall
(
'(PYIDENT
\
(
"
([^"]+)"
\
))
'
, impl)
any_replacements = False
for ref, name in pystrings:
for ref, name in pystrings:
py_const = output.get_interned_identifier(
py_const = output.get_interned_identifier(
StringEncoding.EncodedString(name))
StringEncoding.EncodedString(name))
any_replacements = True
impl = impl.replace(ref, py_const.cname)
impl = impl.replace(ref, py_const.cname)
return impl
return
any_replacements,
impl
def put_code(self, output):
def put_code(self, output):
if self.requires:
if self.requires:
...
@@ -400,10 +402,14 @@ class UtilityCode(UtilityCodeBase):
...
@@ -400,10 +402,14 @@ class UtilityCode(UtilityCodeBase):
self.format_code(self.proto),
self.format_code(self.proto),
'
%
s_proto
' % self.name)
'
%
s_proto
' % self.name)
if self.impl:
if self.impl:
output['
utility_code_def
'].put_or_include(
impl = self.format_code(self.impl)
self.format_code(
is_specialised, impl = self.inject_string_constants(impl, output)
self.inject_string_constants(self.impl, output)),
if not is_specialised:
'
%
s_impl
' % self.name)
# no module specific adaptations => can be reused
output['
utility_code_def
'].put_or_include(
impl, '
%
s_impl
' % self.name)
else:
output['
utility_code_def
'].put(impl)
if self.init:
if self.init:
writer = output['
init_globals
']
writer = output['
init_globals
']
writer.putln("/* %s.init */" % self.name)
writer.putln("/* %s.init */" % self.name)
...
@@ -1530,12 +1536,19 @@ class CCodeWriter(object):
...
@@ -1530,12 +1536,19 @@ class CCodeWriter(object):
def
put_or_include
(
self
,
code
,
name
):
def
put_or_include
(
self
,
code
,
name
):
if
code
:
if
code
:
if
self
.
globalstate
.
common_utility_include_dir
and
len
(
code
)
>
1042
:
include_dir
=
self
.
globalstate
.
common_utility_include_dir
include_file
=
"%s_%s.h"
%
(
name
,
hashlib
.
md5
(
code
).
hexdigest
())
if
include_dir
and
len
(
code
)
>
1042
:
path
=
os
.
path
.
join
(
self
.
globalstate
.
common_utility_include_dir
,
include_file
)
include_file
=
"%s_%s.h"
%
(
name
,
hashlib
.
md5
(
code
).
hexdigest
())
path
=
os
.
path
.
join
(
include_dir
,
include_file
)
if
not
os
.
path
.
exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
tmp_path
=
'%s.tmp%s'
%
(
path
,
os
.
getpid
())
tmp_path
=
'%s.tmp%s'
%
(
path
,
os
.
getpid
())
open
(
tmp_path
,
'w'
).
write
(
code
)
f
=
Utils
.
open_new_file
(
tmp_path
)
try
:
f
.
write
(
code
)
finally
:
f
.
close
()
os
.
rename
(
tmp_path
,
path
)
os
.
rename
(
tmp_path
,
path
)
code
=
'#include "%s"
\
n
'
%
path
code
=
'#include "%s"
\
n
'
%
path
self
.
put
(
code
)
self
.
put
(
code
)
...
...
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