[PYTHONMAC-SIG] Forwarded message: extension module

Jack Jansen subra@apple.com
Thu, 07 Mar 1996 11:34:53 +0100


For reasons unknown to me this message bounced to the -request address
(maybe because the subject starts with "HELP"?), so I'm forwarding
it. 
------- Forwarded Message
To: pythonmac-sig@python.org
From: subra@apple.com (Subra Mayilvahanan)
Subject: HELP: extension module

Hi I need some help with the python extension modules (Version 1.3).
I want to create my own extension module as a shared library on a powermac.

Here is what I did:
* Wrote a tiny module with just one function (source is included at the end.)
  Source file name: "myfirstmodule.c", shared lib name: "myfirstmodule".
* Copied the CW7 PythonCore project file, removed the sources from that and
  added my module source file (retained the run-time and shared lib glue stuff).
* Built the shared lib successfully and copied it to the system extension
  folder.
* Typed "import myfirstmodule" in "PythonPPC" std window.

I am getting an error saying "no module named myfirstmodule".

Any clues?

- -- Subra

- ---------------------------- 8< ------------- 8< -----------------------------
/* myfirstmodule */

#include "Python.h"

static PyObject* gMyFirstModuleError;

static PyObject*
myfirstmodule_add(PyObject* self, PyObject* args)
{
        int a1, a2;
        char result[1024];

        if (!PyArg_ParseTuple(args, "ii", &a1, &a2))
        {
                return NULL; /* invalid arguments */
        }

        sprintf(result, "%d", a1 + a2);
        return Py_BuildValue("s", result);
}

static PyMethodDef gMyFirstModuleMethods[] = {
        {"add", myfirstmodule_add, 1},
        {NULL,  NULL}
};

void
initmyfirstmodule()
{
        PyObject* m;
        PyObject* d;

        m = Py_InitModule("myfirstmodule", gMyFirstModuleMethods);
        d = PyModule_GetDict(m);
        gMyFirstModuleError = PyString_FromString("myfirstmodule.error");
        PyDict_SetItemString(d, "error", gMyFirstModuleError);
}

- ---------------------------- 8< ----------------- 8< -------------------------





------- End of Forwarded Message


=================
PYTHONMAC-SIG  - SIG on Python for the Apple Macintosh

send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
=================