FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Issue #24808: Update the documentation of some PyTypeObject fields · python/cpython@78d5033 · GitHub

Repository navigation

Commit 78d5033

Browse files
Martin Panter
committed
Issue #24808: Update the documentation of some PyTypeObject fields
Patch by Joseph Weston.
1 parent b372356 commit 78d5033

5 files changed

Lines changed: 19 additions & 16 deletions

File tree

‎Doc/c-api/typeobj.rst‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type objects) *must* have the :attr:`ob_size` field.
9494
This field is not inherited by subtypes.
9595

9696

97-
.. c:member:: char* PyTypeObject.tp_name
97+
.. c:member:: const char* PyTypeObject.tp_name
9898
9999
Pointer to a NUL-terminated string containing the name of the type. For types
100100
that are accessible as module globals, the string should be the full module
@@ -367,7 +367,7 @@ type objects) *must* have the :attr:`ob_size` field.
367367
inherited individually.
368368

369369

370-
.. c:member:: long PyTypeObject.tp_flags
370+
.. c:member:: unsigned long PyTypeObject.tp_flags
371371
372372
This field is a bit mask of various flags. Some flags indicate variant
373373
semantics for certain situations; others are used to indicate that certain
@@ -467,7 +467,7 @@ type objects) *must* have the :attr:`ob_size` field.
467467
.. versionadded:: 3.4
468468

469469

470-
.. c:member:: char* PyTypeObject.tp_doc
470+
.. c:member:: const char* PyTypeObject.tp_doc
471471
472472
An optional pointer to a NUL-terminated C string giving the docstring for this
473473
type object. This is exposed as the :attr:`__doc__` attribute on the type and
@@ -614,7 +614,7 @@ type objects) *must* have the :attr:`ob_size` field.
614614
+----------------+------------+
615615

616616

617-
.. c:member:: long PyTypeObject.tp_weaklistoffset
617+
.. c:member:: Py_ssize_t PyTypeObject.tp_weaklistoffset
618618
619619
If the instances of this type are weakly referenceable, this field is greater
620620
than zero and contains the offset in the instance structure of the weak
@@ -781,7 +781,7 @@ type objects) *must* have the :attr:`ob_size` field.
781781
.. XXX explain.
782782
783783
784-
.. c:member:: long PyTypeObject.tp_dictoffset
784+
.. c:member:: Py_ssize_t PyTypeObject.tp_dictoffset
785785
786786
If the instances of this type have a dictionary containing instance variables,
787787
this field is non-zero and contains the offset in the instances of the type of

‎Doc/extending/newtypes.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,20 +893,20 @@ fields in the right order! It's often easiest to find an example that includes
893893
all the fields you need (even if they're initialized to ``0``) and then change
894894
the values to suit your new type. ::
895895

896-
char *tp_name; /* For printing */
896+
const char *tp_name; /* For printing */
897897

898898
The name of the type - as mentioned in the last section, this will appear in
899899
various places, almost entirely for diagnostic purposes. Try to choose something
900900
that will be helpful in such a situation! ::
901901

902-
int tp_basicsize, tp_itemsize; /* For allocation */
902+
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
903903

904904
These fields tell the runtime how much memory to allocate when new objects of
905905
this type are created. Python has some built-in support for variable length
906906
structures (think: strings, lists) which is where the :c:member:`~PyTypeObject.tp_itemsize` field
907907
comes in. This will be dealt with later. ::
908908

909-
char *tp_doc;
909+
const char *tp_doc;
910910

911911
Here you can put a string (or its address) that you want returned when the
912912
Python script references ``obj.__doc__`` to retrieve the doc string.

‎Doc/includes/typestruct.h‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
typedef struct _typeobject {
22
PyObject_VAR_HEAD
3-
char *tp_name; /* For printing, in format "<module>.<name>" */
4-
int tp_basicsize, tp_itemsize; /* For allocation */
3+
const char *tp_name; /* For printing, in format "<module>.<name>" */
4+
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
55

66
/* Methods to implement standard operations */
77

88
destructor tp_dealloc;
99
printfunc tp_print;
1010
getattrfunc tp_getattr;
1111
setattrfunc tp_setattr;
12-
void *tp_reserved;
12+
void *tp_reserved; /* formerly known as tp_compare */
1313
reprfunc tp_repr;
1414

1515
/* Method suites for standard classes */
@@ -30,9 +30,9 @@ typedef struct _typeobject {
3030
PyBufferProcs *tp_as_buffer;
3131

3232
/* Flags to define presence of optional/expanded features */
33-
long tp_flags;
33+
unsigned long tp_flags;
3434

35-
char *tp_doc; /* Documentation string */
35+
const char *tp_doc; /* Documentation string */
3636

3737
/* call function for all accessible objects */
3838
traverseproc tp_traverse;
@@ -44,7 +44,7 @@ typedef struct _typeobject {
4444
richcmpfunc tp_richcompare;
4545

4646
/* weak reference enabler */
47-
long tp_weaklistoffset;
47+
Py_ssize_t tp_weaklistoffset;
4848

4949
/* Iterators */
5050
getiterfunc tp_iter;
@@ -58,7 +58,7 @@ typedef struct _typeobject {
5858
PyObject *tp_dict;
5959
descrgetfunc tp_descr_get;
6060
descrsetfunc tp_descr_set;
61-
long tp_dictoffset;
61+
Py_ssize_t tp_dictoffset;
6262
initproc tp_init;
6363
allocfunc tp_alloc;
6464
newfunc tp_new;
@@ -69,7 +69,6 @@ typedef struct _typeobject {
6969
PyObject *tp_cache;
7070
PyObject *tp_subclasses;
7171
PyObject *tp_weaklist;
72-
7372
destructor tp_del;
7473

7574
/* Type attribute cache version tag. Added in version 2.6 */

‎Misc/ACKS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,7 @@ Bob Weiner
14731473
Edward Welbourne
14741474
Cliff Wells
14751475
Rickard Westman
1476+
Joseph Weston
14761477
Jeff Wheeler
14771478
Christopher White
14781479
David White

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ C API
449449
Documentation
450450
-------------
451451

452+
- Issue #24808: Update the types of some PyTypeObject fields. Patch by
453+
Joseph Weston.
454+
452455
- Issue #22812: Fix unittest discovery examples.
453456
Patch from Pam McA'Nulty.
454457

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL