BUG #2383: MessageBox Win32 API makes clients freeze - Mailing list pgsql-bugs

From Pegasus86
Subject BUG #2383: MessageBox Win32 API makes clients freeze
Date
Msg-id 200604081618.k38GIpdX049177@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #2383: MessageBox Win32 API makes clients freeze  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
The following bug has been logged online:

Bug reference:      2383
Logged by:          Pegasus86
Email address:      Pegasus86@katamail.com
PostgreSQL version: 8.1.3
Operating system:   Windows XP Professional
Description:        MessageBox Win32 API makes clients freeze
Details:

I am working on a PC with AMD64 X2 processor, but 32-bit XP Professional.

I have created a db which contains a function linked to a C function
contained in a dll. This function should show a message box to the users.
The problem is that every client freezes when I call this function through
SQL commands.
I have tried PgAdminIII, psql AND clients, written by me in Delphi,
accessing PostgreSQL via ODBC.

To reproduce the problem, use Dev-Cpp 5 beta for Windows (using GCC) and
create a dll project (choose any name), choosing C as the language for the
project.

Now, you will have 2 files: one .c file, and .h file. These are the
contents:


/****************************************************
C FILE: I have called it "dllmain.c"
****************************************************/
#include "dll.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>

DLLIMPORT void f1 (void)
{
     /*Remember to grant access to user 'Postgres' to the file you want to
open! (in this case, C:/Test.txt */
     FILE *fp = fopen("C:/Test.txt", "w");

     if (!fp){
              exit(1);
     }

     fprintf(fp, "Hello, World of C!!!");
     fclose(fp);
}


DLLIMPORT void f2 (void)
{
    MessageBox (0, "Hello World from DLL!\n", "Hi", MB_ICONINFORMATION);
}


/*DllMain generated by Dev-Cpp*/
BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being
called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
    switch (reason)
    {
      case DLL_PROCESS_ATTACH:
        break;

      case DLL_PROCESS_DETACH:
        break;

      case DLL_THREAD_ATTACH:
        break;

      case DLL_THREAD_DETACH:
        break;
    }

    /* Returns TRUE on success, FALSE on failure */
    return TRUE;
}



/************************************************
HEADER FILE: I have called it "dll.h"
************************************************/
#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


DLLIMPORT void f1 (void);
DLLIMPORT void f2 (void);


#endif /* _DLL_H_ */



Now, simply build the DLL, and create two "C" functions in your database,
called f1 and f2, linking them to the corresponding function in the DLL.

Now, create the file "c:/Test.txt" (you can leave it empty) and run (from
any client):

"SELECT <schema-name>.f1()"  --> it works!!! The file is written!

Now, run

"SELECT <schema-name>.f2()"  ---> frozen!!!


And, last but not least, even wxPython, called trough "plpythonu" freezes
when I try to use its MessageBox() function!!!

Thanks
P.86

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: ORDER BY bug in 8.1, WinXP
Next
From: "Alaa ElGohary"
Date:
Subject: BUG #2384: Can not install PostgreSQL 7.2.7 on FreeBSD6.0