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
Xavier Thompson
cython
Commits
040f00ed
Commit
040f00ed
authored
Jun 09, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow default __alloc__ to be overriden in cypclass
parent
a560f42b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+1
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+11
-8
No files found.
Cython/Compiler/ModuleNode.py
View file @
040f00ed
...
@@ -1070,7 +1070,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1070,7 +1070,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"// Auto generating default constructor to have Python-like behaviour"
)
code
.
putln
(
"// Auto generating default constructor to have Python-like behaviour"
)
code
.
putln
(
"%s(){}"
%
type
.
cname
)
code
.
putln
(
"%s(){}"
%
type
.
cname
)
alloc_entry
=
scope
.
lookup_here
(
"<alloc>"
)
alloc_entry
=
scope
.
lookup_here
(
"<alloc>"
)
if
alloc_entry
.
is_
builtin_cmethod
:
if
alloc_entry
.
is_
default
:
code
.
putln
(
"// Generating default __alloc__ function (used for __new__ calls)"
)
code
.
putln
(
"// Generating default __alloc__ function (used for __new__ calls)"
)
code
.
putln
(
"static %s { return new %s(); }"
%
code
.
putln
(
"static %s { return new %s(); }"
%
(
alloc_entry
.
type
.
declaration_code
(
alloc_entry
.
cname
),
(
alloc_entry
.
type
.
declaration_code
(
alloc_entry
.
cname
),
...
...
Cython/Compiler/Symtab.py
View file @
040f00ed
...
@@ -139,6 +139,9 @@ class Entry(object):
...
@@ -139,6 +139,9 @@ class Entry(object):
# is_rlocked boolean Is locked with a read lock (used for cypclass)
# is_rlocked boolean Is locked with a read lock (used for cypclass)
# needs_rlock boolean The entry needs a read lock (used in autolock mode)
# needs_rlock boolean The entry needs a read lock (used in autolock mode)
# needs_wlock boolean The entry needs a write lock (used in autolock mode)
# needs_wlock boolean The entry needs a write lock (used in autolock mode)
#
# is_default boolean This entry is a compiler-generated default and
# is not user-defined (e.g default contructor)
# TODO: utility_code and utility_code_definition serves the same purpose...
# TODO: utility_code and utility_code_definition serves the same purpose...
...
@@ -213,6 +216,7 @@ class Entry(object):
...
@@ -213,6 +216,7 @@ class Entry(object):
is_rlocked
=
False
is_rlocked
=
False
needs_rlock
=
False
needs_rlock
=
False
needs_wlock
=
False
needs_wlock
=
False
is_default
=
False
def
__init__
(
self
,
name
,
cname
,
type
,
pos
=
None
,
init
=
None
):
def
__init__
(
self
,
name
,
cname
,
type
,
pos
=
None
,
init
=
None
):
self
.
name
=
name
self
.
name
=
name
...
@@ -499,11 +503,11 @@ class Scope(object):
...
@@ -499,11 +503,11 @@ class Scope(object):
if
alt_entry
.
is_inherited
:
if
alt_entry
.
is_inherited
:
previous_alternative_index
=
index
previous_alternative_index
=
index
# In a cypclass, only the predeclared default constructor
is
allowed to be redeclared.
# In a cypclass, only the predeclared default constructor
and __alloc__ are
allowed to be redeclared.
# We don't have to deal with inherited entries because they are hidden as soon as the subclass has a method
# We don't have to deal with inherited entries because they are hidden as soon as the subclass has a method
# of the same name, regardless of the exact signature (this is also C++ behavior by default)
# of the same name, regardless of the exact signature (this is also C++ behavior by default)
.
elif
name
==
'<constructor>'
and
(
not
type
.
args
or
len
(
type
.
args
)
==
type
.
optional_arg_count
):
# The default entry is overriden when there is a subsequent entry with a compatible signature.
# Cython pre-declares the no-args constructor - allow later user definitions.
elif
alt_entry
.
is_default
:
previous_alternative_index
=
index
previous_alternative_index
=
index
cpp_override_allowed
=
True
cpp_override_allowed
=
True
...
@@ -713,7 +717,7 @@ class Scope(object):
...
@@ -713,7 +717,7 @@ class Scope(object):
wrapper_name
=
"<constructor>"
wrapper_name
=
"<constructor>"
wrapper_entry
=
scope
.
declare
(
wrapper_name
,
wrapper_cname
,
wrapper_type
,
pos
,
visibility
)
wrapper_entry
=
scope
.
declare
(
wrapper_name
,
wrapper_cname
,
wrapper_type
,
pos
,
visibility
)
wrapper_type
.
entry
=
wrapper_entry
wrapper_type
.
entry
=
wrapper_entry
# wrapper_entry.is_inherited
= 1
wrapper_entry
.
is_default
=
1
wrapper_entry
.
is_cfunction
=
1
wrapper_entry
.
is_cfunction
=
1
wrapper_entry
.
func_cname
=
"%s::%s"
%
(
entry
.
type
.
empty_declaration_code
(),
wrapper_cname
)
wrapper_entry
.
func_cname
=
"%s::%s"
%
(
entry
.
type
.
empty_declaration_code
(),
wrapper_cname
)
...
@@ -725,9 +729,8 @@ class Scope(object):
...
@@ -725,9 +729,8 @@ class Scope(object):
alloc_type
.
entry
=
alloc_entry
alloc_type
.
entry
=
alloc_entry
# alloc_entry.is_inherited = 1
# alloc_entry.is_inherited = 1
alloc_entry
.
is_cfunction
=
1
alloc_entry
.
is_cfunction
=
1
# is_builtin_cmethod is currently only used in cclass, so it should be safe
# is_default is used to distinguish between implicit default __alloc__ and user-defined one
# to use it here to distinguish between implicit default __alloc__ and user-defined one
alloc_entry
.
is_default
=
1
alloc_entry
.
is_builtin_cmethod
=
1
alloc_entry
.
func_cname
=
"%s::%s"
%
(
entry
.
type
.
empty_declaration_code
(),
alloc_cname
)
alloc_entry
.
func_cname
=
"%s::%s"
%
(
entry
.
type
.
empty_declaration_code
(),
alloc_cname
)
if
entry
.
type
.
activable
:
if
entry
.
type
.
activable
:
...
...
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