cpython/Include/abstract.h
Guido van Rossum cd16bf6404 Merged revisions 55817-55961 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk

................
  r55837 | guido.van.rossum | 2007-06-08 16:04:42 -0700 (Fri, 08 Jun 2007) | 2 lines

  PEP 3119 -- the abc module.
................
  r55838 | guido.van.rossum | 2007-06-08 17:38:55 -0700 (Fri, 08 Jun 2007) | 2 lines

  Implement part of PEP 3119 -- One Trick Ponies.
................
  r55847 | guido.van.rossum | 2007-06-09 08:28:06 -0700 (Sat, 09 Jun 2007) | 2 lines

  Different way to do one trick ponies, allowing registration (per PEP strawman).
................
  r55849 | guido.van.rossum | 2007-06-09 18:06:38 -0700 (Sat, 09 Jun 2007) | 3 lines

  Make sure that the magic looking for __hash__ (etc.) doesn't apply to
  real subclasses of Hashable.
................
  r55852 | guido.van.rossum | 2007-06-10 08:29:51 -0700 (Sun, 10 Jun 2007) | 2 lines

  Add some more examples, e.g. generators and dict views.
................
  r55853 | guido.van.rossum | 2007-06-10 08:31:59 -0700 (Sun, 10 Jun 2007) | 2 lines

  keys() and items() *are* containers -- just values() isn't.
................
  r55864 | georg.brandl | 2007-06-10 15:29:40 -0700 (Sun, 10 Jun 2007) | 2 lines

  PEP 3127: new octal literals, binary literals.
................
  r55865 | georg.brandl | 2007-06-10 15:31:37 -0700 (Sun, 10 Jun 2007) | 2 lines

  Some octal literal fixes in Tools.
................
  r55866 | georg.brandl | 2007-06-10 15:37:43 -0700 (Sun, 10 Jun 2007) | 2 lines

  Tokenizer changes for PEP 3127.
................
  r55867 | georg.brandl | 2007-06-10 15:37:55 -0700 (Sun, 10 Jun 2007) | 2 lines

  Some docs for PEP 3127.
................
  r55868 | georg.brandl | 2007-06-10 15:44:39 -0700 (Sun, 10 Jun 2007) | 2 lines

  Missed a place in intobject.c. Is that used anymore anyway?
................
  r55871 | neal.norwitz | 2007-06-10 18:31:49 -0700 (Sun, 10 Jun 2007) | 182 lines

  Merged revisions 55729-55868 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r55731 | neal.norwitz | 2007-06-01 00:29:12 -0700 (Fri, 01 Jun 2007) | 7 lines

    SF 1668596/1720897: distutils now copies data files
    even if package_dir is empty.

    This needs to be backported.  I'm too tired tonight.  It would be great
    if someone backports this if the buildbots are ok with it.  Otherwise,
    I will try to get to it tomorrow.
  ........
    r55732 | georg.brandl | 2007-06-01 04:33:33 -0700 (Fri, 01 Jun 2007) | 2 lines

    Bug #1722484: remove docstrings again when running with -OO.
  ........
    r55735 | georg.brandl | 2007-06-01 12:20:27 -0700 (Fri, 01 Jun 2007) | 2 lines

    Fix wrong issue number.
  ........
    r55739 | brett.cannon | 2007-06-01 20:02:29 -0700 (Fri, 01 Jun 2007) | 3 lines

    Have configure raise an error when building on AtheOS.  Code specific to AtheOS
    will be removed in Python 2.7.
  ........
    r55746 | neal.norwitz | 2007-06-02 11:33:53 -0700 (Sat, 02 Jun 2007) | 1 line

    Update expected birthday of 2.6
  ........
    r55751 | neal.norwitz | 2007-06-03 13:32:50 -0700 (Sun, 03 Jun 2007) | 10 lines

    Backout the original 'fix' to 1721309 which had no effect.
    Different versions of Berkeley DB handle this differently.
    The comments and bug report should have the details.  Memory is allocated
    in 4.4 (and presumably earlier), but not in 4.5.  Thus
    4.5 has the free error, but not earlier versions.

    Mostly update comments, plus make the free conditional.

    This fix was already applied to the 2.5 branch.
  ........
    r55752 | brett.cannon | 2007-06-03 16:13:41 -0700 (Sun, 03 Jun 2007) | 6 lines

    Make _strptime.TimeRE().pattern() use ``\s+`` for matching whitespace instead
    of ``\s*``.  This prevents patterns from "stealing" bits from other patterns in
    order to make a match work.

    Closes bug #1730389.  Will be backported.
  ........
    r55766 | hyeshik.chang | 2007-06-05 11:16:52 -0700 (Tue, 05 Jun 2007) | 4 lines

    Fix build on FreeBSD.  Bluetooth HCI API in FreeBSD is quite different
    from Linux's.  Just fix the build for now but the code doesn't
    support the complete capability of HCI on FreeBSD yet.
  ........
    r55770 | hyeshik.chang | 2007-06-05 11:58:51 -0700 (Tue, 05 Jun 2007) | 4 lines

    Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it
    reads a file that ends with incomplete sequence and sizehint argument
    for .read() is specified.
  ........
    r55775 | hyeshik.chang | 2007-06-05 12:28:15 -0700 (Tue, 05 Jun 2007) | 2 lines

    Fix for Windows: close a temporary file before trying to delete it.
  ........
    r55783 | guido.van.rossum | 2007-06-05 14:24:47 -0700 (Tue, 05 Jun 2007) | 2 lines

    Patch by Tim Delany (missing DECREF). SF #1731330.
  ........
    r55785 | collin.winter | 2007-06-05 17:17:35 -0700 (Tue, 05 Jun 2007) | 3 lines

    Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O).
  ........
    r55786 | facundo.batista | 2007-06-06 08:13:37 -0700 (Wed, 06 Jun 2007) | 4 lines


    FTP.ntransfercmd method now uses create_connection when passive,
    using the timeout received in connection time.
  ........
    r55792 | facundo.batista | 2007-06-06 10:15:23 -0700 (Wed, 06 Jun 2007) | 7 lines


    Added an optional timeout parameter to function urllib2.urlopen,
    with tests in test_urllib2net.py (must have network resource
    enabled to execute them). Also modified test_urllib2.py because
    testing mock classes must take it into acount. Docs are also
    updated.
  ........
    r55793 | thomas.heller | 2007-06-06 13:19:19 -0700 (Wed, 06 Jun 2007) | 1 line

    Build _ctypes and _ctypes_test in the ReleaseAMD64 configuration.
  ........
    r55802 | georg.brandl | 2007-06-07 06:23:24 -0700 (Thu, 07 Jun 2007) | 3 lines

    Disallow function calls like foo(None=1).
    Backport from py3k rev. 55708 by Guido.
  ........
    r55804 | georg.brandl | 2007-06-07 06:30:24 -0700 (Thu, 07 Jun 2007) | 2 lines

    Make reindent.py executable.
  ........
    r55805 | georg.brandl | 2007-06-07 06:34:10 -0700 (Thu, 07 Jun 2007) | 2 lines

    Patch #1667860: Fix UnboundLocalError in urllib2.
  ........
    r55821 | kristjan.jonsson | 2007-06-07 16:53:49 -0700 (Thu, 07 Jun 2007) | 1 line

    Fixing changes to getbuildinfo.c that broke linux builds
  ........
    r55828 | thomas.heller | 2007-06-08 09:10:27 -0700 (Fri, 08 Jun 2007) | 1 line

    Make this test work with older Python releases where struct has no 't' format character.
  ........
    r55829 | martin.v.loewis | 2007-06-08 10:29:20 -0700 (Fri, 08 Jun 2007) | 3 lines

    Bug #1733488: Fix compilation of bufferobject.c on AIX.
    Will backport to 2.5.
  ........
    r55831 | thomas.heller | 2007-06-08 11:20:09 -0700 (Fri, 08 Jun 2007) | 2 lines

    [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
    with small modifications.
  ........
    r55832 | thomas.heller | 2007-06-08 12:01:06 -0700 (Fri, 08 Jun 2007) | 1 line

    Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
  ........
    r55833 | thomas.heller | 2007-06-08 12:08:31 -0700 (Fri, 08 Jun 2007) | 2 lines

    Fix wrong documentation, and correct the punktuation.
    Closes [1700455].
  ........
    r55834 | thomas.heller | 2007-06-08 12:14:23 -0700 (Fri, 08 Jun 2007) | 1 line

    Fix warnings by using proper function prototype.
  ........
    r55839 | neal.norwitz | 2007-06-08 20:36:34 -0700 (Fri, 08 Jun 2007) | 7 lines

    Prevent expandtabs() on string and unicode objects from causing a segfault when
    a large width is passed on 32-bit platforms.  Found by Google.

    It would be good for people to review this especially carefully and verify
    I don't have an off by one error and there is no other way to cause overflow.
  ........
    r55841 | neal.norwitz | 2007-06-08 21:48:22 -0700 (Fri, 08 Jun 2007) | 1 line

    Use macro version of GET_SIZE to avoid Coverity warning (#150) about a possible error.
  ........
    r55842 | martin.v.loewis | 2007-06-09 00:42:52 -0700 (Sat, 09 Jun 2007) | 3 lines

    Patch #1733960: Allow T_LONGLONG to accept ints.
    Will backport to 2.5.
  ........
    r55843 | martin.v.loewis | 2007-06-09 00:58:05 -0700 (Sat, 09 Jun 2007) | 2 lines

    Fix Windows build.
  ........
    r55845 | martin.v.loewis | 2007-06-09 03:10:26 -0700 (Sat, 09 Jun 2007) | 2 lines

    Provide LLONG_MAX for S390.
  ........
    r55854 | thomas.heller | 2007-06-10 08:59:17 -0700 (Sun, 10 Jun 2007) | 4 lines


    First version of build scripts for Windows/AMD64 (no external
    components are built yet, and 'kill_python' is disabled).
  ........
    r55855 | thomas.heller | 2007-06-10 10:55:51 -0700 (Sun, 10 Jun 2007) | 3 lines

    For now, disable the _bsddb, _sqlite3, _ssl, _testcapi, _tkinter
    modules in the ReleaseAMD64 configuration because they do not compile.
  ........
    r55856 | thomas.heller | 2007-06-10 11:27:54 -0700 (Sun, 10 Jun 2007) | 1 line

    Need to set the environment variables, otherwise devenv.com is not found.
  ........
    r55860 | thomas.heller | 2007-06-10 14:01:17 -0700 (Sun, 10 Jun 2007) | 1 line

    Revert commit 55855.
  ........
................
  r55880 | neal.norwitz | 2007-06-10 22:07:36 -0700 (Sun, 10 Jun 2007) | 5 lines

  Fix the refleak counter on test_collections.  The ABC metaclass creates
  a registry which must be cleared on each run.  Otherwise, there *seem*
  to be refleaks when there really aren't any.  (The class is held within
  the registry even though it's no longer needed.)
................
  r55884 | neal.norwitz | 2007-06-10 22:46:33 -0700 (Sun, 10 Jun 2007) | 1 line

  These tests have been removed, so they are no longer needed here
................
  r55886 | georg.brandl | 2007-06-11 00:26:37 -0700 (Mon, 11 Jun 2007) | 3 lines

  Optimize access to True and False in the compiler (if True)
  and the peepholer (LOAD_NAME True).
................
  r55905 | georg.brandl | 2007-06-11 10:02:26 -0700 (Mon, 11 Jun 2007) | 5 lines

  Remove __oct__ and __hex__ and use __index__ for converting
  non-ints before formatting in a base.

  Add a bin() builtin.
................
  r55906 | georg.brandl | 2007-06-11 10:04:44 -0700 (Mon, 11 Jun 2007) | 2 lines

  int(x, 0) does not "guess".
................
  r55907 | georg.brandl | 2007-06-11 10:05:47 -0700 (Mon, 11 Jun 2007) | 2 lines

  Add a comment to explain that nb_oct and nb_hex are nonfunctional.
................
  r55908 | guido.van.rossum | 2007-06-11 10:49:18 -0700 (Mon, 11 Jun 2007) | 2 lines

  Get rid of unused imports and comment.
................
  r55910 | guido.van.rossum | 2007-06-11 13:05:17 -0700 (Mon, 11 Jun 2007) | 2 lines

  _Abstract.__new__ now requires either no arguments or __init__ overridden.
................
  r55911 | guido.van.rossum | 2007-06-11 13:07:49 -0700 (Mon, 11 Jun 2007) | 7 lines

  Move the collections ABCs to a separate file, _abcoll.py, in order to avoid
  needing to import _collections.so during the bootstrap (this will become
  apparent in the next submit of os.py).

  Add (plain and mutable) ABCs for Set, Mapping, Sequence.
................
  r55912 | guido.van.rossum | 2007-06-11 13:09:31 -0700 (Mon, 11 Jun 2007) | 2 lines

  Rewrite the _Environ class to use the new collections ABCs.
................
  r55913 | guido.van.rossum | 2007-06-11 13:59:45 -0700 (Mon, 11 Jun 2007) | 72 lines

  Merged revisions 55869-55912 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r55869 | neal.norwitz | 2007-06-10 17:42:11 -0700 (Sun, 10 Jun 2007) | 1 line

    Add Atul Varma for patch # 1667860
  ........
    r55870 | neal.norwitz | 2007-06-10 18:22:03 -0700 (Sun, 10 Jun 2007) | 1 line

    Ignore valgrind problems on Ubuntu from ld
  ........
    r55872 | neal.norwitz | 2007-06-10 18:48:46 -0700 (Sun, 10 Jun 2007) | 2 lines

    Ignore config.status.lineno which seems new (new autoconf?)
  ........
    r55873 | neal.norwitz | 2007-06-10 19:14:39 -0700 (Sun, 10 Jun 2007) | 1 line

    Prevent these tests from running on Win64 since they don\'t apply there either
  ........
    r55874 | neal.norwitz | 2007-06-10 19:16:10 -0700 (Sun, 10 Jun 2007) | 5 lines

    Fix a bug when there was a newline in the string expandtabs was called on.
    This also catches another condition that can overflow.

    Will backport.
  ........
    r55879 | neal.norwitz | 2007-06-10 21:52:37 -0700 (Sun, 10 Jun 2007) | 1 line

    Prevent hang if the port cannot be opened.
  ........
    r55881 | neal.norwitz | 2007-06-10 22:28:45 -0700 (Sun, 10 Jun 2007) | 4 lines

    Add all of the distuils modules that don't seem to have explicit tests. :-(
    Move an import in mworkscompiler so that this module can be imported on
    any platform.  Hopefully this works on all platforms.
  ........
    r55882 | neal.norwitz | 2007-06-10 22:35:10 -0700 (Sun, 10 Jun 2007) | 4 lines

    SF #1734732, lower case the module names per PEP 8.

    Will backport.
  ........
    r55885 | neal.norwitz | 2007-06-10 23:16:48 -0700 (Sun, 10 Jun 2007) | 4 lines

    Not sure why this only fails sometimes on Unix machines. Better
    to disable it and only import msvccompiler on Windows since that's
    the only place it can work anyways.
  ........
    r55887 | neal.norwitz | 2007-06-11 00:29:43 -0700 (Mon, 11 Jun 2007) | 4 lines

    Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute.

    Will backport
  ........
    r55889 | neal.norwitz | 2007-06-11 00:36:24 -0700 (Mon, 11 Jun 2007) | 1 line

    Reflow long line
  ........
    r55896 | thomas.heller | 2007-06-11 08:58:33 -0700 (Mon, 11 Jun 2007) | 3 lines

    Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
    or "K" codes.
  ........
    r55901 | facundo.batista | 2007-06-11 09:27:08 -0700 (Mon, 11 Jun 2007) | 5 lines


    Added versionchanged flag to all the methods which received
    a new optional timeout parameter, and a versionadded flag to
    the socket.create_connection function.
  ........
................
  r55914 | guido.van.rossum | 2007-06-11 14:19:50 -0700 (Mon, 11 Jun 2007) | 3 lines

  New super() implementation, for PEP 3135 (though the PEP is not yet updated
  to this design, and small tweaks may still be made later).
................
  r55923 | guido.van.rossum | 2007-06-11 21:15:24 -0700 (Mon, 11 Jun 2007) | 4 lines

  I'm guessing this module broke when Neal ripped out the types module --
  it used 'list' both as a local variable and as the built-in list type.
  Renamed the local variable since that was easier.
................
  r55924 | guido.van.rossum | 2007-06-11 21:20:05 -0700 (Mon, 11 Jun 2007) | 5 lines

  Change all occurrences of super(<thisclass>, <firstarg>) to super().
  Seems to have worked, all the tests still pass.
  Exception: test_descr and test_descrtut, which have tons of these
  and are there to test the various usages.
................
  r55939 | collin.winter | 2007-06-12 13:57:33 -0700 (Tue, 12 Jun 2007) | 1 line

  Patch #1735485: remove StandardError from the exception hierarchy.
................
  r55954 | neal.norwitz | 2007-06-12 21:56:32 -0700 (Tue, 12 Jun 2007) | 51 lines

  Merged revisions 55913-55950 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r55926 | marc-andre.lemburg | 2007-06-12 02:09:58 -0700 (Tue, 12 Jun 2007) | 3 lines

    Apply patch #1734945 to support TurboLinux as distribution.
  ........
    r55927 | marc-andre.lemburg | 2007-06-12 02:26:49 -0700 (Tue, 12 Jun 2007) | 3 lines

    Add patch #1726668: Windows Vista support.
  ........
    r55929 | thomas.heller | 2007-06-12 08:36:22 -0700 (Tue, 12 Jun 2007) | 1 line

    Checkout, but do not yet try to build, exernal sources.
  ........
    r55930 | thomas.heller | 2007-06-12 09:08:27 -0700 (Tue, 12 Jun 2007) | 6 lines

    Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
    right thing to do?).

    Set the /XP64 /RETAIL build enviroment in the makefile when building
    ReleaseAMD64.
  ........
    r55931 | thomas.heller | 2007-06-12 09:23:19 -0700 (Tue, 12 Jun 2007) | 5 lines

    Revert this change, since it breaks the win32 build:

    Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
    right thing to do?).
  ........
    r55934 | thomas.heller | 2007-06-12 10:28:31 -0700 (Tue, 12 Jun 2007) | 3 lines

    Specify the bufferoverflowU.lib to the makefile on the command line
    (for ReleaseAMD64 builds).
  ........
    r55937 | thomas.heller | 2007-06-12 12:02:59 -0700 (Tue, 12 Jun 2007) | 3 lines

    Add bufferoverflowU.lib to PCBuild\_bsddb.vcproj.
    Build sqlite3.dll and bsddb.
  ........
    r55938 | thomas.heller | 2007-06-12 12:56:12 -0700 (Tue, 12 Jun 2007) | 2 lines

    Don't rebuild Berkeley DB if not needed (this was committed by accident).
  ........
    r55948 | martin.v.loewis | 2007-06-12 20:42:19 -0700 (Tue, 12 Jun 2007) | 3 lines

    Provide PY_LLONG_MAX on all systems having long long.
    Will backport to 2.5.
  ........
................
  r55959 | guido.van.rossum | 2007-06-13 09:22:41 -0700 (Wed, 13 Jun 2007) | 2 lines

  Fix a compilation warning.
................
2007-06-13 18:07:49 +00:00

1190 lines
37 KiB
C++

#ifndef Py_ABSTRACTOBJECT_H
#define Py_ABSTRACTOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef PY_SSIZE_T_CLEAN
#define PyObject_CallFunction _PyObject_CallFunction_SizeT
#define PyObject_CallMethod _PyObject_CallMethod_SizeT
#endif
/* Abstract Object Interface (many thanks to Jim Fulton) */
/*
PROPOSAL: A Generic Python Object Interface for Python C Modules
Problem
Python modules written in C that must access Python objects must do
so through routines whose interfaces are described by a set of
include files. Unfortunately, these routines vary according to the
object accessed. To use these routines, the C programmer must check
the type of the object being used and must call a routine based on
the object type. For example, to access an element of a sequence,
the programmer must determine whether the sequence is a list or a
tuple:
if(is_tupleobject(o))
e=gettupleitem(o,i)
else if(is_listitem(o))
e=getlistitem(o,i)
If the programmer wants to get an item from another type of object
that provides sequence behavior, there is no clear way to do it
correctly.
The persistent programmer may peruse object.h and find that the
_typeobject structure provides a means of invoking up to (currently
about) 41 special operators. So, for example, a routine can get an
item from any object that provides sequence behavior. However, to
use this mechanism, the programmer must make their code dependent on
the current Python implementation.
Also, certain semantics, especially memory management semantics, may
differ by the type of object being used. Unfortunately, these
semantics are not clearly described in the current include files.
An abstract interface providing more consistent semantics is needed.
Proposal
I propose the creation of a standard interface (with an associated
library of routines and/or macros) for generically obtaining the
services of Python objects. This proposal can be viewed as one
components of a Python C interface consisting of several components.
From the viewpoint of C access to Python services, we have (as
suggested by Guido in off-line discussions):
- "Very high level layer": two or three functions that let you exec or
eval arbitrary Python code given as a string in a module whose name is
given, passing C values in and getting C values out using
mkvalue/getargs style format strings. This does not require the user
to declare any variables of type "PyObject *". This should be enough
to write a simple application that gets Python code from the user,
execs it, and returns the output or errors. (Error handling must also
be part of this API.)
- "Abstract objects layer": which is the subject of this proposal.
It has many functions operating on objects, and lest you do many
things from C that you can also write in Python, without going
through the Python parser.
- "Concrete objects layer": This is the public type-dependent
interface provided by the standard built-in types, such as floats,
strings, and lists. This interface exists and is currently
documented by the collection of include files provided with the
Python distributions.
From the point of view of Python accessing services provided by C
modules:
- "Python module interface": this interface consist of the basic
routines used to define modules and their members. Most of the
current extensions-writing guide deals with this interface.
- "Built-in object interface": this is the interface that a new
built-in type must provide and the mechanisms and rules that a
developer of a new built-in type must use and follow.
This proposal is a "first-cut" that is intended to spur
discussion. See especially the lists of notes.
The Python C object interface will provide four protocols: object,
numeric, sequence, and mapping. Each protocol consists of a
collection of related operations. If an operation that is not
provided by a particular type is invoked, then a standard exception,
NotImplementedError is raised with a operation name as an argument.
In addition, for convenience this interface defines a set of
constructors for building objects of built-in types. This is needed
so new objects can be returned from C functions that otherwise treat
objects generically.
Memory Management
For all of the functions described in this proposal, if a function
retains a reference to a Python object passed as an argument, then the
function will increase the reference count of the object. It is
unnecessary for the caller to increase the reference count of an
argument in anticipation of the object's retention.
All Python objects returned from functions should be treated as new
objects. Functions that return objects assume that the caller will
retain a reference and the reference count of the object has already
been incremented to account for this fact. A caller that does not
retain a reference to an object that is returned from a function
must decrement the reference count of the object (using
DECREF(object)) to prevent memory leaks.
Note that the behavior mentioned here is different from the current
behavior for some objects (e.g. lists and tuples) when certain
type-specific routines are called directly (e.g. setlistitem). The
proposed abstraction layer will provide a consistent memory
management interface, correcting for inconsistent behavior for some
built-in types.
Protocols
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/* Object Protocol: */
/* Implemented elsewhere:
int PyObject_Print(PyObject *o, FILE *fp, int flags);
Print an object, o, on file, fp. Returns -1 on
error. The flags argument is used to enable certain printing
options. The only option currently supported is Py_Print_RAW.
(What should be said about Py_Print_RAW?)
*/
/* Implemented elsewhere:
int PyObject_HasAttrString(PyObject *o, char *attr_name);
Returns 1 if o has the attribute attr_name, and 0 otherwise.
This is equivalent to the Python expression:
hasattr(o,attr_name).
This function always succeeds.
*/
/* Implemented elsewhere:
PyObject* PyObject_GetAttrString(PyObject *o, char *attr_name);
Retrieve an attributed named attr_name form object o.
Returns the attribute value on success, or NULL on failure.
This is the equivalent of the Python expression: o.attr_name.
*/
/* Implemented elsewhere:
int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
Returns 1 if o has the attribute attr_name, and 0 otherwise.
This is equivalent to the Python expression:
hasattr(o,attr_name).
This function always succeeds.
*/
/* Implemented elsewhere:
PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
Retrieve an attributed named attr_name form object o.
Returns the attribute value on success, or NULL on failure.
This is the equivalent of the Python expression: o.attr_name.
*/
/* Implemented elsewhere:
int PyObject_SetAttrString(PyObject *o, char *attr_name, PyObject *v);
Set the value of the attribute named attr_name, for object o,
to the value, v. Returns -1 on failure. This is
the equivalent of the Python statement: o.attr_name=v.
*/
/* Implemented elsewhere:
int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
Set the value of the attribute named attr_name, for object o,
to the value, v. Returns -1 on failure. This is
the equivalent of the Python statement: o.attr_name=v.
*/
/* implemented as a macro:
int PyObject_DelAttrString(PyObject *o, char *attr_name);
Delete attribute named attr_name, for object o. Returns
-1 on failure. This is the equivalent of the Python
statement: del o.attr_name.
*/
#define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL)
/* implemented as a macro:
int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
Delete attribute named attr_name, for object o. Returns -1
on failure. This is the equivalent of the Python
statement: del o.attr_name.
*/
#define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL)
PyAPI_FUNC(int) PyObject_Cmp(PyObject *o1, PyObject *o2, int *result);
/*
Compare the values of o1 and o2 using a routine provided by
o1, if one exists, otherwise with a routine provided by o2.
The result of the comparison is returned in result. Returns
-1 on failure. This is the equivalent of the Python
statement: result=cmp(o1,o2).
*/
/* Implemented elsewhere:
int PyObject_Compare(PyObject *o1, PyObject *o2);
Compare the values of o1 and o2 using a routine provided by
o1, if one exists, otherwise with a routine provided by o2.
Returns the result of the comparison on success. On error,
the value returned is undefined. This is equivalent to the
Python expression: cmp(o1,o2).
*/
/* Implemented elsewhere:
PyObject *PyObject_Repr(PyObject *o);
Compute the string representation of object, o. Returns the
string representation on success, NULL on failure. This is
the equivalent of the Python expression: repr(o).
Called by the repr() built-in function and by reverse quotes.
*/
/* Implemented elsewhere:
PyObject *PyObject_Str(PyObject *o);
Compute the string representation of object, o. Returns the
string representation on success, NULL on failure. This is
the equivalent of the Python expression: str(o).)
Called by the str() built-in function and by the print
statement.
*/
/* Implemented elsewhere:
PyObject *PyObject_Unicode(PyObject *o);
Compute the unicode representation of object, o. Returns the
unicode representation on success, NULL on failure. This is
the equivalent of the Python expression: unistr(o).)
Called by the unistr() built-in function.
*/
/* Declared elsewhere
PyAPI_FUNC(int) PyCallable_Check(PyObject *o);
Determine if the object, o, is callable. Return 1 if the
object is callable and 0 otherwise.
This function always succeeds.
*/
PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object,
PyObject *args, PyObject *kw);
/*
Call a callable Python object, callable_object, with
arguments and keywords arguments. The 'args' argument can not be
NULL, but the 'kw' argument can be NULL.
*/
PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object,
PyObject *args);
/*
Call a callable Python object, callable_object, with
arguments given by the tuple, args. If no arguments are
needed, then args may be NULL. Returns the result of the
call on success, or NULL on failure. This is the equivalent
of the Python expression: o(*args).
*/
PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object,
char *format, ...);
/*
Call a callable Python object, callable_object, with a
variable number of C arguments. The C arguments are described
using a mkvalue-style format string. The format may be NULL,
indicating that no arguments are provided. Returns the
result of the call on success, or NULL on failure. This is
the equivalent of the Python expression: o(*args).
*/
PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, char *method,
char *format, ...);
/*
Call the method named m of object o with a variable number of
C arguments. The C arguments are described by a mkvalue
format string. The format may be NULL, indicating that no
arguments are provided. Returns the result of the call on
success, or NULL on failure. This is the equivalent of the
Python expression: o.method(args).
*/
PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
char *format, ...);
PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o,
char *name,
char *format, ...);
PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
...);
/*
Call a callable Python object, callable_object, with a
variable number of C arguments. The C arguments are provided
as PyObject * values, terminated by a NULL. Returns the
result of the call on success, or NULL on failure. This is
the equivalent of the Python expression: o(*args).
*/
PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o,
PyObject *method, ...);
/*
Call the method named m of object o with a variable number of
C arguments. The C arguments are provided as PyObject *
values, terminated by NULL. Returns the result of the call
on success, or NULL on failure. This is the equivalent of
the Python expression: o.method(args).
*/
/* Implemented elsewhere:
long PyObject_Hash(PyObject *o);
Compute and return the hash, hash_value, of an object, o. On
failure, return -1. This is the equivalent of the Python
expression: hash(o).
*/
/* Implemented elsewhere:
int PyObject_IsTrue(PyObject *o);
Returns 1 if the object, o, is considered to be true, 0 if o is
considered to be false and -1 on failure. This is equivalent to the
Python expression: not not o
*/
/* Implemented elsewhere:
int PyObject_Not(PyObject *o);
Returns 0 if the object, o, is considered to be true, 1 if o is
considered to be false and -1 on failure. This is equivalent to the
Python expression: not o
*/
PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
/*
On success, returns a type object corresponding to the object
type of object o. On failure, returns NULL. This is
equivalent to the Python expression: type(o).
*/
PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
/*
Return the size of object o. If the object, o, provides
both sequence and mapping protocols, the sequence size is
returned. On error, -1 is returned. This is the equivalent
to the Python expression: len(o).
*/
/* For DLL compatibility */
#undef PyObject_Length
PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
#define PyObject_Length PyObject_Size
PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o);
/*
Return the size of object o. If the object, o, provides
both sequence and mapping protocols, the sequence size is
returned. On error, -1 is returned. If the object provides
a __length_hint__() method, its value is returned. This is an
internal undocumented API provided for performance reasons;
for compatibility, don't use it outside the core. This is the
equivalent to the Python expression:
try:
return len(o)
except (AttributeError, TypeError):
exc_type, exc_value, exc_tb = sys.exc_info()
try:
return o.__length_hint__()
except:
pass
raise exc_type, exc_value, exc_tb
*/
PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
/*
Return element of o corresponding to the object, key, or NULL
on failure. This is the equivalent of the Python expression:
o[key].
*/
PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
/*
Map the object, key, to the value, v. Returns
-1 on failure. This is the equivalent of the Python
statement: o[key]=v.
*/
PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key);
/*
Remove the mapping for object, key, from the object *o.
Returns -1 on failure. This is equivalent to
the Python statement: del o[key].
*/
PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
/*
Delete the mapping for key from *o. Returns -1 on failure.
This is the equivalent of the Python statement: del o[key].
*/
PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
const char **buffer,
Py_ssize_t *buffer_len);
/*
Takes an arbitrary object which must support the (character,
single segment) buffer interface and returns a pointer to a
read-only memory location useable as character based input
for subsequent processing.
0 is returned on success. buffer and buffer_len are only
set in case no error occurs. Otherwise, -1 is returned and
an exception set.
*/
PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
/*
Checks whether an arbitrary object supports the (character,
single segment) buffer interface. Returns 1 on success, 0
on failure.
*/
PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
const void **buffer,
Py_ssize_t *buffer_len);
/*
Same as PyObject_AsCharBuffer() except that this API expects
(readable, single segment) buffer interface and returns a
pointer to a read-only memory location which can contain
arbitrary data.
0 is returned on success. buffer and buffer_len are only
set in case no error occurrs. Otherwise, -1 is returned and
an exception set.
*/
PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
void **buffer,
Py_ssize_t *buffer_len);
/*
Takes an arbitrary object which must support the (writeable,
single segment) buffer interface and returns a pointer to a
writeable memory location in buffer of size buffer_len.
0 is returned on success. buffer and buffer_len are only
set in case no error occurrs. Otherwise, -1 is returned and
an exception set.
*/
/* Iterators */
PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
/* Takes an object and returns an iterator for it.
This is typically a new iterator but if the argument
is an iterator, this returns itself. */
#define PyIter_Check(obj) \
((obj)->ob_type->tp_iternext != NULL)
PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
/* Takes an iterator object and calls its tp_iternext slot,
returning the next value. If the iterator is exhausted,
this returns NULL without setting an exception.
NULL with an exception means an error occurred. */
/* Number Protocol:*/
PyAPI_FUNC(int) PyNumber_Check(PyObject *o);
/*
Returns 1 if the object, o, provides numeric protocols, and
false otherwise.
This function always succeeds.
*/
PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
/*
Returns the result of adding o1 and o2, or null on failure.
This is the equivalent of the Python expression: o1+o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
/*
Returns the result of subtracting o2 from o1, or null on
failure. This is the equivalent of the Python expression:
o1-o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
/*
Returns the result of multiplying o1 and o2, or null on
failure. This is the equivalent of the Python expression:
o1*o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Divide(PyObject *o1, PyObject *o2);
/*
Returns the result of dividing o1 by o2, or null on failure.
This is the equivalent of the Python expression: o1/o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
/*
Returns the result of dividing o1 by o2 giving an integral result,
or null on failure.
This is the equivalent of the Python expression: o1//o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
/*
Returns the result of dividing o1 by o2 giving a float result,
or null on failure.
This is the equivalent of the Python expression: o1/o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
/*
Returns the remainder of dividing o1 by o2, or null on
failure. This is the equivalent of the Python expression:
o1%o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
/*
See the built-in function divmod. Returns NULL on failure.
This is the equivalent of the Python expression:
divmod(o1,o2).
*/
PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
PyObject *o3);
/*
See the built-in function pow. Returns NULL on failure.
This is the equivalent of the Python expression:
pow(o1,o2,o3), where o3 is optional.
*/
PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
/*
Returns the negation of o on success, or null on failure.
This is the equivalent of the Python expression: -o.
*/
PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
/*
Returns the (what?) of o on success, or NULL on failure.
This is the equivalent of the Python expression: +o.
*/
PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
/*
Returns the absolute value of o, or null on failure. This is
the equivalent of the Python expression: abs(o).
*/
PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
/*
Returns the bitwise negation of o on success, or NULL on
failure. This is the equivalent of the Python expression:
~o.
*/
PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
/*
Returns the result of left shifting o1 by o2 on success, or
NULL on failure. This is the equivalent of the Python
expression: o1 << o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
/*
Returns the result of right shifting o1 by o2 on success, or
NULL on failure. This is the equivalent of the Python
expression: o1 >> o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
/*
Returns the result of bitwise and of o1 and o2 on success, or
NULL on failure. This is the equivalent of the Python
expression: o1&o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
/*
Returns the bitwise exclusive or of o1 by o2 on success, or
NULL on failure. This is the equivalent of the Python
expression: o1^o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
/*
Returns the result of bitwise or on o1 and o2 on success, or
NULL on failure. This is the equivalent of the Python
expression: o1|o2.
*/
#define PyIndex_Check(obj) \
((obj)->ob_type->tp_as_number != NULL && \
(obj)->ob_type->tp_as_number->nb_index != NULL)
PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
/*
Returns the object converted to a Python long or int
or NULL with an error raised on failure.
*/
PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
/*
Returns the object converted to Py_ssize_t by going through
PyNumber_Index first. If an overflow error occurs while
converting the int-or-long to Py_ssize_t, then the second argument
is the error-type to return. If it is NULL, then the overflow error
is cleared and the value is clipped.
*/
#define PyNumber_Int PyNumber_Long
/*
Returns the o converted to an integer object on success, or
NULL on failure. This is the equivalent of the Python
expression: int(o).
*/
PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
/*
Returns the o converted to a long integer object on success,
or NULL on failure. This is the equivalent of the Python
expression: long(o).
*/
PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
/*
Returns the o converted to a float object on success, or NULL
on failure. This is the equivalent of the Python expression:
float(o).
*/
/* In-place variants of (some of) the above number protocol functions */
PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
/*
Returns the result of adding o2 to o1, possibly in-place, or null
on failure. This is the equivalent of the Python expression:
o1 += o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
/*
Returns the result of subtracting o2 from o1, possibly in-place or
null on failure. This is the equivalent of the Python expression:
o1 -= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
/*
Returns the result of multiplying o1 by o2, possibly in-place, or
null on failure. This is the equivalent of the Python expression:
o1 *= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2);
/*
Returns the result of dividing o1 by o2, possibly in-place, or null
on failure. This is the equivalent of the Python expression:
o1 /= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
PyObject *o2);
/*
Returns the result of dividing o1 by o2 giving an integral result,
possibly in-place, or null on failure.
This is the equivalent of the Python expression:
o1 /= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
PyObject *o2);
/*
Returns the result of dividing o1 by o2 giving a float result,
possibly in-place, or null on failure.
This is the equivalent of the Python expression:
o1 /= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
/*
Returns the remainder of dividing o1 by o2, possibly in-place, or
null on failure. This is the equivalent of the Python expression:
o1 %= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
PyObject *o3);
/*
Returns the result of raising o1 to the power of o2, possibly
in-place, or null on failure. This is the equivalent of the Python
expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
/*
Returns the result of left shifting o1 by o2, possibly in-place, or
null on failure. This is the equivalent of the Python expression:
o1 <<= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
/*
Returns the result of right shifting o1 by o2, possibly in-place or
null on failure. This is the equivalent of the Python expression:
o1 >>= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
/*
Returns the result of bitwise and of o1 and o2, possibly in-place,
or null on failure. This is the equivalent of the Python
expression: o1 &= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
/*
Returns the bitwise exclusive or of o1 by o2, possibly in-place, or
null on failure. This is the equivalent of the Python expression:
o1 ^= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
/*
Returns the result of bitwise or of o1 and o2, possibly in-place,
or null on failure. This is the equivalent of the Python
expression: o1 |= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
/*
Returns the integer n converted to a string with a base, with a base
marker of 0b, 0o or 0x prefixed if applicable.
If n is not an int object, it is converted with PyNumber_Index first.
*/
/* Sequence protocol:*/
PyAPI_FUNC(int) PySequence_Check(PyObject *o);
/*
Return 1 if the object provides sequence protocol, and zero
otherwise.
This function always succeeds.
*/
PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
/*
Return the size of sequence object o, or -1 on failure.
*/
/* For DLL compatibility */
#undef PySequence_Length
PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);
#define PySequence_Length PySequence_Size
PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
/*
Return the concatenation of o1 and o2 on success, and NULL on
failure. This is the equivalent of the Python
expression: o1+o2.
*/
PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
/*
Return the result of repeating sequence object o count times,
or NULL on failure. This is the equivalent of the Python
expression: o1*count.
*/
PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
/*
Return the ith element of o, or NULL on failure. This is the
equivalent of the Python expression: o[i].
*/
PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
/*
Return the slice of sequence object o between i1 and i2, or
NULL on failure. This is the equivalent of the Python
expression: o[i1:i2].
*/
PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
/*
Assign object v to the ith element of o. Returns
-1 on failure. This is the equivalent of the Python
statement: o[i]=v.
*/
PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
/*
Delete the ith element of object v. Returns
-1 on failure. This is the equivalent of the Python
statement: del o[i].
*/
PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
PyObject *v);
/*
Assign the sequence object, v, to the slice in sequence
object, o, from i1 to i2. Returns -1 on failure. This is the
equivalent of the Python statement: o[i1:i2]=v.
*/
PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
/*
Delete the slice in sequence object, o, from i1 to i2.
Returns -1 on failure. This is the equivalent of the Python
statement: del o[i1:i2].
*/
PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);
/*
Returns the sequence, o, as a tuple on success, and NULL on failure.
This is equivalent to the Python expression: tuple(o)
*/
PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);
/*
Returns the sequence, o, as a list on success, and NULL on failure.
This is equivalent to the Python expression: list(o)
*/
PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
/*
Returns the sequence, o, as a tuple, unless it's already a
tuple or list. Use PySequence_Fast_GET_ITEM to access the
members of this list, and PySequence_Fast_GET_SIZE to get its length.
Returns NULL on failure. If the object does not support iteration,
raises a TypeError exception with m as the message text.
*/
#define PySequence_Fast_GET_SIZE(o) \
(PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
/*
Return the size of o, assuming that o was returned by
PySequence_Fast and is not NULL.
*/
#define PySequence_Fast_GET_ITEM(o, i)\
(PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
/*
Return the ith element of o, assuming that o was returned by
PySequence_Fast, and that i is within bounds.
*/
#define PySequence_ITEM(o, i)\
( o->ob_type->tp_as_sequence->sq_item(o, i) )
/* Assume tp_as_sequence and sq_item exist and that i does not
need to be corrected for a negative index
*/
#define PySequence_Fast_ITEMS(sf) \
(PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
: ((PyTupleObject *)(sf))->ob_item)
/* Return a pointer to the underlying item array for
an object retured by PySequence_Fast */
PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
/*
Return the number of occurrences on value on o, that is,
return the number of keys for which o[key]==value. On
failure, return -1. This is equivalent to the Python
expression: o.count(value).
*/
PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
/*
Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
Use __contains__ if possible, else _PySequence_IterSearch().
*/
#define PY_ITERSEARCH_COUNT 1
#define PY_ITERSEARCH_INDEX 2
#define PY_ITERSEARCH_CONTAINS 3
PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,
PyObject *obj, int operation);
/*
Iterate over seq. Result depends on the operation:
PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
error.
PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of
obj in seq; set ValueError and return -1 if none found;
also return -1 on error.
PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
error.
*/
/* For DLL-level backwards compatibility */
#undef PySequence_In
PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);
/* For source-level backwards compatibility */
#define PySequence_In PySequence_Contains
/*
Determine if o contains value. If an item in o is equal to
X, return 1, otherwise return 0. On error, return -1. This
is equivalent to the Python expression: value in o.
*/
PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);
/*
Return the first index for which o[i]=value. On error,
return -1. This is equivalent to the Python
expression: o.index(value).
*/
/* In-place versions of some of the above Sequence functions. */
PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
/*
Append o2 to o1, in-place when possible. Return the resulting
object, which could be o1, or NULL on failure. This is the
equivalent of the Python expression: o1 += o2.
*/
PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
/*
Repeat o1 by count, in-place when possible. Return the resulting
object, which could be o1, or NULL on failure. This is the
equivalent of the Python expression: o1 *= count.
*/
/* Mapping protocol:*/
PyAPI_FUNC(int) PyMapping_Check(PyObject *o);
/*
Return 1 if the object provides mapping protocol, and zero
otherwise.
This function always succeeds.
*/
PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
/*
Returns the number of keys in object o on success, and -1 on
failure. For objects that do not provide sequence protocol,
this is equivalent to the Python expression: len(o).
*/
/* For DLL compatibility */
#undef PyMapping_Length
PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
#define PyMapping_Length PyMapping_Size
/* implemented as a macro:
int PyMapping_DelItemString(PyObject *o, char *key);
Remove the mapping for object, key, from the object *o.
Returns -1 on failure. This is equivalent to
the Python statement: del o[key].
*/
#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
/* implemented as a macro:
int PyMapping_DelItem(PyObject *o, PyObject *key);
Remove the mapping for object, key, from the object *o.
Returns -1 on failure. This is equivalent to
the Python statement: del o[key].
*/
#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, char *key);
/*
On success, return 1 if the mapping object has the key, key,
and 0 otherwise. This is equivalent to the Python expression:
key in o.
This function always succeeds.
*/
PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);
/*
Return 1 if the mapping object has the key, key,
and 0 otherwise. This is equivalent to the Python expression:
key in o.
This function always succeeds.
*/
PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o);
/*
On success, return a list or tuple of the keys in object o.
On failure, return NULL.
*/
PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o);
/*
On success, return a list or tuple of the values in object o.
On failure, return NULL.
*/
PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o);
/*
On success, return a list or tuple of the items in object o,
where each item is a tuple containing a key-value pair.
On failure, return NULL.
*/
PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, char *key);
/*
Return element of o corresponding to the object, key, or NULL
on failure. This is the equivalent of the Python expression:
o[key].
*/
PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, char *key,
PyObject *value);
/*
Map the object, key, to the value, v. Returns
-1 on failure. This is the equivalent of the Python
statement: o[key]=v.
*/
PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
/* isinstance(object, typeorclass) */
PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
/* issubclass(object, typeorclass) */
#ifdef __cplusplus
}
#endif
#endif /* Py_ABSTRACTOBJECT_H */