On Thu, Mar 11, 2010 at 6:14 PM, Ondrej Certik <[email protected]> wrote:
> Hi,
>
> I am attaching the two files that I want Cython to generate.
>
> It seem to do the job. So far, I just did them by hand and I will test
> my code more in the coming days. If all is fine, I will try to modify
> Cython to do that automatically. The static->extern is easy, this
Btw, and here is my Python() class so far:
class Python {
public:
Python();
Python(int argc, char* argv[]);
~Python();
void eval(const char *text);
void insert_object(const char *name, PyObject *o);
PyObject *get_object(const char *name);
};
and implementation:
#include <stdexcept>
#include "python_api.h"
static int python_count=0;
Python::Python()
{
Python::Python(-1, NULL);
}
Python::Python(int argc, char* argv[])
{
python_count++;
if (python_count == 1) {
// This is a hack:
putenv((char *)"PYTHONPATH=../..");
Py_Initialize();
if (argc >= 0)
PySys_SetArgv(argc, argv);
if (import__hermes_common())
throw std::runtime_error("hermes_common failed to import.");
}
}
Python::~Python()
{
python_count--;
if (python_count == 0) {
Py_Finalize();
}
}
void Python::eval(const char *text)
{
cmd(text);
}
void Python::insert_object(const char *name, PyObject *o)
{
::insert_object(name, o);
}
PyObject *Python::get_object(const char *name)
{
::get_object(name);
}
It's still a work in progress. I'll rename insert_object to push(),
get_object to pull(), eval() to exec() and also implement local
namespace for each instance.
Ondrej
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev