@@ -132,115 +132,6 @@ Numeric Objects
132132.. index :: object: numeric
133133
134134
135- .. _intobjects :
136-
137- Plain Integer Objects
138- ---------------------
139-
140- .. index :: object: integer
141-
142-
143- .. ctype :: PyIntObject
144-
145- This subtype of :ctype: `PyObject ` represents a Python integer object.
146-
147-
148- .. cvar :: PyTypeObject PyInt_Type
149-
150- .. index :: single: IntType (in modules types)
151-
152- This instance of :ctype: `PyTypeObject ` represents the Python plain integer type.
153- This is the same object as ``int `` and ``types.IntType ``.
154-
155-
156- .. cfunction :: int PyInt_Check(PyObject *o)
157-
158- Return true if *o * is of type :cdata: `PyInt_Type ` or a subtype of
159- :cdata: `PyInt_Type `.
160-
161-
162- .. cfunction :: int PyInt_CheckExact(PyObject *o)
163-
164- Return true if *o * is of type :cdata: `PyInt_Type `, but not a subtype of
165- :cdata: `PyInt_Type `.
166-
167-
168- .. cfunction :: PyObject* PyInt_FromString(char *str, char **pend, int base)
169-
170- Return a new :ctype: `PyIntObject ` or :ctype: `PyLongObject ` based on the string
171- value in *str *, which is interpreted according to the radix in *base *. If
172- *pend * is non-*NULL *, ``*pend `` will point to the first character in *str * which
173- follows the representation of the number. If *base * is ``0 ``, the radix will be
174- determined based on the leading characters of *str *: if *str * starts with
175- ``'0x' `` or ``'0X' ``, radix 16 will be used; if *str * starts with ``'0' ``, radix
176- 8 will be used; otherwise radix 10 will be used. If *base * is not ``0 ``, it
177- must be between ``2 `` and ``36 ``, inclusive. Leading spaces are ignored. If
178- there are no digits, :exc: `ValueError ` will be raised. If the string represents
179- a number too large to be contained within the machine's :ctype: `long int ` type
180- and overflow warnings are being suppressed, a :ctype: `PyLongObject ` will be
181- returned. If overflow warnings are not being suppressed, *NULL * will be
182- returned in this case.
183-
184-
185- .. cfunction :: PyObject* PyInt_FromLong(long ival)
186-
187- Create a new integer object with a value of *ival *.
188-
189- The current implementation keeps an array of integer objects for all integers
190- between ``-5 `` and ``256 ``, when you create an int in that range you actually
191- just get back a reference to the existing object. So it should be possible to
192- change the value of ``1 ``. I suspect the behaviour of Python in this case is
193- undefined. :-)
194-
195-
196- .. cfunction :: PyObject* PyInt_FromSsize_t(Py_ssize_t ival)
197-
198- Create a new integer object with a value of *ival *. If the value exceeds
199- ``LONG_MAX ``, a long integer object is returned.
200-
201-
202- .. cfunction :: long PyInt_AsLong(PyObject *io)
203-
204- Will first attempt to cast the object to a :ctype: `PyIntObject `, if it is not
205- already one, and then return its value. If there is an error, ``-1 `` is
206- returned, and the caller should check ``PyErr_Occurred() `` to find out whether
207- there was an error, or whether the value just happened to be -1.
208-
209-
210- .. cfunction :: long PyInt_AS_LONG(PyObject *io)
211-
212- Return the value of the object *io *. No error checking is performed.
213-
214-
215- .. cfunction :: unsigned long PyInt_AsUnsignedLongMask(PyObject *io)
216-
217- Will first attempt to cast the object to a :ctype: `PyIntObject ` or
218- :ctype: `PyLongObject `, if it is not already one, and then return its value as
219- unsigned long. This function does not check for overflow.
220-
221-
222- .. cfunction :: unsigned PY_LONG_LONG PyInt_AsUnsignedLongLongMask(PyObject *io)
223-
224- Will first attempt to cast the object to a :ctype: `PyIntObject ` or
225- :ctype: `PyLongObject `, if it is not already one, and then return its value as
226- unsigned long long, without checking for overflow.
227-
228-
229- .. cfunction :: Py_ssize_t PyInt_AsSsize_t(PyObject *io)
230-
231- Will first attempt to cast the object to a :ctype: `PyIntObject ` or
232- :ctype: `PyLongObject `, if it is not already one, and then return its value as
233- :ctype: `Py_ssize_t `.
234-
235-
236- .. cfunction :: long PyInt_GetMax()
237-
238- .. index :: single: LONG_MAX
239-
240- Return the system's idea of the largest integer it can handle
241- (:const: `LONG_MAX `, as defined in the system header files).
242-
243-
244135.. _boolobjects :
245136
246137Boolean Objects
@@ -289,23 +180,23 @@ are available, however.
289180
290181.. _longobjects :
291182
292- Long Integer Objects
293- --------------------
183+ Integer Objects
184+ ---------------
294185
295186.. index :: object: long integer
187+ object: integer
296188
189+ All integers are implemented as "long" integer objects of arbitrary size.
297190
298191.. ctype :: PyLongObject
299192
300- This subtype of :ctype: `PyObject ` represents a Python long integer object.
193+ This subtype of :ctype: `PyObject ` represents a Python integer object.
301194
302195
303196.. cvar :: PyTypeObject PyLong_Type
304197
305- .. index :: single: LongType (in modules types)
306-
307- This instance of :ctype: `PyTypeObject ` represents the Python long integer type.
308- This is the same object as ``long `` and ``types.LongType ``.
198+ This instance of :ctype: `PyTypeObject ` represents the Python integer type.
199+ This is the same object as ``int ``.
309200
310201
311202.. cfunction :: int PyLong_Check(PyObject *p)
@@ -320,17 +211,39 @@ Long Integer Objects
320211 :ctype: `PyLongObject `.
321212
322213
214+ .. XXX cfunction PyInt_CheckExact(PyObject *p) checks if argument is a long
215+ object and fits into a C long
216+
217+
323218 .. cfunction :: PyObject* PyLong_FromLong(long v)
324219
325220 Return a new :ctype: `PyLongObject ` object from *v *, or *NULL * on failure.
326221
222+ The current implementation keeps an array of integer objects for all integers
223+ between ``-5 `` and ``256 ``, when you create an int in that range you actually
224+ just get back a reference to the existing object. So it should be possible to
225+ change the value of ``1 ``. I suspect the behaviour of Python in this case is
226+ undefined. :-)
227+
327228
328229.. cfunction :: PyObject* PyLong_FromUnsignedLong(unsigned long v)
329230
330231 Return a new :ctype: `PyLongObject ` object from a C :ctype: `unsigned long `, or
331232 *NULL * on failure.
332233
333234
235+ .. cfunction :: PyObject* PyLong_FromSsize_t(Py_ssize_t v)
236+
237+ Return a new :ctype: `PyLongObject ` object with a value of *v *, or *NULL *
238+ on failure.
239+
240+
241+ .. cfunction :: PyObject* PyLong_FromSize_t(size_t v)
242+
243+ Return a new :ctype: `PyLongObject ` object with a value of *v *, or *NULL *
244+ on failure.
245+
246+
334247.. cfunction :: PyObject* PyLong_FromLongLong(PY_LONG_LONG v)
335248
336249 Return a new :ctype: `PyLongObject ` object from a C :ctype: `long long `, or *NULL *
@@ -351,33 +264,32 @@ Long Integer Objects
351264
352265.. cfunction :: PyObject* PyLong_FromString(char *str, char **pend, int base)
353266
354- Return a new :ctype: `PyLongObject ` based on the string value in *str *, which is
355- interpreted according to the radix in *base *. If *pend * is non-*NULL *,
267+ Return a new :ctype: `PyLongObject ` based on the string value in *str *, which
268+ is interpreted according to the radix in *base *. If *pend * is non-*NULL *,
356269 ``*pend `` will point to the first character in *str * which follows the
357- representation of the number. If *base * is ``0 ``, the radix will be determined
358- based on the leading characters of *str *: if *str * starts with ``'0x' `` or
359- ``'0X' ``, radix 16 will be used; if *str * starts with ``'0' ``, radix 8 will be
360- used; otherwise radix 10 will be used. If *base * is not ``0 ``, it must be
361- between ``2 `` and ``36 ``, inclusive. Leading spaces are ignored. If there are
362- no digits, :exc: `ValueError ` will be raised.
270+ representation of the number. If *base * is ``0 ``, the radix will be
271+ determined based on the leading characters of *str *: if *str * starts with
272+ ``'0x' `` or ``'0X' ``, radix 16 will be used; if *str * starts with ``'0o' `` or
273+ ``'0O' ``, radix 8 will be used; if *str * starts with ``'0b' `` or ``'0B' ``,
274+ radix 2 will be used; otherwise radix 10 will be used. If *base * is not
275+ ``0 ``, it must be between ``2 `` and ``36 ``, inclusive. Leading spaces are
276+ ignored. If there are no digits, :exc: `ValueError ` will be raised.
363277
364278
365279.. cfunction :: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
366280
367- Convert a sequence of Unicode digits to a Python long integer value. The first
368- parameter, *u *, points to the first character of the Unicode string, *length *
369- gives the number of characters, and *base * is the radix for the conversion. The
370- radix must be in the range [2, 36]; if it is out of range, :exc: `ValueError `
371- will be raised.
281+ Convert a sequence of Unicode digits to a Python integer value. The Unicode
282+ string is first encoded to a byte string using :cfunc: `PyUnicode_EncodeDecimal `
283+ and then converted using :cfunc: `PyLong_FromString `.
372284
373285
374286.. cfunction :: PyObject* PyLong_FromVoidPtr(void *p)
375287
376- Create a Python integer or long integer from the pointer *p *. The pointer value
377- can be retrieved from the resulting value using :cfunc: `PyLong_AsVoidPtr `.
378- If the integer is larger than LONG_MAX, a positive long integer is returned.
288+ Create a Python integer from the pointer *p *. The pointer value can be
289+ retrieved from the resulting value using :cfunc: `PyLong_AsVoidPtr `.
379290
380291
292+ .. XXX alias PyLong_AS_LONG (for now)
381293 .. cfunction :: long PyLong_AsLong(PyObject *pylong)
382294
383295 .. index ::
@@ -399,29 +311,46 @@ Long Integer Objects
399311 raised.
400312
401313
314+ .. cfunction :: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong)
315+
316+ .. index ::
317+ single: PY_SSIZE_T_MAX
318+
319+ Return a :ctype: `Py_ssize_t ` representation of the contents of *pylong *. If
320+ *pylong * is greater than :const: `PY_SSIZE_T_MAX `, an :exc: `OverflowError ` is
321+ raised.
322+
323+
324+ .. cfunction :: size_t PyLong_AsSize_t(PyObject *pylong)
325+
326+ Return a :ctype: `size_t ` representation of the contents of *pylong *. If
327+ *pylong * is greater than the maximum value for a :ctype: `size_t `, an
328+ :exc: `OverflowError ` is raised.
329+
330+
402331.. cfunction :: PY_LONG_LONG PyLong_AsLongLong(PyObject *pylong)
403332
404- Return a C :ctype: `long long ` from a Python long integer. If *pylong * cannot be
333+ Return a C :ctype: `long long ` from a Python integer. If *pylong * cannot be
405334 represented as a :ctype: `long long `, an :exc: `OverflowError ` will be raised.
406335
407336
408337.. cfunction :: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong)
409338
410- Return a C :ctype: `unsigned long long ` from a Python long integer. If *pylong *
339+ Return a C :ctype: `unsigned long long ` from a Python integer. If *pylong *
411340 cannot be represented as an :ctype: `unsigned long long `, an :exc: `OverflowError `
412341 will be raised if the value is positive, or a :exc: `TypeError ` will be raised if
413342 the value is negative.
414343
415344
416345.. cfunction :: unsigned long PyLong_AsUnsignedLongMask(PyObject *io)
417346
418- Return a C :ctype: `unsigned long ` from a Python long integer, without checking
419- for overflow.
347+ Return a C :ctype: `unsigned long ` from a Python integer, without checking for
348+ overflow.
420349
421350
422351.. cfunction :: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *io)
423352
424- Return a C :ctype: `unsigned long long ` from a Python long integer, without
353+ Return a C :ctype: `unsigned long long ` from a Python integer, without
425354 checking for overflow.
426355
427356
@@ -434,12 +363,19 @@ Long Integer Objects
434363
435364.. cfunction :: void* PyLong_AsVoidPtr(PyObject *pylong)
436365
437- Convert a Python integer or long integer *pylong * to a C :ctype: `void ` pointer.
438- If *pylong * cannot be converted, an :exc: `OverflowError ` will be raised. This
439- is only assured to produce a usable :ctype: `void ` pointer for values created
440- with :cfunc: `PyLong_FromVoidPtr `.
366+ Convert a Python integer *pylong * to a C :ctype: `void ` pointer. If *pylong *
367+ cannot be converted, an :exc: `OverflowError ` will be raised. This is only
368+ assured to produce a usable :ctype: `void ` pointer for values created with
369+ :cfunc: `PyLong_FromVoidPtr `.
370+
441371
442- For values outside 0..LONG_MAX, both signed and unsigned integers are acccepted.
372+ .. XXX name?
373+ .. cfunction :: long PyInt_GetMax()
374+
375+ .. index :: single: LONG_MAX
376+
377+ Return the system's idea of the largest integer it can handle
378+ (:const: `LONG_MAX `, as defined in the system header files).
443379
444380
445381.. _floatobjects :
@@ -2435,7 +2371,7 @@ change in future releases of Python.
24352371.. cfunction :: int PyObject_AsFileDescriptor(PyObject *p)
24362372
24372373 Return the file descriptor associated with *p * as an :ctype: `int `. If the
2438- object is an integer or long integer , its value is returned. If not, the
2374+ object is an integer, its value is returned. If not, the
24392375 object's :meth: `fileno ` method is called if it exists; the method must return
24402376 an integer, which is returned as the file descriptor value. Sets an
24412377 exception and returns ``-1 `` on failure.
0 commit comments