Back to index

python3.2  3.2.2
Classes | Defines | Functions | Variables
xxmodule.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_bug (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_xx (void)

Variables

static PyObjectErrorObject
static PyTypeObject Xxo_Type
static PyMethodDef Xxo_methods []
static PyTypeObject Str_Type
static PyTypeObject Null_Type
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 xxmodule.c.


Function Documentation

static XxoObject* newXxoObject ( PyObject arg) [static]

Definition at line 31 of file xxmodule.c.

{
    XxoObject *self;
    self = PyObject_New(XxoObject, &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 264 of file xxmodule.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 353 of file xxmodule.c.

{
    PyObject *m = NULL;

    /* Due to cross platform compiler issues the slots must be filled
     * here. It's required for portability to Windows without requiring
     * C++. */
    Null_Type.tp_base = &PyBaseObject_Type;
    Null_Type.tp_new = PyType_GenericNew;
    Str_Type.tp_base = &PyUnicode_Type;

    /* Finalize the type object including setting type of the new type
     * object; doing it here is required for portability, too. */
    if (PyType_Ready(&Xxo_Type) < 0)
        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("xx.error", NULL, NULL);
        if (ErrorObject == NULL)
            goto fail;
    }
    Py_INCREF(ErrorObject);
    PyModule_AddObject(m, "error", ErrorObject);

    /* Add Str */
    if (PyType_Ready(&Str_Type) < 0)
        goto fail;
    PyModule_AddObject(m, "Str", (PyObject *)&Str_Type);

    /* Add Null */
    if (PyType_Ready(&Null_Type) < 0)
        goto fail;
    PyModule_AddObject(m, "Null", (PyObject *)&Null_Type);
    return m;
 fail:
    Py_XDECREF(m);
    return NULL;
}

Here is the call graph for this function:

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

Definition at line 181 of file xxmodule.c.

{
    PyObject *list, *item;

    if (!PyArg_ParseTuple(args, "O:bug", &list))
        return NULL;

    item = PyList_GetItem(list, 0);
    /* Py_INCREF(item); */
    PyList_SetItem(list, 1, PyLong_FromLong(0L));
    PyObject_Print(item, stdout, 0);
    printf("\n");
    /* Py_DECREF(item); */

    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

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

Definition at line 152 of file xxmodule.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 166 of file xxmodule.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 202 of file xxmodule.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 xxmodule.c.

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

Definition at line 51 of file xxmodule.c.

{
    if (!PyArg_ParseTuple(args, ":demo"))
        return NULL;
    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 66 of file xxmodule.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 79 of file xxmodule.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 xxmodule.c.

Definition at line 270 of file xxmodule.c.

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

Definition at line 340 of file xxmodule.c.

Definition at line 215 of file xxmodule.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")},
    {"bug",             xx_bug,         METH_VARARGS,
        PyDoc_STR("bug(o) -> None")},
    {NULL,              NULL}           
}

Definition at line 322 of file xxmodule.c.

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

Definition at line 59 of file xxmodule.c.

static PyTypeObject Xxo_Type [static]

Definition at line 26 of file xxmodule.c.