Re: plpython function problem workaround

From: Marco Colombo <pgsql(at)esiway(dot)net>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: plpython function problem workaround
Date: 2005-03-14 19:14:42
Message-ID: Pine.LNX.4.61.0503142008510.20758@Megathlon.ESI
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 14 Mar 2005, Michael Fuhr wrote:

> Would we? My understanding is that code passed to PyRun_String()
> and friends must be free of line-ending CRs on all platforms, and
> that the code that reads a "normal" Python script takes care of
> that (i.e., normalizes line endings to be LF only). Can anybody
> confirm or deny?

I'm not sure of that. I suspect you'll need to pass CRs on windows.

If anyone manages to compile the following code on Windows...

#include "Python.h"

void
run_program(const char *program)
{
PyObject *ret, *globals, *locals;

printf("> running:\n%s\n", program);
globals = PyDict_New();
locals = PyDict_New();
ret = PyRun_String(program, Py_file_input, globals, locals);
if (ret) {
Py_DECREF(ret);
printf("\n");
} else {
PyErr_Print();
}
Py_DECREF(locals);
Py_DECREF(globals);
printf("> end\n\n");

}

int
main(int argc, char *argv[])
{
const char *program1 = "print 1\nprint 2\n";
const char *program2 = "print 1\r\nprint 2\r\n";

Py_Initialize();
printf("> Initialized.\n");
printf("> Python %s\n", Py_GetVersion());
run_program(program1);
run_program(program2);
Py_Finalize();
printf("> Finalized.\n");
}

On my Fedora Core 2, I need to complile it with the following command:

gcc -I/usr/include/python2.3 -L/usr/lib/python2.3/config py-test.c -o py-test\
-lpython2.3 -ldl -lm -lpthread -lutil

This is my first attempt to embed python, so I may be missing something...

On Linux, you get:

$ ./py-test 2>&1 | cat -v
> Initialized.
> Python 2.3.3 (#1, May 7 2004, 10:31:40)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)]
> running:
print 1
print 2

1
2

> end

> running:
print 1^M
print 2^M

File "<string>", line 1
print 1^M
^
SyntaxError: invalid syntax
> end

> Finalized.

I bet on windows the first program fails and the second is ok.

.TM.
--
____/ ____/ /
/ / / Marco Colombo
___/ ___ / / Technical Manager
/ / / ESI s.r.l.
_____/ _____/ _/ Colombo(at)ESI(dot)it

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2005-03-14 20:15:58 Re: [GENERAL] A way to let Vacuum warn if FSM settings are
Previous Message Tom Lane 2005-03-14 19:14:19 Re: prelimiary performance comparison pgsql vs mysql