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
204e2891
Commit
204e2891
authored
Feb 23, 2007
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify sizeof() operator to return size of extension type struct
parent
78ed7c3a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
6 deletions
+14
-6
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+9
-4
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+5
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
204e2891
...
...
@@ -2352,7 +2352,7 @@ class SizeofTypeNode(SizeofNode):
base_type
=
self
.
base_type
.
analyse
(
env
)
_
,
arg_type
=
self
.
declarator
.
analyse
(
base_type
,
env
)
self
.
arg_type
=
arg_type
if
arg_type
.
is_pyobject
:
if
arg_type
.
is_pyobject
and
not
arg_type
.
is_extension_type
:
error
(
self
.
pos
,
"Cannot take sizeof Python object"
)
elif
arg_type
.
is_void
:
error
(
self
.
pos
,
"Cannot take sizeof void"
)
...
...
@@ -2361,6 +2361,11 @@ class SizeofTypeNode(SizeofNode):
self
.
type
=
PyrexTypes
.
c_int_type
def
calculate_result_code
(
self
):
if
self
.
arg_type
.
is_extension_type
:
# the size of the pointer is boring
# we want the size of the actual struct
arg_code
=
self
.
arg_type
.
declaration_code
(
""
,
deref
=
1
)
else
:
arg_code
=
self
.
arg_type
.
declaration_code
(
""
)
return
"(sizeof(%s))"
%
arg_code
...
...
@@ -2744,14 +2749,14 @@ class CondExprNode(ExprNode):
def
compute_result_type
(
self
,
type1
,
type2
):
if
type1
==
type2
:
return
type1
elif
type1
.
is_pyobject
or
type2
.
is_pyobject
:
return
py_object_type
elif
type1
.
is_numeric
and
type2
.
is_numeric
:
return
PyrexTypes
.
widest_numeric_type
(
type1
,
type2
)
elif
type1
.
is_extension_type
and
type1
.
subtype_of_resolved_type
(
type2
):
return
type2
elif
type2
.
is_extension_type
and
type2
.
subtype_of_resolved_type
(
type1
):
return
type1
elif
type1
.
is_pyobject
or
type2
.
is_pyobject
:
return
py_object_type
else
:
return
None
...
...
Cython/Compiler/PyrexTypes.py
View file @
204e2891
...
...
@@ -225,7 +225,7 @@ class PyExtensionType(PyObjectType):
return
self
.
typeobj_cname
is
None
and
self
.
module_name
is
not
None
def
declaration_code
(
self
,
entity_code
,
for_display
=
0
,
dll_linkage
=
None
,
pyrex
=
0
):
for_display
=
0
,
dll_linkage
=
None
,
pyrex
=
0
,
deref
=
0
):
if
pyrex
:
return
"%s %s"
%
(
self
.
name
,
entity_code
)
else
:
...
...
@@ -234,6 +234,9 @@ class PyExtensionType(PyObjectType):
else
:
base_format
=
"struct %s"
base
=
public_decl
(
base_format
%
self
.
objstruct_cname
,
dll_linkage
)
if
deref
:
return
"%s %s"
%
(
base
,
entity_code
)
else
:
return
"%s *%s"
%
(
base
,
entity_code
)
def
attributes_known
(
self
):
...
...
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