File: greet3.c

package info (click to toggle)
python-virtualenv 20.17.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,580 kB
  • sloc: python: 9,952; sh: 149; ansic: 61; csh: 35; makefile: 10
file content (38 lines) | stat: -rw-r--r-- 653 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <Python.h>

static PyObject * greet(PyObject * self, PyObject * args) {
  const char * name;
  if (!PyArg_ParseTuple(args, "s", & name)) {
    return NULL;
  }
  printf("Hello %s!\n", name);
  Py_RETURN_NONE;
}

static PyMethodDef GreetMethods[] = {
  {
    "greet",
    greet,
    METH_VARARGS,
    "Greet an entity."
  },
  {
    NULL,
    NULL,
    0,
    NULL
  }
};

static struct PyModuleDef greet_definition = {
  PyModuleDef_HEAD_INIT,
  "greet",
  "A Python module that prints 'greet world' from C code.",
  -1,
  GreetMethods
};

PyMODINIT_FUNC PyInit_greet(void) {
  return PyModule_Create( & greet_definition);
}