Extension modules and common routines in Python/C API

T

ty ty

Hi, folks!

I'm writing wrapper for C library. This library consist of several parts. And i want split my extension package into different extension modules. I think, this is the right way ;-) But, there are some common parts that exist in extension package, get_library_version, Error, and so on. I've decided to create additional module, named core, where these routines and variables are defined. And when get_library_version, for example, is used by programmer, Error, in opposite, is used by routines in another modules. As i mentioned in ( above mail), i use create_error for adding new exception class with neccessary fields. Now i call create_error in initcore function, which initialize core module. But, if i don't import package.core, and only import package.module, when package.module.function fails, python's runtime throws error:
SystemError: error return without exception set
because, Error is not properly initialize in that point.

And, if i add:

if(!Error)
create_error();
in init functions of all my modules, create_error runs several times (for each imported module). I think, i get a different Error every time. I can't check this because of above issue.

So, my questions is: how can i organize this pattern? Should i add import package.core in __init__.py in package dir? Or should i create subclass exception of Error in every module?
What is the right and pythonic way for doing that? :)

Thanks!

(crosspost from http://stackoverflow.com/questions/3119026/extension-modules-and-common-routines-in-python-c-api )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top