Skip to content

Commit 74b6b59

Browse files
committed
BUG#33410592: Fix compiler warnings
1 parent 11d5d57 commit 74b6b59

File tree

4 files changed

+40
-31
lines changed

4 files changed

+40
-31
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v8.0.28
1414
- WL#14814: Remove support for TLS 1.0 and 1.1
1515
- WL#14813: Add support for Python 3.10
1616
- WL#14720: Support for Multi Factor authentication (pure Python)
17+
- BUG#33410592: Fix compiler warnings
1718
- BUG#27358941: Invalid types for params silently ignored in execute method
1819

1920
v8.0.27

src/mysql_capi.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2929
*/
3030

31-
#define PY_SSIZE_T_CLEAN 1
31+
#define PY_SSIZE_T_CLEAN
3232

3333
#include <stdio.h>
3434
#include <stdlib.h>
@@ -916,7 +916,6 @@ MySQL_change_user(MySQL *self, PyObject *args, PyObject *kwds)
916916
char *oci_config_file = NULL;
917917
unsigned int mfa_factor1= 1, mfa_factor2= 2, mfa_factor3= 3;
918918
int res;
919-
int option_set_res= 0;
920919
static char *kwlist[]= {"user", "password", "database",
921920
"password1", "password2", "password3",
922921
"oci_config_file", NULL};
@@ -1334,7 +1333,6 @@ MySQL_connect(MySQL *self, PyObject *args, PyObject *kwds)
13341333
ssl_ca= NULL;
13351334
}
13361335
mysql_ssl_set(&self->session, ssl_key, ssl_cert, ssl_ca, NULL, NULL);
1337-
char logout[100];
13381336
if (tls_versions != NULL)
13391337
{
13401338
mysql_options(&self->session,
@@ -2043,7 +2041,7 @@ MySQL_convert_to_mysql(MySQL *self, PyObject *args)
20432041
}
20442042
else if (PyUnicode_Check(new_value))
20452043
{
2046-
PyObject *quoted= PyBytes_FromFormat("'%s'", PyUnicode_AS_DATA(new_value));
2044+
PyObject *quoted= PyBytes_FromFormat("'%s'", (const char *)PyUnicode_1BYTE_DATA(new_value));
20472045
PyTuple_SET_ITEM(prepared, i, quoted);
20482046
}
20492047
else
@@ -2116,8 +2114,7 @@ MySQL_query(MySQL *self, PyObject *args, PyObject *kwds)
21162114
mybinds = calloc(size, sizeof(MYSQL_BIND));
21172115
bindings = calloc(size, sizeof(struct MySQL_binding));
21182116
const char **names = calloc(size, sizeof(char *));
2119-
PyObject *retval = NULL;
2120-
int i = 0, res = 0;
2117+
int i = 0;
21212118

21222119
for (i = 0; i < (int) size; i++) {
21232120
struct MySQL_binding *pbind = &bindings[i];
@@ -2149,7 +2146,9 @@ MySQL_query(MySQL *self, PyObject *args, PyObject *kwds)
21492146
mbind->buffer_type = MYSQL_TYPE_LONG;
21502147
#endif
21512148
mbind->is_null = (bool_ *) 0;
2152-
mbind->length = sizeof(mbind->buffer_type);
2149+
if (mbind->length) {
2150+
*mbind->length = sizeof(mbind->buffer_type);
2151+
}
21532152
continue;
21542153
}
21552154

@@ -2266,7 +2265,7 @@ MySQL_query(MySQL *self, PyObject *args, PyObject *kwds)
22662265
mbind->is_null = (bool_ *) 0;
22672266
} else if (PyUnicode_Check(pbind->str_value)) {
22682267
Py_ssize_t len;
2269-
mbind->buffer = PyUnicode_AsUTF8AndSize(pbind->str_value, &len);
2268+
mbind->buffer = (char *)PyUnicode_AsUTF8AndSize(pbind->str_value, &len);
22702269
mbind->buffer_length = (unsigned long) len;
22712270
mbind->length = &mbind->buffer_length;
22722271
mbind->is_null = (bool_ *) 0;
@@ -3502,7 +3501,7 @@ MySQLPrepStmt_execute(MySQLPrepStmt *self, PyObject *args)
35023501
else if (PyUnicode_Check(pbind->str_value))
35033502
{
35043503
Py_ssize_t len;
3505-
mbind->buffer= PyUnicode_AsUTF8AndSize(pbind->str_value, &len);
3504+
mbind->buffer= (char *)PyUnicode_AsUTF8AndSize(pbind->str_value, &len);
35063505
mbind->buffer_length= (unsigned long)len;
35073506
mbind->length= &mbind->buffer_length;
35083507
mbind->is_null= (bool_ *)0;

src/mysql_capi_conversion.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pytomy_timedelta(PyObject *obj)
195195

196196
if (micro_secs)
197197
{
198-
strncpy(fmt, "%02d:%02d:%02d.%06d", 19);
198+
strncpy(fmt, "%02d:%02d:%02d.%06d", 20);
199199
if (days < 0)
200200
{
201201
micro_secs= 1000000 - micro_secs;
@@ -204,7 +204,7 @@ pytomy_timedelta(PyObject *obj)
204204
}
205205
else
206206
{
207-
strncpy(fmt, "%02d:%02d:%02d", 14);
207+
strncpy(fmt, "%02d:%02d:%02d", 15);
208208
}
209209

210210
if (days < 0)
@@ -699,10 +699,9 @@ PyObject*
699699
pytomy_decimal(PyObject *obj)
700700
{
701701
PyObject *str= PyObject_Str(obj);
702-
PyObject *tmp= (const char *)PyUnicode_1BYTE_DATA(str);
703-
PyObject *ret= PyBytes_FromString(tmp);
704-
Py_DECREF(tmp);
705-
return ret;
702+
PyObject *bytes= PyUnicode_AsUTF8String(str);
703+
Py_DECREF(str);
704+
return bytes;
706705
}
707706

708707
/**

src/mysqlxpb/mysqlxpb.cc

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2929
*/
3030

31-
#define PY_SSIZE_T_CLEAN 1
31+
#define PY_SSIZE_T_CLEAN
3232

3333
#include "python_cast.h"
3434
#include "python.h"
@@ -165,9 +165,12 @@ static PyObject* ConvertPbToPyRequired(
165165
return PyLong_FromLong(static_cast<long>(message.GetReflection()->
166166
GetInt64(message, &field)));
167167
}
168+
169+
// Tag-delimited message. Deprecated.
170+
case google::protobuf::FieldDescriptor::TYPE_GROUP:
171+
break;
168172
}
169173

170-
assert(false);
171174
return NULL;
172175
}
173176

@@ -262,9 +265,12 @@ static PyObject* ConvertPbToPyRepeated(int index,
262265
return PyLong_FromLong(static_cast<long>(message.
263266
GetReflection()->GetRepeatedInt64(message, &field, index)));
264267
}
268+
269+
// Tag-delimited message. Deprecated.
270+
case google::protobuf::FieldDescriptor::TYPE_GROUP:
271+
break;
265272
}
266273

267-
assert(false);
268274
return NULL;
269275
};
270276

@@ -379,9 +385,12 @@ static void ConvertPyToPbRequired(
379385
python_cast<google::protobuf::int64>(obj));
380386
return;
381387
}
388+
389+
// Tag-delimited message. Deprecated.
390+
case google::protobuf::FieldDescriptor::TYPE_GROUP:
391+
break;
382392
}
383393

384-
assert(false);
385394
throw std::runtime_error("Unknown Protobuf type.");
386395
}
387396

@@ -391,14 +400,13 @@ static void AddPyListToMessageRepeatedField(
391400
google::protobuf::Message& message,
392401
const google::protobuf::FieldDescriptor& field,
393402
PyObject* list) {
394-
google::protobuf::RepeatedField<T>* mutable_field =
395-
message.GetReflection()->MutableRepeatedField<T>(&message, &field);
403+
google::protobuf::MutableRepeatedFieldRef<T> mutable_field =
404+
message.GetReflection()->GetMutableRepeatedFieldRef<T>(&message, &field);
396405
Py_ssize_t list_size = PyList_Size(list);
397406

398407
if (list_size > 0) {
399-
mutable_field->Reserve(list_size);
400408
for (Py_ssize_t idx = 0; idx < list_size; ++idx) {
401-
mutable_field->Add(python_cast<T>(PyList_GetItem(list, idx)));
409+
mutable_field.Add(python_cast<T>(PyList_GetItem(list, idx)));
402410
}
403411
}
404412
}
@@ -409,20 +417,19 @@ static void AddPyListToMessageRepeatedMessage(
409417
const google::protobuf::FieldDescriptor& field,
410418
google::protobuf::DynamicMessageFactory& factory,
411419
PyObject* list) {
412-
google::protobuf::RepeatedPtrField<google::protobuf::Message>* mutable_field =
420+
google::protobuf::MutableRepeatedFieldRef<google::protobuf::Message> mutable_field =
413421
message.GetReflection()->
414-
MutableRepeatedPtrField<google::protobuf::Message>(&message, &field);
422+
GetMutableRepeatedFieldRef<google::protobuf::Message>(&message, &field);
415423
Py_ssize_t list_size = PyList_Size(list);
416424

417425
if (list_size > 0) {
418-
mutable_field->Reserve(list_size);
419426
for (Py_ssize_t idx = 0; idx < list_size; ++idx) {
420427
google::protobuf::Message* msg = CreateMessage(PyList_GetItem(list, idx), factory);
421428
if (!msg) {
422429
// CreateMessage already reported an error, we can leave quietly
423430
return;
424431
}
425-
mutable_field->AddAllocated(msg);
432+
mutable_field.Add(*msg);
426433
}
427434
}
428435
}
@@ -432,15 +439,14 @@ static void AddPyListToMessageRepeatedString(
432439
google::protobuf::Message& message,
433440
const google::protobuf::FieldDescriptor& field,
434441
PyObject* list) {
435-
google::protobuf::RepeatedPtrField<google::protobuf::string>* mutable_field =
442+
google::protobuf::MutableRepeatedFieldRef<google::protobuf::string> mutable_field =
436443
message.GetReflection()->
437-
MutableRepeatedPtrField<google::protobuf::string>(&message, &field);
444+
GetMutableRepeatedFieldRef<google::protobuf::string>(&message, &field);
438445
Py_ssize_t list_size = PyList_Size(list);
439446

440447
if (list_size > 0) {
441-
mutable_field->Reserve(list_size);
442448
for (Py_ssize_t idx = 0; idx < list_size; ++idx) {
443-
mutable_field->AddAllocated(new google::protobuf::string(
449+
mutable_field.Add(google::protobuf::string(
444450
python_cast<std::string>(PyList_GetItem(list, idx))));
445451
}
446452
}
@@ -569,6 +575,10 @@ static void ConvertPyToPbRepeated(
569575
message, field, list);
570576
return;
571577
}
578+
579+
// Tag-delimited message. Deprecated.
580+
case google::protobuf::FieldDescriptor::TYPE_GROUP:
581+
break;
572582
}
573583

574584
assert(false);

0 commit comments

Comments
 (0)