Skip to content

Commit

Permalink
Add tox.ini and more entries in .gitignore.
Browse files Browse the repository at this point in the history
Also, update README to note that windows version is untested.
  • Loading branch information
jd-boyd committed Nov 19, 2015
1 parent 874cc0c commit 45b62dd
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,7 @@
*.egg-info/
build/
*.so
dist
MANIFEST
.tox
.\#*
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -6,7 +6,7 @@
Copyright (c) 1996-2002 Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
Copyright (c) 2011-2014 Joshua D. Boyd
Copyright (c) 2011-2015 Joshua D. Boyd
<jdboyd@jdboyd.net>
https://github.com/jd-boyd/python-lzo
```
Expand Down Expand Up @@ -46,6 +46,10 @@ in the Python Reference Manual for more information.
Additionally you should read the docs and study the example
programs that ship with the LZO library. Really.

# Notes

The windows version is untested. If you do test it, please let me
know the results.

# Copyright

Expand All @@ -59,4 +63,3 @@ Joshua D. Boyd <jdboyd@jdboyd.net>

The LZO and Python-LZO algorithms and implementations are distributed under
the terms of the GNU General Public License (GPL). See the file COPYING.

60 changes: 60 additions & 0 deletions lzomodule.c
Expand Up @@ -51,6 +51,9 @@
# error "Need LZO version 1.07 or greater"
#endif




#undef UNUSED
#define UNUSED(var) ((void)&var)

Expand Down Expand Up @@ -92,7 +95,11 @@ compress(PyObject *dummy, PyObject *args)
out_len = in_len + in_len / 16 + 64 + 3;

/* alloc buffers */
#if PY_MAJOR_VERSION >= 3
result_str = PyBytes_FromStringAndSize(NULL, 5 + out_len);
#else
result_str = PyString_FromStringAndSize(NULL, 5 + out_len);
#endif
if (result_str == NULL)
return PyErr_NoMemory();
if (level == 1)
Expand All @@ -106,7 +113,11 @@ compress(PyObject *dummy, PyObject *args)
}

/* compress */
#if PY_MAJOR_VERSION >= 3
out = (lzo_bytep) PyBytes_AsString(result_str);
#else
out = (lzo_bytep) PyString_AsString(result_str);
#endif
new_len = out_len;
if (level == 1)
{
Expand Down Expand Up @@ -135,7 +146,11 @@ compress(PyObject *dummy, PyObject *args)

/* return */
if (new_len != out_len)
#if PY_MAJOR_VERSION >= 3
_PyBytes_Resize(&result_str, 5 + new_len);
#else
_PyString_Resize(&result_str, 5 + new_len);
#endif
return result_str;
}

Expand Down Expand Up @@ -172,12 +187,20 @@ decompress(PyObject *dummy, PyObject *args)
goto header_error;

/* alloc buffers */
#if PY_MAJOR_VERSION >= 3
result_str = PyBytes_FromStringAndSize(NULL, out_len);
#else
result_str = PyString_FromStringAndSize(NULL, out_len);
#endif
if (result_str == NULL)
return PyErr_NoMemory();

/* decompress */
#if PY_MAJOR_VERSION >= 3
out = (lzo_bytep) PyBytes_AsString(result_str);
#else
out = (lzo_bytep) PyString_AsString(result_str);
#endif
new_len = out_len;
err = lzo1x_decompress_safe(in+5, in_len, out, &new_len, NULL);
if (err != LZO_E_OK || new_len != out_len)
Expand Down Expand Up @@ -228,7 +251,11 @@ optimize(PyObject *dummy, PyObject *args)
goto header_error;

/* alloc buffers */
#if PY_MAJOR_VERSION >= 3
result_str = PyBytes_FromStringAndSize(in, len);
#else
result_str = PyString_FromStringAndSize(in, len);
#endif
if (result_str == NULL)
return PyErr_NoMemory();
out = (lzo_bytep) PyMem_Malloc(out_len > 0 ? out_len : 1);
Expand All @@ -239,7 +266,11 @@ optimize(PyObject *dummy, PyObject *args)
}

/* optimize */
#if PY_MAJOR_VERSION >= 3
in = (lzo_bytep) PyBytes_AsString(result_str);
#else
in = (lzo_bytep) PyString_AsString(result_str);
#endif
new_len = out_len;
err = lzo1x_optimize(in+5, in_len, out, &new_len, NULL);
PyMem_Free(out);
Expand Down Expand Up @@ -282,7 +313,11 @@ adler32(PyObject *dummy, PyObject *args)
return NULL;
if (len > 0)
val = lzo_adler32((lzo_uint32)val, (const lzo_bytep)buf, len);
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong(val);
#else
return PyInt_FromLong(val);
#endif
}


Expand All @@ -309,7 +344,11 @@ crc32(PyObject *dummy, PyObject *args)
return NULL;
if (len > 0)
val = lzo_crc32((lzo_uint32)val, (const lzo_bytep)buf, len);
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong(val);
#else
return PyInt_FromLong(val);
#endif
}


Expand Down Expand Up @@ -384,19 +423,40 @@ void initlzo(void)
LzoError = PyErr_NewException("lzo.error", NULL, NULL);
PyDict_SetItemString(d, "error", LzoError);

#if PY_MAJOR_VERSION >= 3
v = PyBytes_FromString("Markus F.X.J. Oberhumer <markus@oberhumer.com>");
#else
v = PyString_FromString("Markus F.X.J. Oberhumer <markus@oberhumer.com>");
#endif

PyDict_SetItemString(d, "__author__", v);
Py_DECREF(v);
#if PY_MAJOR_VERSION >= 3
v = PyBytes_FromString(MODULE_VERSION);
#else
v = PyString_FromString(MODULE_VERSION);
#endif
PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v);
#if PY_MAJOR_VERSION >= 3
v = PyLong_FromLong((long)lzo_version());
#else
v = PyInt_FromLong((long)lzo_version());
#endif
PyDict_SetItemString(d, "LZO_VERSION", v);
Py_DECREF(v);
#if PY_MAJOR_VERSION >= 3
v = PyBytes_FromString(lzo_version_string());
#else
v = PyString_FromString(lzo_version_string());
#endif
PyDict_SetItemString(d, "LZO_VERSION_STRING", v);
Py_DECREF(v);
#if PY_MAJOR_VERSION >= 3
v = PyBytes_FromString(lzo_version_date());
#else
v = PyString_FromString(lzo_version_date());
#endif
PyDict_SetItemString(d, "LZO_VERSION_DATE", v);
Py_DECREF(v);

Expand Down
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -82,4 +82,3 @@ def get_kw(**kw): return kw
setup_args["platforms"] = "All"

setup(**setup_args)

1 change: 0 additions & 1 deletion tests/test.py
Expand Up @@ -102,4 +102,3 @@ def main(args):

if __name__ == '__main__':
sys.exit(main(sys.argv))

8 changes: 8 additions & 0 deletions tox.ini
@@ -0,0 +1,8 @@
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py27,py34
[testenv]
deps=
nose
#commands=nosetests # or 'nosetests' or ...
commands=python tests/test.py

0 comments on commit 45b62dd

Please sign in to comment.