On Fri, 13 Mar 2009, Bill Janssen wrote:
Michael McCandless <luc...@mikemccandless.com> wrote:
I'm playing with 2.4.1 RC3 (on OS X 10.5.6) and found a few issues:
* If I fail to call lucene.initVM, I get a rather unfriendly Bus
Error. Is it possible (desirable?) to detect this and throw a
friendly exception instead?
I was thinking about this some more, and have an idea. How about only
having the dictionary of the module init'ed by calling initVM? That is,
it would be practically speaking impossible to call any other Java
method until the VM has been initialized and the thread attached. The
overhead would go into "import", where it might be acceptable. So
instead of getting the bus error, you'd get an AttributeError.
Or, keep the dictionary, but map the values associated with each
variable in the module to an error function which raises
JavaNotInitialized, and do the real mapping after the initialization
step.
The following needs to work:
>>> from lucene import Document, initVM, CLASSPATH
>>> initVM(CLASSPATH)
>>> Document()
So, messing with the module dictionary is not really an option.
But messing with all the C types mapping to Java classes could be done.
Again, as with attachCurrentThread(), we don't want to be in a situation
where the init check is run for every call all the time. So that C type
messing needs to be implemented in a way that catches the error before
initVM() is called and just runs without any checks after it got called.
Maybe initializing the tp_getattro slot of the C type struct with a checking
version before initVM() is called and replacing it with the real version
during initVM() is the way to go. Would you like to contribute a patch ?
Hint: in macros.h, add a parameter to DECLARE_TYPE to take this checking
tp_getattro version, have JCC generate code with that new parameter so that
all C type mapping to Java classes are initialized with that checking
tp_getattro, and then, during initVM(), as all of these types are visited,
replace the tp_getattro with the python default, PyObject_GenericGetAttr().
You might also have to play the same trick with the tp_new C type struct
slot to catch the constructor calls.
Andi..