Integrating a library and using interrogate

Hi, I’m integrating berkelium (see herefor info)

I’ve just got everything compiling, mostly by copying the build targetadds used by awesomium, and every use of the word awesomium in the build system then cloning it with berkelium. (which worked surprisingly well, though apparently means I’ve used the deprecated PandaModules system, but I don’t know how I should be doing it otherwise)

Still haven’t wrapped everything up properly yet, just trying to ensure I can get them talking at all.

My first question is a silly one, but I can’t figure it out:

Where does my python function end up, where should I import from?

I’ve got a single published c++ function,

inside berkelium_init.h:

class berkelium_p3d {
PUBLISHED:
	void berkelium_init();
};

(the class/method naming will be improved once I’ve got it working)

and I just want to run it, which will tell me if python->panda->berkelium is working,

The interrogate command used during the compile is

built/bin/interrogate -srcdir panda/src/berkelium -Ipanda/src/berkelium -Dvolatile -Dmutable -DCPPPARSER -D__STDC__=1 -D__cplusplus -D__inline -longlong __int64 -D_X86_ -DWIN32_VC -D_WIN32 -D_MSC_VER=1500 -D"_declspec(param)=" -D_near -D_far -D__near -D__far -D__stdcall -oc built/tmp/libberkelium_igate.cxx -od built/pandac/input/libberkelium.in -fnames -string -refcount -assert -python-native -Sbuilt/include/parser-inc -Ipanda/src/berkelium -Sthirdparty/win-python/include -Sthirdparty/win-libs-vc9/berkelium/include -Sbuilt/tmp -Sbuilt/include -DMAKEPANDA= -DBUILDING_PANDABERKELIUM -module p3berkelium -library libberkelium berkelium_init.h panda_window_delegate.h pandaberkelium_composite1.cxx

Could someone who knows these tools well tell me where I should be looking for the python produced (where I should be importing it from). My googling suggested it would be in pandac.berkelium (from “-module p3berkelium” with the p3 removed) but python tells me otherwise, maybe its just not working yet?

as an aside, interrogate seems to not like preprocessing instructions that compare 2 macros

e.g.

#if BERKELIUM_PLATFORM == PLATFORM_WINDOWS

where both were defined as 0 threw a parse error.
Whats annoying is that throwing
#ifndef BUILDING_PYTHONINTERFACES
around it didn’t avoid the problem so I had to hack in a fix to the problem. Such a solution might not always be available, so maybe this should be fixed?

In the PandaModules system, all C++ symbols end up in the same flat space, within PandaModules itself. This assumes that genPyCode has been run with the name of your new library as a parameter (genPyCode generates PandaModules.py, which is just a sequence of import statements for all of the known C++ modules).

Or, you could just import your compiled library directly: “import libp3berkelium”, and you should find your symbols there.

Hmm, I was pretty sure this did work correctly. Are you sure both of your macros were in fact defined?

David

To import your libp3berkelium through the new import system, don’t run the genPyCode step but instead add your library to the dictionary in panda3d.py (open the file, and it’s straight-forward). Then you’ll be able to import from “panda3d.berkelium”.

Thanks for the hints

It seems I’m not getting any python output yet then, I tried all 3 and got
ImportError: No module named libp3berkelium
or
ImportError: No module named berkelium
It also doesn’t appear in the help(‘panda3d’) list, much like awesomium doesn’t (though awesomium isnt compiled so I wouldnt expect it to appear). I can only assume things are only added if they have something to show.

Yeah, I’m pretty certain they were both defined to 0

#define PLATFORM_WINDOWS 0
#define PLATFORM_LINUX   1
#define PLATFORM_MAC     2
...
#if defined(__WIN32__) || defined(_WIN32)
...
#  define BERKELIUM_PLATFORM PLATFORM_WINDOWS
...
#endif
...
#if BERKELIUM_PLATFORM == PLATFORM_WINDOWS

I avoided the problem with:
#if BERKELIUM_PLATFORM == 0//PLATFORM_WINDOWS

PLATFORM_WINDOWS is never redefined, so I can’t see how it could be going wrong.

Did you compile built/tmp/libberkelium_igate.cxx and link it into a DLL? What happens if you directly import that DLL? (You might need to rename it to a .pyd extension temporarily to allow Python to import it directly.)

I’ll investigate the #if problem.

David

“import libp3berkelium” will only work if there’s a libp3berkelium.pyd on the PYTHONPATH (you can simply rename the .dll to .pyd). The panda3d.* import system or PandaModules also allow importing dlls without having to rename it to pyd.

Did you put it in the same directory, in the bin directory of the Panda3D installation (or the lib directory on non-Windows)?

For the record, I just tried to interrogate the following code:

#define TEST1 0
#define TEST2 0
#if TEST1 == TEST2
#error 1
#else
#error 2
#endif

and it aborts with error “1”. If I comment out #error 1, it parses without error.

David