[C++-sig] [Py++] Export #define directives to ctypes

Nikolaus Rath Nikolaus at rath.org
Sun Dec 27 23:54:16 CET 2009


Hello,

Is there a way to export preprocessor definitions (#define ...) with the
ctypes code generator?

At the moment I'm using this rather nasty hack:

/* Header file */
// FUSE_SET_ATTR_* is defined with #define in fuse_lowlevel.h
#include <fuse_lowlevel.h>
const int D_FUSE_SET_ATTR_MODE = FUSE_SET_ATTR_MODE; 
const int D_FUSE_SET_ATTR_UID = FUSE_SET_ATTR_UID;
// ...

# Code generator
mb.write_module(os.path.join(code_path, 'ctypes_api.py'))
fh = open(os.path.join(code_path, 'ctypes_api.py'), 'a')
fh.write('\n')
for var in mb.global_ns.decls(lambda f: f.name.startswith('D_')):
    fh.write('{0} = {1}\n'.format(var.name[2:], var._value))
fh.close()


But it'd be nice if there was a better solution (so that I don't have to
define a new variable for every #define that I want to export).


Best,

   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C



More information about the Cplusplus-sig mailing list