Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36f22a2

Browse files
author
Martin Panter
committed
Issue #24808: Merge 3.4 into 3.5; adjust new tp_as_async field
2 parents ef4554f + 78d5033 commit 36f22a2

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
@@ -372,7 +372,7 @@ type objects) *must* have the :attr:`ob_size` field.
372372
inherited individually.
373373

374374

375-
.. c:member:: long PyTypeObject.tp_flags
375+
.. c:member:: unsigned long PyTypeObject.tp_flags
376376
377377
This field is a bit mask of various flags. Some flags indicate variant
378378
semantics for certain situations; others are used to indicate that certain
@@ -472,7 +472,7 @@ type objects) *must* have the :attr:`ob_size` field.
472472
.. versionadded:: 3.4
473473

474474

475-
.. c:member:: char* PyTypeObject.tp_doc
475+
.. c:member:: const char* PyTypeObject.tp_doc
476476
477477
An optional pointer to a NUL-terminated C string giving the docstring for this
478478
type object. This is exposed as the :attr:`__doc__` attribute on the type and
@@ -619,7 +619,7 @@ type objects) *must* have the :attr:`ob_size` field.
619619
+----------------+------------+
620620

621621

622-
.. c:member:: long PyTypeObject.tp_weaklistoffset
622+
.. c:member:: Py_ssize_t PyTypeObject.tp_weaklistoffset
623623
624624
If the instances of this type are weakly referenceable, this field is greater
625625
than zero and contains the offset in the instance structure of the weak
@@ -786,7 +786,7 @@ type objects) *must* have the :attr:`ob_size` field.
786786
.. XXX explain.
787787
788788
789-
.. c:member:: long PyTypeObject.tp_dictoffset
789+
.. c:member:: Py_ssize_t PyTypeObject.tp_dictoffset
790790
791791
If the instances of this type have a dictionary containing instance variables,
792792
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-
PyAsyncMethods *tp_as_async;
12+
PyAsyncMethods *tp_as_async; /* formerly known as tp_compare or tp_reserved */
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
@@ -1519,6 +1519,7 @@ Bob Weiner
15191519
Edward Welbourne
15201520
Cliff Wells
15211521
Rickard Westman
1522+
Joseph Weston
15221523
Jeff Wheeler
15231524
Christopher White
15241525
David White

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Library
2929
Documentation
3030
-------------
3131

32+
- Issue #24808: Update the types of some PyTypeObject fields. Patch by
33+
Joseph Weston.
34+
3235
- Issue #22812: Fix unittest discovery examples.
3336
Patch from Pam McA'Nulty.
3437

0 commit comments

Comments
 (0)