Skip to content

Commit

Permalink
Building on MinGW
Browse files Browse the repository at this point in the history
mkleehammer/pyodbc/mkleehammer#1168
  • Loading branch information
RoDuth committed Dec 16, 2024
1 parent 12fe42e commit 86feb6d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
12 changes: 10 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import sys, os, shlex, re
import sys, os, re, shlex, sysconfig
from os.path import exists, join, isdir, relpath, expanduser
from pathlib import Path
from inspect import cleandoc
Expand Down Expand Up @@ -83,7 +83,15 @@ def get_compiler_settings():
'define_macros': [('PYODBC_VERSION', VERSION)]
}

if os.name == 'nt':
if 'mingw' in sysconfig.get_platform():
# Windows mingw (note that os.name == 'nt' is True)
settings['extra_compile_args'].extend([
'-Wno-write-strings',
'-Wno-deprecated-declarations',
])
settings['libraries'].append('odbc32')

elif os.name == 'nt':
settings['extra_compile_args'].extend([
'/Wall',
'/wd4514', # unreference inline function removed
Expand Down
4 changes: 2 additions & 2 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ static bool ApplyPreconnAttrs(HDBC hdbc, SQLINTEGER ikey, PyObject *value, char
{
if (_PyLong_Sign(value) >= 0)
{
ivalue = (SQLPOINTER)PyLong_AsUnsignedLong(value);
ivalue = (SQLPOINTER)(uintptr_t)PyLong_AsUnsignedLong(value);
vallen = SQL_IS_UINTEGER;
} else
{
ivalue = (SQLPOINTER)PyLong_AsLong(value);
ivalue = (SQLPOINTER)(uintptr_t)PyLong_AsLong(value);
vallen = SQL_IS_INTEGER;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/pyodbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ typedef long long INT64;
typedef unsigned long long UINT64;
#define _strcmpi strcasecmp
#define _strdup strdup
#ifdef __MINGW32__
#include <windef.h>
#include <malloc.h>
#include <windows.h>
#else
inline int max(int lhs, int rhs) { return (rhs > lhs) ? rhs : lhs; }
#endif
#endif

#ifdef __SUN__
#include <alloca.h>
Expand Down Expand Up @@ -109,6 +115,11 @@ inline void _strlwr(char* name)
#define CDECL
#endif

#ifdef __MINGW32__
#define min(X,Y) ((X) < (Y) ? (X) : (Y))
#define max(X,Y) ((X) > (Y) ? (X) : (Y))
#endif

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

Expand Down
3 changes: 2 additions & 1 deletion src/pyodbcmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ static bool AllocateEnv()
}

SQLPOINTER defaultVersion = (SQLPOINTER)SQL_OV_ODBC3;
#ifdef SQL_OV_ODBC3_80
PyObject* odbcversion = PyObject_GetAttrString(pModule, "odbcversion");
if (PyObject_TypeCheck(odbcversion, &PyUnicode_Type)) {
if (PyUnicode_CompareWithASCIIString(odbcversion, "3.8") == 0)
Expand All @@ -311,7 +312,7 @@ static bool AllocateEnv()
}
}
Py_DECREF(odbcversion);

#endif
if (!SQL_SUCCEEDED(SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, defaultVersion, sizeof(int))))
{
PyErr_SetString(PyExc_RuntimeError, "Unable to set SQL_ATTR_ODBC_VERSION attribute.");
Expand Down

0 comments on commit 86feb6d

Please sign in to comment.