root/pymain.c

Revision 1, 1.1 KB (checked in by root, 3 years ago)

Initial commit

Line 
1#include "Python.h"
2#include <stdio.h>
3#include <unistd.h>
4#include <pthread.h>
5
6
7PyObject* py_main(PyObject *_, PyObject *args);
8
9static PyMethodDef mtds[] = {
10  {"py_main",  py_main,  METH_VARARGS},
11  {NULL, NULL, 0,  NULL}
12};
13
14
15
16PyMODINIT_FUNC initpymain(void)
17{
18  Py_InitModule("pymain", mtds);
19}
20
21void* dead(void*_)
22{
23  for(;;) {
24    puts("...");
25    sleep(3);
26  }
27}
28
29void blah(int argc, char **argv)
30{
31  int i;
32  pthread_t t;
33
34  for(i = 0; i < argc; ++i)
35    puts(argv[i]);
36
37
38  pthread_create(&t, NULL, dead, NULL);
39}
40
41PyObject* py_main(PyObject *_, PyObject *args)
42{
43  int sz;
44  int i;
45  int argc;
46  char ** argv;
47
48  if(!PyTuple_Check(args)) Py_RETURN_NONE;
49
50  sz = PyTuple_Size(args);
51  for(i = 0; i < sz; ++i)
52    if(!PyString_Check(PyTuple_GetItem(args, i)))
53      Py_RETURN_NONE;
54
55
56  argc = sz + 1;
57  argv = malloc(argc * sizeof(char *));
58 
59  argv[0] = "py ewm II";
60  for(i = 1; i < argc; ++i) {
61    const char *str = PyString_AsString(PyTuple_GetItem(args, i - 1));
62    argv[i] = malloc(strlen(str + 1));
63    strcpy(argv[i], str);
64  }
65
66  blah(argc, argv);
67  Py_RETURN_NONE;
68}
Note: See TracBrowser for help on using the browser.