Skip to content

Segmentation fault when using mysql on Windows #18

Description

@pavonia

I'm trying to use mysql-0.1.1.8 on a Windows system. I managed to circumvent #3 by passing the flags manually via --extra-include/lib-dirs to cabal. However, there are more problems because pthread is not supported on Windows systems. Using pthreads-win32 (http://www.sourceware.org/pthreads-win32/) still leads to errors because several definitions from signal.h are not found in my MinGW installation.

As all the pthread functions only seem to be used to avoid RTS interruptions, I removed mysql_signals.h and mysql_signals.c from the project and changed the foreign import calls in Database.MySQL.Base.C back to their original names, e.g.

foreign import ccall unsafe "mysql_signals.h _hs_mysql_real_connect"

becomes

foreign import ccall unsafe mysql_real_connect

etc.

After doing these changes the package builds fine, the following test program builds fine and there aren't any linker errors anymore.

module Main where

import Control.Exception
import Database.MySQL.Base

main :: IO ()
main = do
    putStrLn $ "Client info: " ++ clientInfo
    handle (\e -> putStrLn $ "ERROR: " ++ show (e :: MySQLError)) $ do
        conn <- connect $ ConnectInfo {
                connectHost = "localhost",
                connectUser = "root",
                connectPassword = "pass",
                connectDatabase = "",
                connectPort = 0,
                connectOptions = [],
                connectPath = "",
                connectSSL = Nothing
            }
        info <- serverInfo conn
        putStrLn $ "Server info: " ++ info
        close conn

The only problem is the program produces a segmentation fault when run:

Client info: 5.0.51a
Segmentation fault/access violation in generated code

Note that the call to clientInfo works fine, but the attempt to connect to the database segfaults. I thought it might be an incompatible MySQL version of something like that, so I wrote a small C program doing basically the same function calls, and that works fine:

#include <stdio.h>
#include <stdlib.h>
#include <winsock.h>
#include <mysql.h>

int main(int argc, char **argv)
{  
    MYSQL *conn = mysql_init(NULL);

    if (conn == NULL) {
        printf("%s\n", mysql_error(conn));
        exit(1);
    }

    printf("Client info: %s\n", mysql_get_client_info());

    if (mysql_real_connect(conn, "localhost", "root", "pass", NULL, 0, NULL, 0) == NULL) {
        printf("%s\n", mysql_error(conn));
        mysql_close(conn);
        exit(1);
    }

    printf("Server info: %s\n", mysql_get_server_info(conn));

    mysql_close(conn);
    exit(0);
}

outputs

Client info: 5.0.51a
Server info: 5.1.32-community

Performing SQL requests and fetching the result also works fine in C. So the problem clearly is related to the Haskell package, but I have no idea where to start debugging this. May it be the changes I did to the package causing this problem? I would try using the functions from Database.MySQL.Base.C directly but I'm not familiar with the FFI, so I don't know how to use them safely.

Any ideas on that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions