-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug when I trying install the mariadb with pip #29
base: 1.1
Are you sure you want to change the base?
Conversation
…emoving the & operand
Hey, there! Same issue here. Do you need to recompile the c files somehow after the change? Please, specify the exact steps you went through:) Thanks in advance. |
Yes. It needs to you install the package from source. |
mariadb/mariadb_cursor.c
Outdated
@@ -1135,7 +1135,7 @@ MrdbCursor_execute_text(MrdbCursor *self, PyObject *stmt) | |||
statement = PyUnicode_AsUTF8AndSize(stmt, (Py_ssize_t *)&statement_len); | |||
} else if (Py_TYPE(stmt) == &PyBytes_Type) | |||
{ | |||
PyBytes_AsStringAndSize(stmt, &statement, (Py_ssize_t *)&statement_len); | |||
PyBytes_AsStringAndSize(stmt, (char**)statement, (Py_ssize_t *)&statement_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the address (&) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello. I remove it to convert directly to char**
.
I tried changing the statement type from const char*
to char*
and it also worked.
However, I don't know what is the best way to do it and whether the latter could cause problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of casting away the const
incorrectly, within this function you can instead drop const
from the declaration of statement
:
diff --git a/mariadb/mariadb_cursor.c b/mariadb/mariadb_cursor.c
index 65fab74..191f93a 100644
--- a/mariadb/mariadb_cursor.c
+++ b/mariadb/mariadb_cursor.c
@@ -1125,7 +1125,7 @@ MrdbCursor_execute_text(MrdbCursor *self, PyObject *stmt)
{
int rc;
MYSQL *db;
- const char *statement;
+ char *statement;
size_t statement_len= 0;
MARIADB_CHECK_CONNECTION(self->connection, NULL);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey. I made these changes and updated the pr. Thanks :)
…ation I made this change based on pr comments. I removed the const key when declaring statement and reverted the changes I had made previously (explicitly casting the statement variable to char**)
When you remove const from statement, you will break the line with PyUnicode_AsUTF8AndSize():
That funciton is defined as
seen in https://docs.python.org/3/c-api/unicode.html. Also the function `mysql_send_query(db, statement, (long)statement_len) is defined as
So either we cast the
or for more readability:
|
Within this function, we can also exchange the
|
I was not able to install mariadb-connector with pip because it was getting a compiler error when building.
Probably because one of the flags -Werror=format-security which treats warning as error.
The output of error:
Since the function PyBytes_AsStringAndSize from bytesobjects.h expectate a char** and not a const char** I remove the "pass by reference" and add a explicit conversion of type of statement to (char**).
After that I could install the mariadb package with pip using the source code that I edit.