Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
52d2c38b
Commit
52d2c38b
authored
Jan 10, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement coercions involving instances properly
parent
3f0acbf9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
1 deletion
+53
-1
Objects/classobject.c
Objects/classobject.c
+53
-1
No files found.
Objects/classobject.c
View file @
52d2c38b
...
@@ -924,6 +924,58 @@ halfbinop(v, w, opname, r_result, thisfunc, swapped)
...
@@ -924,6 +924,58 @@ halfbinop(v, w, opname, r_result, thisfunc, swapped)
return
*
r_result
==
NULL
?
-
1
:
0
;
return
*
r_result
==
NULL
?
-
1
:
0
;
}
}
static
int
instance_coerce
(
pv
,
pw
)
object
**
pv
;
object
**
pw
;
{
object
*
v
=
*
pv
;
object
*
w
=
*
pw
;
object
*
coerce
;
object
*
args
;
object
*
coerced
;
coerce
=
getattr
(
v
,
"__coerce__"
);
if
(
coerce
==
NULL
)
{
/* No __coerce__ method: always OK */
err_clear
();
INCREF
(
v
);
INCREF
(
w
);
return
0
;
}
/* Has __coerce__ method: call it */
args
=
mkvalue
(
"(O)"
,
w
);
if
(
args
==
NULL
)
{
return
-
1
;
}
coerced
=
call_object
(
coerce
,
args
);
DECREF
(
args
);
DECREF
(
coerce
);
if
(
coerced
==
NULL
)
{
/* __coerce__ call raised an exception */
return
-
1
;
}
if
(
coerced
==
None
)
{
/* __coerce__ says "I can't do it" */
DECREF
(
coerced
);
return
1
;
}
if
(
!
is_tupleobject
(
coerced
)
||
gettuplesize
(
coerced
)
!=
2
)
{
/* __coerce__ return value is malformed */
DECREF
(
coerced
);
err_setstr
(
TypeError
,
"coercion should return None or 2-tuple"
);
return
-
1
;
}
/* __coerce__ returned two new values */
*
pv
=
gettupleitem
(
coerced
,
0
);
*
pw
=
gettupleitem
(
coerced
,
1
);
INCREF
(
*
pv
);
INCREF
(
*
pw
);
DECREF
(
coerced
);
return
0
;
}
#define UNARY(funcname, methodname) \
#define UNARY(funcname, methodname) \
static object *funcname(self) instanceobject *self; { \
static object *funcname(self) instanceobject *self; { \
...
@@ -1018,7 +1070,7 @@ static number_methods instance_as_number = {
...
@@ -1018,7 +1070,7 @@ static number_methods instance_as_number = {
0
,
/*nb_and*/
0
,
/*nb_and*/
0
,
/*nb_xor*/
0
,
/*nb_xor*/
0
,
/*nb_or*/
0
,
/*nb_or*/
0
,
/*nb_coerce*/
(
coercion
)
instance_coerce
,
/*nb_coerce*/
(
unaryfunc
)
instance_int
,
/*nb_int*/
(
unaryfunc
)
instance_int
,
/*nb_int*/
(
unaryfunc
)
instance_long
,
/*nb_long*/
(
unaryfunc
)
instance_long
,
/*nb_long*/
(
unaryfunc
)
instance_float
,
/*nb_float*/
(
unaryfunc
)
instance_float
,
/*nb_float*/
...
...
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