Numpy Toy Box / convsrc / convsrcmodule.c.src

/* -*- c -*- */
#include <Python.h>

static PyObject *
fact(PyObject *self, PyObject *args)
{
  int n;
  int i;
  int ret=1;
 
  if (!PyArg_ParseTuple(args, "i", &n))
    return NULL;
 
  for (i=n; i>0; i--) ret *= i;
 
  return Py_BuildValue("i", ret);
}

static PyObject *
hello(PyObject *self, PyObject *args)
{
  printf("Hello World!!\n");
  Py_RETURN_NONE;
}

static PyObject *
goodbye(PyObject *self, PyObject *args)
{
  printf("Goodbye!!\n");
  Py_RETURN_NONE;
}

static PyObject *
combination(PyObject *self, PyObject *args)
{
  /* Cannot be used like this: 
     a = (func1(a), func2(a), func3(a))*3
     And:
     a = (func1(a,b,c), func2(a,b,c), func3(a,b,c))*3
   */

/**begin repeat
   # b = (This is B)*3,
         (Is this B?)*3,
         (This IS B)*3
   #
   # a = (func1_a, func2_a, func3_a)*3
   #
*/
  printf("combination a='@a@' b='@b@'\n");
/**end repeat**/
  Py_RETURN_NONE;
}

static char convsrc_doc[] = "C extention module example\n";

static PyMethodDef methods[] = {
/**begin repeat
   #func=fact, hello, goodbye, combination#
*/
  {"@func@", (PyCFunction)@func@, METH_VARARGS, "docstring of @func@.\n"},
/**end repeat**/
  {NULL, NULL}
};

#ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
initconvsrc(void)
{
  Py_InitModule3("convsrc", methods, convsrc_doc);
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.