--- Coro-Mysql/Mysql.xs 2011/02/17 02:05:15 1.7 +++ Coro-Mysql/Mysql.xs 2013/08/03 02:11:27 1.11 @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -23,11 +23,13 @@ #include "violite.h" -#define DESC_OFFSET 22 - #define CoMy_MAGIC 0x436f4d79 typedef struct { +#if DESC_IS_PTR + char desc[30]; + const char *old_desc; +#endif int magic; SV *corohandle_sv, *corohandle; int bufofs, bufcnt; @@ -37,10 +39,15 @@ char buf[VIO_READ_BUFFER_SIZE]; } ourdata; -#define OURDATAPTR (*((ourdata **)((vio)->desc + DESC_OFFSET))) +#if DESC_IS_PTR +# define OURDATAPTR (*(ourdata **)&((vio)->desc)) +#else +# define DESC_OFFSET 22 +# define OURDATAPTR (*((ourdata **)((vio)->desc + DESC_OFFSET))) +#endif -static int -our_read (Vio *vio, xgptr p, int len) +static xlen +our_read (Vio *vio, xgptr p, xlen len) { ourdata *our = OURDATAPTR; @@ -94,8 +101,8 @@ return len; } -static int -our_write (Vio *vio, const xgptr p, int len) +static xlen +our_write (Vio *vio, cxgptr p, xlen len) { char *ptr = (char *)p; my_bool dummy; @@ -167,6 +174,10 @@ SvREFCNT_dec (our->corohandle); SvREFCNT_dec (our->corohandle_sv); +#if DESC_IS_PTR + vio->desc = our->old_desc; +#endif + Safefree (our); vio->read = vio_read; @@ -215,13 +226,18 @@ } void -_patch (IV sock, int fd, SV *corohandle_sv, SV *corohandle) +_patch (IV sock, int fd, unsigned long client_version, SV *corohandle_sv, SV *corohandle) CODE: { MYSQL *my = (MYSQL *)sock; Vio *vio = my->net.vio; ourdata *our; + /* matching versions are required but not sufficient */ + if (client_version != mysql_get_client_version ()) + croak ("DBD::mysql linked against different libmysqlclient library than Coro::Mysql (%lu vs. %lu).", + client_version, mysql_get_client_version ()); + if (fd != my->net.fd) croak ("DBD::mysql fd and libmysql disagree - library mismatch, unsupported transport or API changes?"); @@ -229,7 +245,7 @@ croak ("DBD::mysql fd and vio-sd disagree - library mismatch, unsupported transport or API changes?"); if (vio->vioclose != vio_close) - croak ("vio.write has unexpected content - library mismatch, unsupported transport or API changes?"); + croak ("vio.vioclose has unexpected content - library mismatch, unsupported transport or API changes?"); if (vio->write != vio_write) croak ("vio.write has unexpected content - library mismatch, unsupported transport or API changes?"); @@ -249,8 +265,13 @@ ev_io_init (&(our->ww), iocb, vio->sd, EV_WRITE); } #endif - +#if DESC_IS_PTR + our->old_desc = vio->desc; + strncpy (our->desc, vio->desc, sizeof (our->desc)); + our->desc [sizeof (our->desc) - 1] = 0; +#else vio->desc [DESC_OFFSET - 1] = 0; +#endif OURDATAPTR = our; vio->vioclose = our_close;