Re: plpython function problem workaround - Mailing list pgsql-general

From Michael Fuhr
Subject Re: plpython function problem workaround
Date
Msg-id 20050315175645.GA66610@winnie.fuhr.org
Whole thread Raw
In response to Re: plpython function problem workaround  (Marco Colombo <pgsql@esiway.net>)
List pgsql-general
On Tue, Mar 15, 2005 at 06:03:01PM +0100, Marco Colombo wrote:
> On Tue, 15 Mar 2005, Michael Fuhr wrote:
> >I'll postpone commenting on the rest until we find out how the
> >example programs run on Windows.  If nobody follows up here then
> >maybe I'll wander over to comp.lang.python.
>
> Yeah, there's no point in discussing until we have some real world
> data. I can't compile on windows, so I'll have to wait someone else
> to do that. I'm basing my opinions on Python documentation only.

I've been looking through the Python source code (2.4.1c1) and I've
found several places that use only \n in embedded code.  One is
Modules/main.c, which says it's the "Python interpreter main program."
The Py_Main() function is processing command-line options and does
the following:

    if (c == 'c') {
            /* -c is the last option; following arguments
               that look like options are left for the
               command to interpret. */
            command = malloc(strlen(_PyOS_optarg) + 2);
            if (command == NULL)
                    Py_FatalError(
                       "not enough memory to copy -c argument");
            strcpy(command, _PyOS_optarg);
            strcat(command, "\n");
            break;
    }

Later, without further changes to the command variable, it does this:

    if (command) {
        sts = PyRun_SimpleStringFlags(command, &cf) != 0;
        free(command);

Modules/cPickle.c has additional examples:

    if (!( r=PyRun_String(
                   "def __init__(self, *args): self.args=args\n\n"
                   "def __str__(self):\n"
                   "  return self.args and ('%s' % self.args[0]) or '(what)'\n",
                   Py_file_input,
                   module_dict, t)  ))  return -1;

and

    if (!( r=PyRun_String(
                   "def __init__(self, *args): self.args=args\n\n"
                   "def __str__(self):\n"
                   "  a=self.args\n"
                   "  a=a and type(a[0]) or '(what)'\n"
                   "  return 'Cannot pickle %s objects' % a\n"
                   , Py_file_input,
                   module_dict, t)  ))  return -1;

The code in Demo/embed/demo.c uses only \n to terminate its lines:

    PyRun_SimpleString("import sys\n");
    PyRun_SimpleString("print sys.builtin_module_names\n");
    PyRun_SimpleString("print sys.modules.keys()\n");
    PyRun_SimpleString("print sys.executable\n");
    PyRun_SimpleString("print sys.argv\n");

If these examples are intended to run on Windows, then presumably
using \n works on that platform.  That doesn't necessarily preclude
\r\n from working as well, but apparently a platform-specific
sequence isn't required.  I'd still be interested in having somebody
run the test programs we've both posted to find out for sure.

Is anybody who's following this thread running a PostgreSQL server
with PL/Python on Windows?  We could use a test platform to answer
some questions, since the PostgreSQL aspect of this discussion is
about problems with PL/Python.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: Massive performance differences
Next
From: Ragnar Hafstað
Date:
Subject: Re: pg/plsql question