SWIG for HDF5 - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

SWIG for HDF5

Description:

Takes C declarations and turns them into the glue needed to access them from ... C, C , Objective-C. Higher-level languages. Python, Perl, Tcl, C#, Java, ... – PowerPoint PPT presentation

Number of Views:126
Avg rating:3.0/5.0
Slides: 17
Provided by: peter198
Category:
Tags: swig | hdf5 | objectivec

less

Transcript and Presenter's Notes

Title: SWIG for HDF5


1
SWIG for HDF5
  • Choonghwan Lee
  • The HDF Group
  • August 6, 2008

2
Motivation
  • Python users want to write an application using
    HDF5 library

3
SWIG(Simplified Wrapper and Interface Generator)
4
What is SWIG?
  • Takes C declarations and turns them into the glue
    needed to access them from higher-level
    languages.
  • Lower-level libraries
  • C, C, Objective-C
  • Higher-level languages
  • Python, Perl, Tcl, C, Java,
  • We can manually do this, but it is too tedious
  • As lex and yacc make our lives easier

5
SWIG is not
  • Library application users dont need SWIG
  • Interpreter add-on
  • Generated wrapper may be still low-level
  • PyHDF

6
What does SWIG rely on?
  • Higher-level languages can call C function from
    shared object and dynamically linked library
  • Python extension module
  • C - P/Invoke
  • Java JNI
  • Reading and writing variables can be wrapped by
    getter and setter functions

7
How to use SWIG
SWIG Interface
SWIG
C Wrapper
Python Wrapper
swig python hello.i
8
How to use SWIG
gcc shared \ hello_wrap.c \ impl.c \ -o
_hello.so
SWIG Interface
SWIG
C Wrapper
Python Wrapper
9
How to use SWIG
SWIG Interface
SWIG
python gtgtgt import hello gtgtgt print
hello.literal 1 gtgtgt print hello.constvar 1
C Wrapper
Python Wrapper
10
HDF5 Wrapper
11
Goal
  • Does not introduce new names
  • readonly variables or constants

hdf5.H5Dcreate(group, name,
hdf5.H5T_NATIVE_INT, dataspace,
hdf5.H5P_DEFAULT)
hdf5.H5Fopen(fname,
hdf5.H5F_ACC_RDWR, hdf5.H5P_DEFAULT)
12
Problem
  • Some macros are too complicated for SWIG

13
What can SWIG recognize?
  • Global variables
  • Preprocessor macros

/put in cvar/ extern int globalvar1_g const
int constvar 3
/ignored/ define funccall_globalvar \
(init(), globalvar1_g) /ignored/
define funccall_literal \
(check(), 2) define literal 4 /ignored/
define globalvar globalvar1_g
14
Augment SWIG Interface file
module hdf5 ... ... init H5open()
H5check() undef H5T_NATIVE_INT constant
hid_t H5T_NATIVE_INT H5T_NATIVE_INT_g undef
H5F_ACC_RDWR define H5F_ACC_RDWR 0x0001u
/ HDF5 headers / extern hid_t
H5T_NATIVE_INT_g define H5T_NATIVE_INT \
(H5OPEN H5T_NATIVE_INT_g) define H5F_ACC_RDWR
\ (H5CHECK 0x0001u)
15
Evaluation
  • Dont need to modify HDF5
  • Need to distribute SWIG Interface file
  • Hard-coded macros are not manageable
  • define H5F_ACC_RDWR 0x0001u

16
Discussion
  • Can we distribute SWIG Interface?
  • Can we modify HDF5 library?
  • Backward compatible?
Write a Comment
User Comments (0)
About PowerShow.com