Back to index

python3.2  3.2.2
Classes | Defines | Functions | Variables
xxlimited.c File Reference
#include "Python.h"

Go to the source code of this file.

Classes

struct  XxoObject

Defines

#define XxoObject_Check(v)   (Py_TYPE(v) == Xxo_Type)

Functions

static XxoObjectnewXxoObject (PyObject *arg)
static void Xxo_dealloc (XxoObject *self)
static PyObjectXxo_demo (XxoObject *self, PyObject *args)
static PyObjectXxo_getattro (XxoObject *self, PyObject *name)
static int Xxo_setattr (XxoObject *self, char *name, PyObject *v)
 PyDoc_STRVAR (xx_foo_doc,"foo(i,j)\n\ \n\ Return the sum of i and j.")
static PyObjectxx_foo (PyObject *self, PyObject *args)
static PyObjectxx_new (PyObject *self, PyObject *args)
static PyObjectxx_roj (PyObject *self, PyObject *args)
static PyObjectnull_richcompare (PyObject *self, PyObject *other, int op)
 PyDoc_STRVAR (module_doc,"This is a template module just for instruction.")
PyMODINIT_FUNC PyInit_xxlimited (void)

Variables

static PyObjectErrorObject
static PyObjectXxo_Type
static PyMethodDef Xxo_methods []
static PyType_Slot Xxo_Type_slots []
static PyType_Spec Xxo_Type_spec
static PyType_Slot Str_Type_slots []
static PyType_Spec Str_Type_spec
static PyType_Slot Null_Type_slots []
static PyType_Spec Null_Type_spec
static PyMethodDef xx_methods []
static struct PyModuleDef

Class Documentation

struct XxoObject

Definition at line 21 of file xxlimited.c.

Collaboration diagram for XxoObject:
Class Members
PyObject_HEAD PyObject * x_attr

Define Documentation

#define XxoObject_Check (   v)    (Py_TYPE(v) == Xxo_Type)

Definition at line 28 of file xxlimited.c.


Function Documentation

static XxoObject* newXxoObject ( PyObject arg) [static]

Definition at line 31 of file xxlimited.c.

{
    XxoObject *self;
    self = PyObject_New(XxoObject, (PyTypeObject*)Xxo_Type);
    if (self == NULL)
        return NULL;
    self->x_attr = NULL;
    return self;
}

Here is the caller graph for this function:

static PyObject* null_richcompare ( PyObject self,
PyObject other,
int  op 
) [static]

Definition at line 188 of file xxlimited.c.

PyDoc_STRVAR ( xx_foo_doc  ,
"foo(i,j)\n\\n\Return the sum of i and j."   
)
PyDoc_STRVAR ( module_doc  ,
"This is a template module just for instruction."   
)

Definition at line 242 of file xxlimited.c.

{
    PyObject *m = NULL;
    PyObject *o;

    /* Due to cross platform compiler issues the slots must be filled
     * here. It's required for portability to Windows without requiring
     * C++. */
    Null_Type_slots[0].pfunc = &PyBaseObject_Type;
    Null_Type_slots[1].pfunc = PyType_GenericNew;
    Str_Type_slots[0].pfunc = &PyUnicode_Type;

    Xxo_Type = PyType_FromSpec(&Xxo_Type_spec);
    if (Xxo_Type == NULL)
        goto fail;

    /* Create the module and add the functions */
    m = PyModule_Create(&xxmodule);
    if (m == NULL)
        goto fail;

    /* Add some symbolic constants to the module */
    if (ErrorObject == NULL) {
        ErrorObject = PyErr_NewException("xxlimited.error", NULL, NULL);
        if (ErrorObject == NULL)
            goto fail;
    }
    Py_INCREF(ErrorObject);
    PyModule_AddObject(m, "error", ErrorObject);

    /* Add Str */
    o = PyType_FromSpec(&Str_Type_spec);
    if (o == NULL)
        goto fail;
    PyModule_AddObject(m, "Str", o);

    /* Add Null */
    o = PyType_FromSpec(&Null_Type_spec);
    if (o == NULL)
        goto fail;
    PyModule_AddObject(m, "Null", o);
    return m;
 fail:
    Py_XDECREF(m);
    return NULL;
}

Here is the call graph for this function:

static PyObject* xx_foo ( PyObject self,
PyObject args 
) [static]

Definition at line 130 of file xxlimited.c.

{
    long i, j;
    long res;
    if (!PyArg_ParseTuple(args, "ll:foo", &i, &j))
        return NULL;
    res = i+j; /* XXX Do something here */
    return PyLong_FromLong(res);
}

Here is the call graph for this function:

static PyObject* xx_new ( PyObject self,
PyObject args 
) [static]

Definition at line 144 of file xxlimited.c.

{
    XxoObject *rv;

    if (!PyArg_ParseTuple(args, ":new"))
        return NULL;
    rv = newXxoObject(args);
    if (rv == NULL)
        return NULL;
    return (PyObject *)rv;
}

Here is the call graph for this function:

static PyObject* xx_roj ( PyObject self,
PyObject args 
) [static]

Definition at line 159 of file xxlimited.c.

{
    PyObject *a;
    long b;
    if (!PyArg_ParseTuple(args, "O#:roj", &a, &b))
        return NULL;
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static void Xxo_dealloc ( XxoObject self) [static]

Definition at line 44 of file xxlimited.c.

{
    Py_XDECREF(self->x_attr);
    PyObject_Del(self);
}
static PyObject* Xxo_demo ( XxoObject self,
PyObject args 
) [static]

Definition at line 51 of file xxlimited.c.

{
    PyObject *o = NULL;
    if (!PyArg_ParseTuple(args, "|O:demo", &o))
        return NULL;
    /* Test availability of fast type checks */
    if (o != NULL && PyUnicode_Check(o)) {
        Py_INCREF(o);
        return o;
    }
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* Xxo_getattro ( XxoObject self,
PyObject name 
) [static]

Definition at line 72 of file xxlimited.c.

{
    if (self->x_attr != NULL) {
        PyObject *v = PyDict_GetItem(self->x_attr, name);
        if (v != NULL) {
            Py_INCREF(v);
            return v;
        }
    }
    return PyObject_GenericGetAttr((PyObject *)self, name);
}

Here is the call graph for this function:

static int Xxo_setattr ( XxoObject self,
char *  name,
PyObject v 
) [static]

Definition at line 85 of file xxlimited.c.

{
    if (self->x_attr == NULL) {
        self->x_attr = PyDict_New();
        if (self->x_attr == NULL)
            return -1;
    }
    if (v == NULL) {
        int rv = PyDict_DelItemString(self->x_attr, name);
        if (rv < 0)
            PyErr_SetString(PyExc_AttributeError,
                "delete non-existing Xxo attribute");
        return rv;
    }
    else
        return PyDict_SetItemString(self->x_attr, name, v);
}

Here is the call graph for this function:


Variable Documentation

PyObject* ErrorObject [static]

Definition at line 19 of file xxlimited.c.

Initial value:

Definition at line 194 of file xxlimited.c.

Initial value:
 {
    "xxlimited.Null",
    0,               
    0,               
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
    Null_Type_slots
}

Definition at line 201 of file xxlimited.c.

struct PyModuleDef [static]
Initial value:
 {
    PyModuleDef_HEAD_INIT,
    "xxlimited",
    module_doc,
    -1,
    xx_methods,
    NULL,
    NULL,
    NULL,
    NULL
}

Definition at line 229 of file xxlimited.c.

Initial value:
 {    
    {Py_tp_base, NULL}, 
    {0, 0},
}

Definition at line 172 of file xxlimited.c.

Initial value:
 {
    "xxlimited.Str",
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
    Str_Type_slots
}

Definition at line 177 of file xxlimited.c.

PyMethodDef xx_methods[] [static]
Initial value:
 {
    {"roj",             xx_roj,         METH_VARARGS,
        PyDoc_STR("roj(a,b) -> None")},
    {"foo",             xx_foo,         METH_VARARGS,
        xx_foo_doc},
    {"new",             xx_new,         METH_VARARGS,
        PyDoc_STR("new() -> new Xx object")},
    {NULL,              NULL}           
}

Definition at line 213 of file xxlimited.c.

Initial value:
 {
    {"demo",            (PyCFunction)Xxo_demo,  METH_VARARGS,
        PyDoc_STR("demo() -> None")},
    {NULL,              NULL}           
}

Definition at line 65 of file xxlimited.c.

PyObject* Xxo_Type [static]

Definition at line 26 of file xxlimited.c.

Initial value:

Definition at line 103 of file xxlimited.c.

Initial value:
 {
    "xxlimited.Xxo",
    sizeof(XxoObject),
    0,
    Py_TPFLAGS_DEFAULT,
    Xxo_Type_slots
}

Definition at line 112 of file xxlimited.c.