Bug #91955 8.0 broke plugin API for C
Submitted: 9 Aug 2018 19:06 Modified: 9 Nov 2018 3:44
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[9 Aug 2018 19:06] Laurynas Biveinis
Description:
Unless I'm missing something, 8.0 broke ability to build C plugins.

A plugin source file (written in C) includes include/mysql/plugin.h, which further includes status_var.h, and there we find

struct SHOW_VAR {
...
};
...
typedef int (*mysql_show_var_func)(MYSQL_THD, SHOW_VAR *, char *);
...

resulting in 

/Users/laurynas/percona/mysql-server/include/mysql/status_var.h:90:47: error: must use 'struct' tag to refer to type 'SHOW_VAR'
typedef int (*mysql_show_var_func)(MYSQL_THD, SHOW_VAR *, char *);
                                              ^
                                              struct 

with clang at least. This appears to be introduced by -

commit 545b168a5b8966cd4a35386dfcafd31f35e080a7
Author: Steinar H. Gunderson <steinar.gunderson@oracle.com>
Date:   Wed Sep 13 12:57:13 2017 +0200

    Bug #26781567: REMOVE C LEGACY
    
    Replace the final typedefs to st_* and *_st structs.
    
    Note in particular that st_mysql_show_var was called sometimes SHOW_VAR
    and sometimes STATUS_VAR (by way of duplicated forward-declaring typedefs).
    This patch changes it so that it's universally SHOW_VAR, which seems to
    match better with the original type name.
    
    Change-Id: Ide483ceac31284d909c42adb46496308dd4d4f85

How to repeat:
See above

Suggested fix:
Add that struct tag
Have a small test C plugin in-tree to avoid regressions in the future, as already suggested in bug 89288
[10 Aug 2018 5:15] Laurynas Biveinis
Then

In file included from /Users/laurynas/percona/mysql-server/include/mysql/plugin.h:76:
In file included from /Users/laurynas/percona/mysql-server/include/mysql/services.h:28:
In file included from /Users/laurynas/percona/mysql-server/include/mysql/service_command.h:32:
/Users/laurynas/percona/mysql-server/include/mysql/com_data.h:64:3: error: must use 'struct' tag to refer to type 'PS_PARAM'
  PS_PARAM *parameters;
  ^
  struct 

... and many more errors in that header
[10 Aug 2018 5:40] Laurynas Biveinis
In file included from /Users/laurynas/percona/mysql-server/include/mysql/plugin.h:76:
In file included from /Users/laurynas/percona/mysql-server/include/mysql/services.h:28:
In file included from /Users/laurynas/percona/mysql-server/include/mysql/service_command.h:33:
/Users/laurynas/percona/mysql-server/include/mysql/service_srv_session.h:47:8: error: expected identifier or '('
extern "C" struct srv_session_service_st {
       ^
[10 Aug 2018 5:42] Laurynas Biveinis
In file included from /Users/laurynas/percona/mysql-server/include/mysql/plugin.h:76:
In file included from /Users/laurynas/percona/mysql-server/include/mysql/services.h:28:
In file included from /Users/laurynas/percona/mysql-server/include/mysql/service_command.h:35:
/Users/laurynas/percona/mysql-server/include/decimal.h:58:38: error: must use 'struct' tag to refer to type 'decimal_t'
int string2decimal(const char *from, decimal_t *to, char **end);
                                     ^
                                     struct
[10 Aug 2018 8:55] Laurynas Biveinis
After some mechanical fixes we bump into service_rules_table.h, which is a completely C++ header.
[15 Aug 2018 14:37] Steinar Gunderson
Writing plugins in C is not supported. Reassigning to documentation so this can be made clear.
[16 Aug 2018 5:30] MySQL Verification Team
Hello Laurynas,

Thank you for the report and feedback!
Verifying this as a doc issue per Steinar's last note.

regards,
Umesh
[9 Nov 2018 3:44] Paul DuBois
Posted by developer:
 
Correct, plugins now must be compiled as C++ code, as of MySQL 8.0.13. I added a changelog entry for Bug#26781567:

Previously, MySQL plugins could be written in C or C++. MySQL header
files used by plugins now contain C++ code, which means that plugins
must be written in C++, not C.

Also updated https://dev.mysql.com/doc/refman/8.0/en/writing-plugins-overview.html to list conditions for plugin writing.