diff --git a/.gitignore b/.gitignore index 94d4066..c6e8698 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ /build *.pyc +umysql.egg-info +umysql.so +/.project +/.pydevproject diff --git a/README b/README index d36779a..9a655e8 100644 --- a/README +++ b/README @@ -1,10 +1,12 @@ +:: WARNING :: +This driver is no longer supported or recommended. See https://github.com/zodb/relstorage/issues/264 + :: Description :: -A fast MySQL driver written in pure C/C++ for Python. +A fast MySQL driver written in pure C/C++ for Python. Compatible with gevent through monkey patching :: Requirements :: -Requires Python (http://www.python.org) +Requires Python (http://www.python.org) :: Installation :: python setup.py build install - diff --git a/lib/Connection.cpp b/lib/Connection.cpp index fcacef6..8d6f516 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -68,10 +68,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define snprintf _snprintf #endif -//#define PRINTMARK() fprintf(stderr, "%08x:%s:%s MARK(%d)\n", GetTickCount(), __FILE__, __FUNCTION__, __LINE__) -#define PRINTMARK() +//#define PRINTMARK() fprintf(stderr, "%08x:%s:%s MARK(%d)\n", GetTickCount(), __FILE__, __FUNCTION__, __LINE__) +#define PRINTMARK() -Connection::Connection (UMConnectionCAPI *_capi) +Connection::Connection (UMConnectionCAPI *_capi) : m_reader(MYSQL_RX_BUFFER_SIZE) , m_writer(MYSQL_TX_BUFFER_SIZE) { @@ -127,15 +127,16 @@ void Connection::scramble(const char *_scramble1, const char *_scramble2, UINT8 for (int index = 0; index < 20; index ++) { - _outToken[index] = final_hash[index] ^ stage1_hash[index]; + _outToken[index] = final_hash[index] ^ stage1_hash[index]; } } bool Connection::readSocket() { + m_reader.defrag(); size_t bytesToRecv = m_reader.getEndPtr() - m_reader.getWritePtr(); - assert (bytesToRecv <= m_reader.getEndPtr() - m_reader.getWritePtr()); + assert (bytesToRecv <= m_reader.getEndPtr() - m_reader.getWritePtr()); if (bytesToRecv == 0) { @@ -207,7 +208,7 @@ bool Connection::close(void) m_writer.finalize(0); if (!sendPacket()) - { + { m_capi.clearException(); } } diff --git a/lib/PacketReader.cpp b/lib/PacketReader.cpp index 4acc321..0e206b5 100644 --- a/lib/PacketReader.cpp +++ b/lib/PacketReader.cpp @@ -96,6 +96,22 @@ void PacketReader::skip() } } +void PacketReader::defrag(void) +{ + if (m_writeCursor == m_buffEnd && m_readCursor > m_buffStart) { + assert (m_packetEnd == NULL); + size_t bytesToCopy = m_writeCursor - m_readCursor; + //fprintf(stderr, "%s: Transferring %zu bytes to beginning\n", __FUNCTION__, bytesToCopy); + memmove(m_buffStart, m_readCursor, bytesToCopy); + assert (*m_buffStart == *m_readCursor); + assert (m_buffStart[1] == m_readCursor[1]); + m_readCursor = m_buffStart; + m_writeCursor = m_buffStart + bytesToCopy; + memset(m_writeCursor + 1, 0, m_buffEnd - m_writeCursor - 1); + } + +} + void PacketReader::push(size_t _cbData) { //fprintf (stderr, "%s: Pushing %u bytes\n", __FUNCTION__, _cbData); @@ -249,20 +265,20 @@ UINT8 *PacketReader::readLengthCodedBinary(size_t *_outLen) case 252: m_readCursor ++; *_outLen = (size_t) *((UINT16 *) m_readCursor); - m_readCursor += 2; + m_readCursor += 2; break; case 253: m_readCursor ++; *_outLen = (size_t) *((UINT32 *) m_readCursor); *_outLen &= 0xffffff; - m_readCursor += 3; + m_readCursor += 3; break; case 254: m_readCursor ++; *_outLen = (size_t) *((UINT64 *) m_readCursor); - m_readCursor += 8; + m_readCursor += 8; break; } @@ -326,6 +342,3 @@ UINT64 PacketReader::readLengthCodedInteger() return ret; } - - - diff --git a/lib/PacketReader.h b/lib/PacketReader.h index 557f4ad..735dbfa 100644 --- a/lib/PacketReader.h +++ b/lib/PacketReader.h @@ -76,6 +76,7 @@ class PacketReader PacketReader (size_t cbSize); ~PacketReader (void); void skip(); + void defrag(); void push(size_t _cbData); char *getWritePtr(); char *getStartPtr(); @@ -95,4 +96,4 @@ class PacketReader UINT8 *readLengthCodedBinary(size_t *_outLen); }; -#endif \ No newline at end of file +#endif diff --git a/python/umysql.c b/python/umysql.c index 2564e97..c568ed3 100644 --- a/python/umysql.c +++ b/python/umysql.c @@ -769,11 +769,12 @@ PyObject *Connection_isConnected(Connection *self, PyObject *args) Py_RETURN_FALSE; } +#ifndef PYPY_VERSION PyObject *PyUnicode_EncodeCP1250Helper(const Py_UNICODE *data, Py_ssize_t length, const char *errors) { return PyUnicode_Encode (data, length, "cp1250", errors); } - +#endif PyObject *HandleError(Connection *self, const char *funcName) { @@ -878,8 +879,12 @@ PyObject *Connection_connect(Connection *self, PyObject *args) else if (strcmp (pstrCharset, "cp1250") == 0) { +#ifndef PYPY_VERSION self->charset = MCS_cp1250_general_ci; self->PFN_PyUnicode_Encode = PyUnicode_EncodeCP1250Helper; +#else + return PyErr_Format (PyExc_ValueError, "Unsupported character set '%s' specified", pstrCharset); +#endif } else if (strcmp (pstrCharset, "utf8mb4") == 0) @@ -1093,7 +1098,7 @@ PyObject *EscapeQueryArguments(Connection *self, PyObject *inQuery, PyObject *it { /* FIXME: Allocate a PyString and resize it just like the Python code does it */ - obuffer = (char *) PyObject_Malloc(cbOutQuery); + obuffer = (char *) PyMem_Malloc(cbOutQuery); heap = 1; } else @@ -1124,7 +1129,7 @@ PyObject *EscapeQueryArguments(Connection *self, PyObject *inQuery, PyObject *it if (*iptr != 's' && *iptr != '%') { Py_DECREF(iterator); - if (heap) PyObject_Free(obuffer); + if (heap) PyMem_Free(obuffer); return PyErr_Format (PyExc_ValueError, "Found character %c expected %%", *iptr); } diff --git a/setup.py b/setup.py index 81383bc..58b6918 100644 --- a/setup.py +++ b/setup.py @@ -68,6 +68,8 @@ Programming Language :: Python Topic :: Database Topic :: Software Development :: Libraries :: Python Modules +Programming Language :: Python :: Implementation :: CPython +Programming Language :: Python :: Implementation :: PyPy """.splitlines())) """ @@ -75,13 +77,13 @@ shutil.rmtree("./build") except(OSError): pass -""" - +""" + libs = [] if sys.platform != "win32": libs.append("stdc++") - + if sys.platform == "win32": libs.append("ws2_32") @@ -92,16 +94,16 @@ library_dirs = [], libraries=libs, define_macros=[('WIN32_LEAN_AND_MEAN', None)]) - + setup (name = 'umysql', - version = "2.61", + version = "2.62.dev0", description = "Ultra fast MySQL driver for Python", ext_modules = [module1], author="Jonas Tarnstrom", author_email="jonas.tarnstrom@esn.me", download_url="http://github.com/esnme/ultramysql", license="BSD License", - platforms=['any'], + platforms=['any'], url="http://www.esn.me", classifiers=CLASSIFIERS, - ) + )