File: cstruct.h

package info (click to toggle)
psyco-doc 1.6-1
  • links: PTS
  • area: contrib
  • in suites: lenny
  • size: 1,832 kB
  • ctags: 3,236
  • sloc: ansic: 23,895; python: 5,646; perl: 1,309; makefile: 153
file content (42 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download | duplicates (6)
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
 /***************************************************************/
/***  Turning general-purpose C structures into Python objects ***/
 /***************************************************************/

#ifndef _CSTRUCT_H
#define _CSTRUCT_H


#include "psyco.h"


#define PyCStruct_HEAD                          \
  PyObject_HEAD                                 \
  destructor cs_destructor;                     \
  PyObject* cs_key;

typedef struct {  /* internal */
  PyCStruct_HEAD
} cstruct_header_t;


EXTERNVAR PyTypeObject PyCStruct_Type;

#define PyCStruct_Check(op)	PyObject_TypeCheck(op, &PyCStruct_Type)

EXTERNFN PyObject* PyCStruct_New(size_t size, destructor d);
#define PyCStruct_NEW(TYPE, d)                          \
  ((TYPE*) PyCStruct_New(sizeof(TYPE), (destructor)(d)))

/* lookup in the given dict for the item whose key is a CStruct with
   the given key as cs_key */
PSY_INLINE PyObject* PyCStruct_DictGet(PyObject* dict, PyObject* key)
{
  cstruct_header_t sample;
  sample.ob_type = &PyCStruct_Type;
  sample.ob_refcnt = 1;
  sample.cs_key = key;
  return PyDict_GetItem(dict, (PyObject*) &sample);
}


#endif /* _CSTRUCT_H */