[DB-SIG] Re: [Psycopg] mxDateTime still eludes me....

Federico Di Gregorio fog@mixadlive.com
Fri, 20 Apr 2001 10:23:26 +0200


Scavenging the mail folder uncovered M.-A. Lemburg's letter:
> > yes, this is a know problem of psycopg, it can't find mxDateTime outside
> > the top level python library path. will be resolved in next release, i
> > hope...
> 
> Note that if you use the import API mxDateTime_ImportModuleAndAPI() 
> from mxDateTime.h it will find the package all by itself -- you should 
> never import the C extension mxDateTime directly, please always use 
> import mx.DateTime.

currently i am still using 1.3.0 (from python i do an import DateTime,
without the 'mx') and yes, we tried to call mxDateTime_ImportModuleAndAPI()
but, apparently, this does not work when the psycopg module is loaded
inside Zope. so we use a slightly modified version of 
mxDateTime_ImportModuleAndAPI() (attached.) i will be more than happy to
use the Right (TM) function, if i understand why it does not work inside
Zope...

the problem is MXDATETIME_LOCATION, calculated (the wrong way, else
we should net have had any problems) at configure time.

    msys = PyImport_ImportModule("sys");
    if (!msys) {
        return;
    }
    v = PyObject_GetAttrString(msys, "path");
    datetime_path = PyString_FromString(MXDATETIME_LOCATION);
    if (!datetime_path) {
        return;
    }
    if (PyList_Insert(v, 0, datetime_path) == -1) {
        Py_DECREF(datetime_path);
        return;
    }
    mod = PyImport_ImportModule(MXDATETIME_API_MODULE);
    if (mod == NULL) {
        return ;
    }
    api_obj = PyObject_GetAttrString(mod, MXDATETIME_MODULE"API");
    if (api_obj == NULL) {
        Py_DECREF(mod);
        return;
    }
    Py_DECREF(mod);
    Dprintf("initpsycopg(): API object found\n");
    api = PyCObject_AsVoidPtr(api_obj);
    if (api == NULL) {
        Py_DECREF(mod);
        Py_DECREF(v);
        return;
    }
    memcpy(&mxDateTime, api, sizeof(mxDateTime));
    mxDateTimeP = &mxDateTime;

-- 
Federico Di Gregorio
MIXAD LIVE Chief of Research & Technology              fog@mixadlive.com
Debian GNU/Linux Developer & Italian Press Contact        fog@debian.org
                           Don't dream it. Be it. -- Dr. Frank'n'further