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

Skip to content

Commit f78b1c6

Browse files
committed
I've moved the remains of PyInt_ to the longobject.h header file and removed the inclusing of intobject.h from Python.h. Now the intobject.h exists only to provide some aliases for porters from Python 2.x.
1 parent 2137b6a commit f78b1c6

6 files changed

Lines changed: 35 additions & 48 deletions

File tree

Doc/whatsnew/3.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ changes to your code:
387387

388388
* Everything is all in the details!
389389

390+
* Developers can include intobject.h after Python.h for some PyInt_ aliases.
391+
390392
.. ======================================================================
391393
392394

Include/Python.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666

6767
#include "bytesobject.h"
6868
#include "unicodeobject.h"
69-
#include "intobject.h"
7069
#include "longobject.h"
7170
#include "longintrepr.h"
7271
#include "boolobject.h"

Include/intobject.h

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,29 @@
1+
/* Integer object interface
12
2-
/* Integer object interface */
3-
4-
/*
5-
PyIntObject represents a (long) integer. This is an immutable object;
6-
an integer cannot change its value after creation.
7-
8-
There are functions to create new integer objects, to test an object
9-
for integer-ness, and to get the integer value. The latter functions
10-
returns -1 and sets errno to EBADF if the object is not an PyIntObject.
11-
None of the functions should be applied to nil objects.
12-
13-
The type PyIntObject is (unfortunately) exposed here so we can declare
14-
_Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this.
15-
*/
3+
This header files exists to make porting code to Python 3.0 easier. It
4+
defines aliases from PyInt_* to PyLong_*. Only PyInt_GetMax() and
5+
PyInt_CheckExact() remain in longobject.h.
6+
*/
167

178
#ifndef Py_INTOBJECT_H
189
#define Py_INTOBJECT_H
1910
#ifdef __cplusplus
2011
extern "C" {
2112
#endif
2213

23-
/*
24-
typedef struct {
25-
PyObject_HEAD
26-
long ob_ival;
27-
} PyIntObject;
28-
29-
PyAPI_DATA(PyTypeObject) PyInt_Type;
30-
*/
31-
32-
#define PyInt_CheckExact(op) (PyLong_CheckExact(op) && _PyLong_FitsInLong(op))
33-
34-
#if 0
35-
# define PyInt_Check(op) PyLong_Check(op)
36-
# define PyInt_FromString PyLong_FromString
37-
# define PyInt_FromUnicode PyLong_FromUnicode
38-
# define PyInt_FromLong PyLong_FromLong
39-
# define PyInt_FromSize_t PyLong_FromSize_t
40-
# define PyInt_FromSsize_t PyLong_FromSsize_t
41-
# define PyInt_AsLong PyLong_AsLong
42-
# define PyInt_AsSsize_t PyLong_AsSsize_t
43-
# define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
44-
# define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
45-
# define PyInt_AS_LONG PyLong_AS_LONG
46-
#endif
47-
48-
PyAPI_FUNC(long) PyInt_GetMax(void);
49-
50-
/* These aren't really part of the Int object, but they're handy; the protos
51-
* are necessary for systems that need the magic of PyAPI_FUNC.
52-
*/
53-
PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
54-
PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
14+
#warning "DeprecationWarning: intobject.h is going to be removed in 3.1"
15+
16+
#define PyInt_Check(op) PyLong_Check(op)
17+
#define PyInt_FromString PyLong_FromString
18+
#define PyInt_FromUnicode PyLong_FromUnicode
19+
#define PyInt_FromLong PyLong_FromLong
20+
#define PyInt_FromSize_t PyLong_FromSize_t
21+
#define PyInt_FromSsize_t PyLong_FromSsize_t
22+
#define PyInt_AsLong PyLong_AsLong
23+
#define PyInt_AsSsize_t PyLong_AsSsize_t
24+
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
25+
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
26+
#define PyInt_AS_LONG PyLong_AS_LONG
5527

5628
#ifdef __cplusplus
5729
}

Include/longobject.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PyAPI_DATA(PyTypeObject) PyLong_Type;
1414
#define PyLong_Check(op) \
1515
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_LONG_SUBCLASS)
1616
#define PyLong_CheckExact(op) (Py_Type(op) == &PyLong_Type)
17+
#define PyInt_CheckExact(op) (PyLong_CheckExact(op) && _PyLong_FitsInLong(op))
1718

1819
PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
1920
PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
@@ -30,6 +31,8 @@ PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
3031
cleanup to keep the extra information. [CH] */
3132
#define PyLong_AS_LONG(op) PyLong_AsLong(op)
3233

34+
PyAPI_FUNC(long) PyInt_GetMax(void);
35+
3336
/* Used by socketmodule.c */
3437
#if SIZEOF_SOCKET_T <= SIZEOF_LONG
3538
#define PyLong_FromSocket_t(fd) PyLong_FromLong((SOCKET_T)(fd))
@@ -127,6 +130,12 @@ PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
127130
appending a base prefix of 0[box] if base is 2, 8 or 16. */
128131
PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *aa, int base);
129132

133+
/* These aren't really part of the long object, but they're handy. The
134+
functions are in Python/mystrtoul.c.
135+
*/
136+
PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
137+
PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
138+
130139
#ifdef __cplusplus
131140
}
132141
#endif

Makefile.pre.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ PYTHON_HEADERS= \
546546
Include/asdl.h \
547547
Include/abstract.h \
548548
Include/boolobject.h \
549+
Include/bytes_methods.h \
549550
Include/bytesobject.h \
550551
Include/ceval.h \
551552
Include/classobject.h \
@@ -563,10 +564,10 @@ PYTHON_HEADERS= \
563564
Include/formatter_unicode.h \
564565
Include/funcobject.h \
565566
Include/import.h \
566-
Include/intobject.h \
567567
Include/intrcheck.h \
568568
Include/iterobject.h \
569569
Include/listobject.h \
570+
Include/longintrepr.h \
570571
Include/longobject.h \
571572
Include/memoryobject.h \
572573
Include/methodobject.h \

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Core and Builtins
5050
removed and im_func + im_self are renamed to __func__ and __self__. The
5151
factory PyMethod_New takes only func and instance as argument.
5252

53+
- intobject.h is no longer included by Python.h. The remains were moved
54+
to longobject.h. It still exists to define several aliases from PyInt_
55+
to PyLong_ functions.
56+
5357

5458
Extension Modules
5559
-----------------

0 commit comments

Comments
 (0)