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
c3b2a4af
Kaydet (Commit)
c3b2a4af
authored
Ock 14, 2008
tarafından
Christian Heimes
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added more comments to the new structseq repr code and implemented several of Neal's suggestions.
üst
c94e2b5c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
17 deletions
+36
-17
structseq.c
Objects/structseq.c
+36
-17
No files found.
Objects/structseq.c
Dosyayı görüntüle @
c3b2a4af
...
...
@@ -230,23 +230,37 @@ make_tuple(PyStructSequence *obj)
static
PyObject
*
structseq_repr
(
PyStructSequence
*
obj
)
{
PyObject
*
tup
,
*
val
,
*
repr
;
/* buffer and type size were chosen well considered. */
#define REPR_BUFFER_SIZE 512
#define TYPE_MAXSIZE 100
PyObject
*
tup
;
PyTypeObject
*
typ
=
Py_TYPE
(
obj
);
int
i
,
len
;
char
buf
[
250
+
5
];
/* "...)\0" */
char
*
cname
,
*
crepr
;
char
*
pbuf
=
buf
;
char
*
endbuf
=
&
buf
[
250
];
strncpy
(
pbuf
,
typ
->
tp_name
,
50
);
pbuf
+=
strlen
(
typ
->
tp_name
)
>
50
?
50
:
strlen
(
typ
->
tp_name
);
*
pbuf
++
=
'('
;
int
i
,
removelast
=
0
;
Py_ssize_t
len
;
char
buf
[
REPR_BUFFER_SIZE
];
char
*
endofbuf
,
*
pbuf
=
buf
;
/* pointer to end of writeable buffer; safes space for "...)\0" */
endofbuf
=
&
buf
[
REPR_BUFFER_SIZE
-
5
];
if
((
tup
=
make_tuple
(
obj
))
==
NULL
)
{
return
NULL
;
}
/* "typename(", limited to TYPE_MAXSIZE */
len
=
strlen
(
typ
->
tp_name
)
>
TYPE_MAXSIZE
?
TYPE_MAXSIZE
:
strlen
(
typ
->
tp_name
);
strncpy
(
pbuf
,
typ
->
tp_name
,
len
);
pbuf
+=
len
;
*
pbuf
++
=
'('
;
for
(
i
=
0
;
i
<
VISIBLE_SIZE
(
obj
);
i
++
)
{
PyObject
*
val
,
*
repr
;
char
*
cname
,
*
crepr
;
cname
=
typ
->
tp_members
[
i
].
name
;
val
=
PyTuple_GetItem
(
tup
,
i
);
if
(
cname
==
NULL
||
val
==
NULL
)
{
return
NULL
;
...
...
@@ -262,8 +276,10 @@ structseq_repr(PyStructSequence *obj)
Py_DECREF
(
repr
);
return
NULL
;
}
len
=
strlen
(
cname
)
+
strlen
(
crepr
)
+
3
;
if
((
pbuf
+
len
)
<
endbuf
)
{
/* + 3: keep space for "=" and ", " */
len
=
strlen
(
cname
)
+
strlen
(
crepr
)
+
3
;
if
((
pbuf
+
len
)
<=
endofbuf
)
{
strcpy
(
pbuf
,
cname
);
pbuf
+=
strlen
(
cname
);
*
pbuf
++
=
'='
;
...
...
@@ -271,23 +287,26 @@ structseq_repr(PyStructSequence *obj)
pbuf
+=
strlen
(
crepr
);
*
pbuf
++
=
','
;
*
pbuf
++
=
' '
;
removelast
=
1
;
Py_DECREF
(
repr
);
}
else
{
strcpy
(
pbuf
,
"..."
);
pbuf
+=
5
;
pbuf
+=
3
;
removelast
=
0
;
Py_DECREF
(
repr
);
break
;
}
}
Py_DECREF
(
tup
);
pbuf
-=
2
;
if
(
removelast
)
{
/* overwrite last ", " */
pbuf
-=
2
;
}
*
pbuf
++
=
')'
;
*
pbuf
=
'\0'
;
repr
=
PyString_FromString
(
buf
);
return
repr
;
return
PyString_FromString
(
buf
);
}
static
PyObject
*
...
...
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