Skip to content

Commit f5566d3

Browse files
Fix: Build failure on IBM z15 (s390x) (Issue #1005) (#1009)
Signed-off-by: Balram Choudhary <bchoudhary@rocketsoftware.com>
1 parent eec53c1 commit f5566d3

1 file changed

Lines changed: 27 additions & 31 deletions

File tree

ibm_db.c

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,13 +2380,16 @@ static SQLWCHAR *getUnicodeDataAsSQLWCHAR(PyObject *pyobj, int *isNewBuffer)
23802380
if (maxuniValue <= 65536)
23812381
{
23822382
*isNewBuffer = 0;
2383-
PyObject *result = (SQLWCHAR *)PyUnicode_AsWideCharString(pyobj, &maxuniValue);
2383+
SQLWCHAR *result = (SQLWCHAR *)PyUnicode_AsWideCharString(pyobj, &maxuniValue);
2384+
if (result == NULL) {
2385+
LogMsg(ERROR, "PyUnicode_AsWideCharString() failed");
2386+
return NULL;
2387+
}
23842388
snprintf(messageStr, sizeof(messageStr), " result obtained: %p", (void *)result);
23852389
LogMsg(DEBUG, "UCS2 case:");
23862390
LogMsg(INFO, "exit getUnicodeDataAsSQLWCHAR()");
2387-
return (SQLWCHAR *)PyUnicode_AsWideCharString(pyobj, &maxuniValue);
2391+
return result;
23882392
}
2389-
23902393
*isNewBuffer = 1;
23912394
pNewBuffer = (SQLWCHAR *)ALLOC_N(SQLWCHAR, nCharLen + 1);
23922395
snprintf(messageStr, sizeof(messageStr), "Allocated new buffer: pNewBuffer=%p, size=%d", (void *)pNewBuffer, nCharLen + 1);
@@ -2608,6 +2611,8 @@ static void _python_ibm_db_clear_conn_err_cache(void)
26082611

26092612
static PyObject *ibm_db_get_sqlcode(PyObject *self, PyObject *args)
26102613
{
2614+
LogMsg(INFO, "entry get_sqlcode()");
2615+
LogUTF8Msg(args);
26112616
conn_handle *conn_res = NULL;
26122617
PyObject *py_conn_res = NULL;
26132618
stmt_handle *stmt_res = NULL;
@@ -2616,7 +2621,6 @@ static PyObject *ibm_db_get_sqlcode(PyObject *self, PyObject *args)
26162621
char *return_str = NULL; /* This variable is used by
26172622
* _python_ibm_db_check_sql_errors to return err
26182623
* strings */
2619-
LogMsg(INFO, "entry get_sqlcode()");
26202624
if (!PyArg_ParseTuple(args, "|O", &py_conn_res) | (!PyArg_ParseTuple(args, "|O", &py_stmt_res)))
26212625
{
26222626
LogMsg(ERROR, "Failed to parse arguments");
@@ -2653,67 +2657,65 @@ static PyObject *ibm_db_get_sqlcode(PyObject *self, PyObject *args)
26532657
LogMsg(DEBUG, messageStr);
26542658
}
26552659

2656-
return_str = (SQLINTEGER *)PyMem_New(SQLINTEGER, 1);
2657-
snprintf(messageStr, sizeof(messageStr), "Allocated return_str: %p, size: %d", return_str, DB2_MAX_ERR_MSG_LEN);
2658-
LogMsg(DEBUG, messageStr);
2659-
2660+
return_str = PyMem_New(char, DB2_MAX_ERR_MSG_LEN);
26602661
if (return_str == NULL)
26612662
{
26622663
PyErr_NoMemory();
26632664
return NULL;
26642665
}
2665-
memset(return_str, 0, sizeof(SQLINTEGER));
2666-
LogMsg(DEBUG, "Initialized return_str with zeros");
2666+
memset(return_str, 0, DB2_MAX_ERR_MSG_LEN);
2667+
snprintf(messageStr, sizeof(messageStr), "Allocated return_str: %p, size: %d", (void *)return_str, DB2_MAX_ERR_MSG_LEN);
2668+
LogMsg(DEBUG, messageStr);
26672669
if (SQL_HANDLE_DBC)
26682670
{
26692671
_python_ibm_db_check_sql_errors(conn_res->hdbc, SQL_HANDLE_DBC, -1, 0,
26702672
return_str, DB2_ERR,
26712673
conn_res->error_recno_tracker);
2672-
snprintf(messageStr, sizeof(messageStr), "SQL errors checked. return_str: %s", return_str);
2674+
snprintf(messageStr, sizeof(messageStr), "SQL errors checked for DBC. return_str: %s", return_str);
26732675
LogMsg(DEBUG, messageStr);
26742676
}
26752677
if (SQL_HANDLE_STMT)
26762678
{
26772679
_python_ibm_db_check_sql_errors(stmt_res->hstmt, SQL_HANDLE_STMT, -1, 0,
26782680
return_str, DB2_ERR,
26792681
stmt_res->error_recno_tracker);
2680-
snprintf(messageStr, sizeof(messageStr), "SQL errors checked. return_str: %s", return_str);
2682+
snprintf(messageStr, sizeof(messageStr), "SQL errors checked for STMT. return_str: %s", return_str);
26812683
LogMsg(DEBUG, messageStr);
26822684
}
26832685
if (conn_res->error_recno_tracker - conn_res->errormsg_recno_tracker >= 1)
26842686
{
2685-
LogMsg(DEBUG, "Updating errormsg_recno_tracker");
2687+
LogMsg(DEBUG, "Updating conn_res->errormsg_recno_tracker");
26862688
conn_res->errormsg_recno_tracker = conn_res->error_recno_tracker;
26872689
}
26882690
conn_res->error_recno_tracker++;
2689-
snprintf(messageStr, sizeof(messageStr), "Updated error_recno_tracker: %d, errormsg_recno_tracker: %d", conn_res->error_recno_tracker, stmt_res->errormsg_recno_tracker);
2691+
snprintf(messageStr, sizeof(messageStr), "Updated conn error_recno_tracker: %d, errormsg_recno_tracker: %d", conn_res->error_recno_tracker, stmt_res->errormsg_recno_tracker);
26902692
LogMsg(DEBUG, messageStr);
26912693
if (stmt_res->error_recno_tracker - stmt_res->errormsg_recno_tracker >= 1)
26922694
{
2693-
LogMsg(DEBUG, "Updating errormsg_recno_tracker");
2695+
LogMsg(DEBUG, "Updating stmt_res->errormsg_recno_tracker");
26942696
stmt_res->errormsg_recno_tracker = stmt_res->error_recno_tracker;
26952697
}
26962698
stmt_res->error_recno_tracker++;
2697-
snprintf(messageStr, sizeof(messageStr), "Updated error_recno_tracker: %d, errormsg_recno_tracker: %d", stmt_res->error_recno_tracker, stmt_res->errormsg_recno_tracker);
2699+
snprintf(messageStr, sizeof(messageStr), "Updated stmt error_recno_tracker: %d, errormsg_recno_tracker: %d", stmt_res->error_recno_tracker, stmt_res->errormsg_recno_tracker);
26982700
LogMsg(DEBUG, messageStr);
26992701
if (return_str != NULL)
27002702
{
27012703
retVal = StringOBJ_FromASCII(return_str);
27022704
PyMem_Del(return_str);
27032705
return_str = NULL;
27042706
}
2705-
snprintf(messageStr, sizeof(messageStr), "Created return value: %p", retVal);
2707+
snprintf(messageStr, sizeof(messageStr), "Created return value: %p", (void *)retVal);
27062708
LogMsg(DEBUG, messageStr);
27072709
LogMsg(INFO, "exit get_sqlcode()");
27082710
return retVal;
27092711
}
27102712
else
27112713
{
27122714
PyObject *defaultErrorCode = StringOBJ_FromASCII(IBM_DB_G(__python_err_code));
2713-
snprintf(messageStr, sizeof(messageStr), "No Statement object provided. Returning default error sqlcode: %s", PyUnicode_AsUTF8(defaultErrorCode));
2715+
snprintf(messageStr, sizeof(messageStr), "Connection or Statement object is not provided. Returning default error sqlcode: %s", PyUnicode_AsUTF8(defaultErrorCode));
27142716
LogMsg(DEBUG, messageStr);
2715-
LogMsg(INFO, "exit conn_error()");
2716-
return StringOBJ_FromASCII(IBM_DB_G(__python_err_code));
2717+
LogMsg(INFO, "exit get_sqlcode()");
2718+
return defaultErrorCode;
27172719
}
27182720
}
27192721

@@ -8151,22 +8153,16 @@ static int _python_ibm_db_bind_data(stmt_handle *stmt_res, param_node *curr, PyO
81518153
}
81528154
}
81538155

8154-
if (isNewBuffer == 0)
8155-
{
8156-
dest_uvalue = (char *)&curr->uvalue[0] + (curr->param_size * i);
8157-
dest_uvalue = memcpy(dest_uvalue, tmp_uvalue, (param_length + sizeof(SQLWCHAR)));
8158-
param_size = curr->param_size;
8159-
}
8160-
else if (param_length <= curr->param_size)
8156+
if (isNewBuffer == 0 || param_length <= curr->param_size)
81618157
{
8162-
dest_uvalue = (char *)&curr->uvalue[0] + (curr->param_size * i);
8163-
dest_uvalue = memcpy(dest_uvalue, tmp_uvalue, (param_length + sizeof(SQLWCHAR)));
8158+
dest_uvalue = &curr->uvalue[(curr->param_size / sizeof(SQLWCHAR)) * i];
8159+
memcpy(dest_uvalue, tmp_uvalue, param_length);
81648160
param_size = curr->param_size;
81658161
}
81668162
else if (curr->data_type == SQL_TYPE_TIMESTAMP)
81678163
{
8168-
dest_uvalue = (char *)&curr->uvalue[0] + (param_length * i);
8169-
dest_uvalue = memcpy(dest_uvalue, tmp_uvalue, param_length);
8164+
dest_uvalue = &curr->uvalue[(param_length / sizeof(SQLWCHAR)) * i];
8165+
memcpy(dest_uvalue, tmp_uvalue, param_length);
81708166
param_size = param_length;
81718167
}
81728168
PyMem_Del(tmp_uvalue);

0 commit comments

Comments
 (0)