File: db.i

package info (click to toggle)
swig 1.1p5-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 9,448 kB
  • ctags: 5,025
  • sloc: cpp: 21,599; ansic: 13,333; yacc: 3,297; python: 2,794; makefile: 2,197; perl: 1,984; tcl: 1,583; sh: 736; lisp: 201; objc: 143
file content (51 lines) | stat: -rw-r--r-- 1,242 bytes parent folder | download | duplicates (4)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
// Simple database-like module.
// This shows how one can convert to and from C structures
// and Python tuples

%module db

%{
#include "db.h"
%}

// We use a typemap to define how we want to parse User records

// Define how a User record is to be passed into a C function
// This works for both "User" and "User *"

%typemap(python,in) User * {
  static User temp;                /* A temporary holding place */
  char       *login,*name,*home;   /* Temporary variables       */
  if (!PyArg_ParseTuple($source,"siiss",&login,&temp.uid,&temp.gid,&name,&home))
    return NULL;

  /* Safely copy passed values into our structure */

  strncpy(temp.login,login,16);
  strncpy(temp.name,name,32);
  strncpy(temp.home,home,256);

  /* Set the User * pointer to our temporary structure */

  $target = &temp;
}

// Describe how we want to return a user record

%typemap(python,out) User * {
  if ($source) {
    $target = Py_BuildValue("(siiss)",$source->login,$source->uid,
			    $source->gid,$source->name,$source->home);
  } else {
    $target = Py_None;
    Py_INCREF(Py_None);
  }
}

extern void add_user(User u);
extern void sort_users();
extern User *lookup_user(char *name);
extern User *get_user(int index);
extern int num_users();