Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c6bb8f7a
Kaydet (Commit)
c6bb8f7a
authored
Tem 01, 1991
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add and use coerce() routine for mixed mode arithmetic
üst
22825e86
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
17 deletions
+76
-17
bltinmodule.c
Python/bltinmodule.c
+76
-17
No files found.
Python/bltinmodule.c
Dosyayı görüntüle @
c6bb8f7a
...
...
@@ -82,7 +82,7 @@ builtin_dir(self, v)
else
{
if
(
!
is_moduleobject
(
v
))
{
err_setstr
(
TypeError
,
"dir() argument
,
must be module or absent"
);
"dir() argument must be module or absent"
);
return
NULL
;
}
d
=
getmoduledict
(
v
);
...
...
@@ -96,22 +96,28 @@ builtin_dir(self, v)
}
static
object
*
builtin_divmod
(
self
,
v
)
builtin_divmod
(
self
,
args
)
object
*
self
;
object
*
v
;
object
*
args
;
{
object
*
x
;
number_methods
*
nm
;
if
(
v
==
NULL
||
!
is_tupleobject
(
v
)
||
gettuplesize
(
v
)
!=
2
)
{
object
*
v
,
*
w
,
*
x
;
if
(
args
==
NULL
||
!
is_tupleobject
(
args
)
||
gettuplesize
(
args
)
!=
2
)
{
err_setstr
(
TypeError
,
"divmod() requires 2 arguments"
);
return
NULL
;
}
x
=
gettupleitem
(
v
,
0
);
if
((
nm
=
x
->
ob_type
->
tp_as_number
)
==
NULL
)
{
v
=
gettupleitem
(
args
,
0
);
w
=
gettupleitem
(
args
,
1
);
if
(
v
->
ob_type
->
tp_as_number
==
NULL
||
w
->
ob_type
->
tp_as_number
==
NULL
)
{
err_setstr
(
TypeError
,
"divmod() requires numeric arguments"
);
return
NULL
;
}
return
(
*
nm
->
nb_divmod
)(
x
,
gettupleitem
(
v
,
1
));
if
(
coerce
(
&
v
,
&
w
)
!=
0
)
return
NULL
;
x
=
(
*
v
->
ob_type
->
tp_as_number
->
nb_divmod
)(
v
,
w
);
DECREF
(
v
);
DECREF
(
w
);
return
x
;
}
static
object
*
...
...
@@ -362,22 +368,28 @@ builtin_ord(self, v)
}
static
object
*
builtin_pow
(
self
,
v
)
builtin_pow
(
self
,
args
)
object
*
self
;
object
*
v
;
object
*
args
;
{
object
*
x
;
number_methods
*
nm
;
if
(
v
==
NULL
||
!
is_tupleobject
(
v
)
||
gettuplesize
(
v
)
!=
2
)
{
object
*
v
,
*
w
,
*
x
;
if
(
args
==
NULL
||
!
is_tupleobject
(
args
)
||
gettuplesize
(
args
)
!=
2
)
{
err_setstr
(
TypeError
,
"pow() requires 2 arguments"
);
return
NULL
;
}
x
=
gettupleitem
(
v
,
0
);
if
((
nm
=
x
->
ob_type
->
tp_as_number
)
==
NULL
)
{
v
=
gettupleitem
(
args
,
0
);
w
=
gettupleitem
(
args
,
1
);
if
(
v
->
ob_type
->
tp_as_number
==
NULL
||
w
->
ob_type
->
tp_as_number
==
NULL
)
{
err_setstr
(
TypeError
,
"pow() requires numeric arguments"
);
return
NULL
;
}
return
(
*
nm
->
nb_power
)(
x
,
gettupleitem
(
v
,
1
));
if
(
coerce
(
&
v
,
&
w
)
!=
0
)
return
NULL
;
x
=
(
*
v
->
ob_type
->
tp_as_number
->
nb_power
)(
v
,
w
);
DECREF
(
v
);
DECREF
(
w
);
return
x
;
}
static
object
*
...
...
@@ -557,3 +569,50 @@ initbuiltin()
initerrors
();
(
void
)
dictinsert
(
builtin_dict
,
"None"
,
None
);
}
/* Coerce two numeric types to the "larger" one.
Increment the reference count on each argument.
Return -1 and raise an exception if no coercion is possible
(and then no reference count is incremented).
XXX This should be distributed over the various numeric types,
XXX but for now I don't see how to implement that.
XXX So, for now, if you add a new numeric type,
XXX you must add to this function as well. */
int
coerce
(
pv
,
pw
)
object
**
pv
,
**
pw
;
{
register
object
*
v
=
*
pv
;
register
object
*
w
=
*
pw
;
if
(
v
->
ob_type
==
w
->
ob_type
)
{
INCREF
(
v
);
INCREF
(
w
);
return
0
;
}
if
(
v
->
ob_type
->
tp_as_number
==
NULL
||
w
->
ob_type
->
tp_as_number
==
NULL
)
{
err_setstr
(
TypeError
,
"mixing number and non-number"
);
return
-
1
;
}
if
(
is_floatobject
(
v
)
||
is_floatobject
(
w
))
{
v
=
builtin_float
((
object
*
)
0
,
v
);
w
=
builtin_float
((
object
*
)
0
,
w
);
}
else
if
(
is_longobject
(
v
)
||
is_longobject
(
w
))
{
v
=
builtin_long
((
object
*
)
0
,
v
);
w
=
builtin_long
((
object
*
)
0
,
w
);
}
else
{
err_setstr
(
TypeError
,
"can't coerce numeric types?!?!?"
);
return
-
1
;
}
if
(
v
==
NULL
||
w
==
NULL
)
{
XDECREF
(
v
);
XDECREF
(
w
);
return
-
1
;
}
*
pv
=
v
;
*
pw
=
w
;
return
0
;
}
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