Back to index

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

Go to the source code of this file.

Classes

struct  Noddy

Functions

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_noddy2 (void)

Variables

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

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 void Noddy_dealloc ( Noddy self) [static]

Definition at line 12 of file noddy2.c.

{
    Py_XDECREF(self->first);
    Py_XDECREF(self->last);
    Py_TYPE(self)->tp_free((PyObject*)self);
}
static int Noddy_init ( Noddy self,
PyObject args,
PyObject kwds 
) [static]

Definition at line 47 of file noddy2.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 87 of file noddy2.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 20 of file noddy2.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:

Definition at line 176 of file noddy2.c.

{
    PyObject* m;

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

    m = PyModule_Create(&noddy2module);
    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,
    "noddy2",
    "Example module that creates an extension type.",
    -1,
    NULL, NULL, NULL, NULL, NULL
}

Definition at line 167 of file noddy2.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 76 of file noddy2.c.

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

Definition at line 118 of file noddy2.c.

Definition at line 125 of file noddy2.c.