Back to index

python3.2  3.2.2
Classes | Functions | Variables
noddy4.c File Reference
#include <Python.h>
#include "structmember.h"

Go to the source code of this file.

Classes

struct  Noddy

Functions

static int Noddy_traverse (Noddy *self, visitproc visit, void *arg)
static int Noddy_clear (Noddy *self)
static void Noddy_dealloc (Noddy *self)
static PyObjectNoddy_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
static int Noddy_init (Noddy *self, PyObject *args, PyObject *kwds)
static PyObjectNoddy_name (Noddy *self)
PyMODINIT_FUNC PyInit_noddy4 (void)

Variables

static PyMemberDef Noddy_members []
static PyMethodDef Noddy_methods []
static PyTypeObject NoddyType
static PyModuleDef noddy4module

Class Documentation

struct Noddy

Definition at line 4 of file noddy2.c.

Collaboration diagram for Noddy:
Class Members
PyObject_HEAD PyObject * first
PyObject * last
int number

Function Documentation

static int Noddy_clear ( Noddy self) [static]

Definition at line 31 of file noddy4.c.

{
    PyObject *tmp;

    tmp = self->first;
    self->first = NULL;
    Py_XDECREF(tmp);

    tmp = self->last;
    self->last = NULL;
    Py_XDECREF(tmp);

    return 0;
}

Here is the caller graph for this function:

static void Noddy_dealloc ( Noddy self) [static]

Definition at line 47 of file noddy4.c.

{
    Noddy_clear(self);
    Py_TYPE(self)->tp_free((PyObject*)self);
}

Here is the call graph for this function:

static int Noddy_init ( Noddy self,
PyObject args,
PyObject kwds 
) [static]

Definition at line 81 of file noddy4.c.

{
    PyObject *first=NULL, *last=NULL, *tmp;

    static char *kwlist[] = {"first", "last", "number", NULL};

    if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist, 
                                      &first, &last, 
                                      &self->number))
        return -1; 

    if (first) {
        tmp = self->first;
        Py_INCREF(first);
        self->first = first;
        Py_XDECREF(tmp);
    }

    if (last) {
        tmp = self->last;
        Py_INCREF(last);
        self->last = last;
        Py_XDECREF(tmp);
    }

    return 0;
}

Here is the call graph for this function:

static PyObject* Noddy_name ( Noddy self) [static]

Definition at line 121 of file noddy4.c.

{
    static PyObject *format = NULL;
    PyObject *args, *result;

    if (format == NULL) {
        format = PyUnicode_FromString("%s %s");
        if (format == NULL)
            return NULL;
    }

    if (self->first == NULL) {
        PyErr_SetString(PyExc_AttributeError, "first");
        return NULL;
    }

    if (self->last == NULL) {
        PyErr_SetString(PyExc_AttributeError, "last");
        return NULL;
    }

    args = Py_BuildValue("OO", self->first, self->last);
    if (args == NULL)
        return NULL;

    result = PyUnicode_Format(format, args);
    Py_DECREF(args);
    
    return result;
}

Here is the call graph for this function:

static PyObject* Noddy_new ( PyTypeObject type,
PyObject args,
PyObject kwds 
) [static]

Definition at line 54 of file noddy4.c.

{
    Noddy *self;

    self = (Noddy *)type->tp_alloc(type, 0);
    if (self != NULL) {
        self->first = PyUnicode_FromString("");
        if (self->first == NULL)
          {
            Py_DECREF(self);
            return NULL;
          }
        
        self->last = PyUnicode_FromString("");
        if (self->last == NULL)
          {
            Py_DECREF(self);
            return NULL;
          }

        self->number = 0;
    }

    return (PyObject *)self;
}

Here is the call graph for this function:

static int Noddy_traverse ( Noddy self,
visitproc  visit,
void arg 
) [static]

Definition at line 12 of file noddy4.c.

{
    int vret;

    if (self->first) {
        vret = visit(self->first, arg);
        if (vret != 0)
            return vret;
    }
    if (self->last) {
        vret = visit(self->last, arg);
        if (vret != 0)
            return vret;
    }

    return 0;
}

Here is the call graph for this function:

Definition at line 211 of file noddy4.c.

{
    PyObject* m;

    if (PyType_Ready(&NoddyType) < 0)
        return NULL;

    m = PyModule_Create(&noddy4module);
    if (m == NULL)
        return NULL;

    Py_INCREF(&NoddyType);
    PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType);
    return m;
}

Here is the call graph for this function:


Variable Documentation

Initial value:
 {
    PyModuleDef_HEAD_INIT,
    "noddy4",
    "Example module that creates an extension type.",
    -1,
    NULL, NULL, NULL, NULL, NULL
}

Definition at line 202 of file noddy4.c.

Initial value:
 {
    {"first", T_OBJECT_EX, offsetof(Noddy, first), 0,
     "first name"},
    {"last", T_OBJECT_EX, offsetof(Noddy, last), 0,
     "last name"},
    {"number", T_INT, offsetof(Noddy, number), 0,
     "noddy number"},
    {NULL}  
}

Definition at line 110 of file noddy4.c.

Initial value:
 {
    {"name", (PyCFunction)Noddy_name, METH_NOARGS,
     "Return the name, combining the first and last name"
    },
    {NULL}  
}

Definition at line 152 of file noddy4.c.

Definition at line 159 of file noddy4.c.