~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Include/methodobject.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* Method object interface */
 
3
 
 
4
#ifndef Py_METHODOBJECT_H
 
5
#define Py_METHODOBJECT_H
 
6
#ifdef __cplusplus
 
7
extern "C" {
 
8
#endif
 
9
 
 
10
/* This is about the type 'builtin_function_or_method',
 
11
   not Python methods in user-defined classes.  See classobject.h
 
12
   for the latter. */
 
13
 
 
14
PyAPI_DATA(PyTypeObject) PyCFunction_Type;
 
15
 
 
16
#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
 
17
 
 
18
typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
 
19
typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
 
20
                                             PyObject *);
 
21
typedef PyObject *(*PyNoArgsFunction)(PyObject *);
 
22
 
 
23
PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
 
24
PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
 
25
PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
 
26
 
 
27
/* Macros for direct access to these values. Type checks are *not*
 
28
   done, so use with care. */
 
29
#define PyCFunction_GET_FUNCTION(func) \
 
30
        (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
 
31
#define PyCFunction_GET_SELF(func) \
 
32
        (((PyCFunctionObject *)func) -> m_self)
 
33
#define PyCFunction_GET_FLAGS(func) \
 
34
        (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
 
35
PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
 
36
 
 
37
struct PyMethodDef {
 
38
    const char  *ml_name;       /* The name of the built-in function/method */
 
39
    PyCFunction  ml_meth;       /* The C function that implements it */
 
40
    int          ml_flags;      /* Combination of METH_xxx flags, which mostly
 
41
                                   describe the args expected by the C func */
 
42
    const char  *ml_doc;        /* The __doc__ attribute, or NULL */
 
43
};
 
44
typedef struct PyMethodDef PyMethodDef;
 
45
 
 
46
#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
 
47
PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, 
 
48
                                         PyObject *);
 
49
 
 
50
/* Flag passed to newmethodobject */
 
51
/* #define METH_OLDARGS  0x0000   -- unsupported now */
 
52
#define METH_VARARGS  0x0001
 
53
#define METH_KEYWORDS 0x0002
 
54
/* METH_NOARGS and METH_O must not be combined with the flags above. */
 
55
#define METH_NOARGS   0x0004
 
56
#define METH_O        0x0008
 
57
 
 
58
/* METH_CLASS and METH_STATIC are a little different; these control
 
59
   the construction of methods for a class.  These cannot be used for
 
60
   functions in modules. */
 
61
#define METH_CLASS    0x0010
 
62
#define METH_STATIC   0x0020
 
63
 
 
64
/* METH_COEXIST allows a method to be entered even though a slot has
 
65
   already filled the entry.  When defined, the flag allows a separate
 
66
   method, "__contains__" for example, to coexist with a defined 
 
67
   slot like sq_contains. */
 
68
 
 
69
#define METH_COEXIST   0x0040
 
70
 
 
71
typedef struct {
 
72
    PyObject_HEAD
 
73
    PyMethodDef *m_ml; /* Description of the C function to call */
 
74
    PyObject    *m_self; /* Passed as 'self' arg to the C func, can be NULL */
 
75
    PyObject    *m_module; /* The __module__ attribute, can be anything */
 
76
} PyCFunctionObject;
 
77
 
 
78
PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);
 
79
 
 
80
#ifdef __cplusplus
 
81
}
 
82
#endif
 
83
#endif /* !Py_METHODOBJECT_H */