From a5078d6cd71090aa9139aa729e377b9714b7afed Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Sun, 3 Mar 2013 17:27:01 -0300 Subject: [PATCH 1/6] Added testing infrastructure with travis --- .travis.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..95f434a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,24 @@ +language: python + +python: + - "2.6" + - "2.7" + - "3.2" + - "3.3" + +branches: + only: + - master + +install: + - wget "http://repo.continuum.io/pkgs/free/linux-64/llvm-3.2-0.tar.bz2" + - tar -xjf llvm-3.2-0.tar.bz2 + - PATH+=":`pwd`/bin" + - export LD_LIBRARY_PATH="`pwd`/lib" + - export LLVM_CONFIG_PATH="`pwd`/bin/llvm-config" + - $LLVM_CONFIG_PATH --cflags # test llvm-config + - export LLVMPY_DYNLINK=1 + - python setup.py install -q + +script: python -c "import llvm; llvm.test()" + From 372d6018759744dee6dac70fc6814c452864b7c0 Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Mon, 4 Mar 2013 23:28:10 -0300 Subject: [PATCH 2/6] Changed test command for travis --- .travis.yml | 2 +- llvm/__init__.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 95f434a..f4474f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,5 +20,5 @@ install: - export LLVMPY_DYNLINK=1 - python setup.py install -q -script: python -c "import llvm; llvm.test()" +script: cd ~; python -c "import sys;import llvm;sys.exit(0 if llvm.test() == 0 else 1)" diff --git a/llvm/__init__.py b/llvm/__init__.py index e3e785f..8f71446 100644 --- a/llvm/__init__.py +++ b/llvm/__init__.py @@ -34,9 +34,11 @@ class LLVMException(Exception): def test(verbosity=1): """test(verbosity=1) -> TextTestResult - Run self-test, and return unittest.runner.TextTestResult object. + Run self-test, and return the number of failures + errors """ from llvm.test_llvmpy import run - return run(verbosity=verbosity) + result = run(verbosity=verbosity) + + return len(result.failures) + len(result.errors) From e4996f02d7573cec9033acb65176196a370710c8 Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Mon, 4 Mar 2013 23:47:54 -0300 Subject: [PATCH 3/6] Fix for Python 3.2 --- llvmpy/include/python3adapt.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/llvmpy/include/python3adapt.h b/llvmpy/include/python3adapt.h index 5b19ebe..a60153f 100644 --- a/llvmpy/include/python3adapt.h +++ b/llvmpy/include/python3adapt.h @@ -9,13 +9,10 @@ #define PyBytes_FromStringAndSize PyString_FromStringAndSize #define PyBytes_FromString PyString_FromString -#endif - -#if (PY_VERSION_HEX >= 0x03000000) +#else #define PyString_Check PyUnicode_Check #define PyString_Size PyUnicode_GET_SIZE -#define PyString_AsString PyUnicode_AsUTF8 #define PyString_FromStringAndSize PyUnicode_FromStringAndSize #define PyString_FromString PyUnicode_FromString @@ -27,6 +24,12 @@ #define PyFile_Check(x) (1) +#if (PY_VERSION_HEX < 0x03030000) +#define PyString_AsString(x) PyBytes_AsString(PyUnicode_AsUTF8String(x)) +#else +#define PyString_AsString PyUnicode_AsUTF8 #endif -#endif //PYTHON3ADAPT_H \ No newline at end of file +#endif // (PY_VERSION_HEX < 0x03000000) + +#endif //PYTHON3ADAPT_H From 931352d4bfab72897dc8012c78d9f64739656226 Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Tue, 5 Mar 2013 14:31:21 -0300 Subject: [PATCH 4/6] Fix memory leak in Python 3.2 --- llvmpy/include/python3adapt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvmpy/include/python3adapt.h b/llvmpy/include/python3adapt.h index a60153f..db7f28d 100644 --- a/llvmpy/include/python3adapt.h +++ b/llvmpy/include/python3adapt.h @@ -25,7 +25,7 @@ #define PyFile_Check(x) (1) #if (PY_VERSION_HEX < 0x03030000) -#define PyString_AsString(x) PyBytes_AsString(PyUnicode_AsUTF8String(x)) +#define PyString_AsString _PyUnicode_AsString #else #define PyString_AsString PyUnicode_AsUTF8 #endif From b8da3c7a7335e5b2f4a9cee14fe4ae5783fa000f Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Tue, 5 Mar 2013 18:01:57 -0300 Subject: [PATCH 5/6] Changed imports in llpython --- llpython/byte_control.py | 8 ++++---- llpython/byte_flow.py | 6 +++--- llpython/byte_translator.py | 14 +++++++------- llpython/bytecode_visitor.py | 4 ++-- llpython/gen_bytecode_visitor.py | 4 ++-- llpython/nobitey.py | 7 +++---- llpython/phi_injector.py | 2 +- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/llpython/byte_control.py b/llpython/byte_control.py index 9df6d5c..acd5a41 100644 --- a/llpython/byte_control.py +++ b/llpython/byte_control.py @@ -1,12 +1,12 @@ #! /usr/bin/env python # ______________________________________________________________________ - +from __future__ import absolute_import import opcode -import opcode_util +from . import opcode_util import pprint -from bytecode_visitor import BasicBlockVisitor, BenignBytecodeVisitorMixin -from control_flow import ControlFlowGraph +from .bytecode_visitor import BasicBlockVisitor, BenignBytecodeVisitorMixin +from .control_flow import ControlFlowGraph # ______________________________________________________________________ diff --git a/llpython/byte_flow.py b/llpython/byte_flow.py index 4a878b2..2201791 100644 --- a/llpython/byte_flow.py +++ b/llpython/byte_flow.py @@ -1,11 +1,11 @@ #! /usr/bin/env python # ______________________________________________________________________ - +from __future__ import absolute_import import dis import opcode -from bytecode_visitor import BasicBlockVisitor -import opcode_util +from .bytecode_visitor import BasicBlockVisitor +from . import opcode_util # ______________________________________________________________________ diff --git a/llpython/byte_translator.py b/llpython/byte_translator.py index 3922099..9b6d2de 100644 --- a/llpython/byte_translator.py +++ b/llpython/byte_translator.py @@ -4,19 +4,19 @@ ''' # ______________________________________________________________________ # Module imports - +from __future__ import absolute_import import opcode import types import logging import llvm.core as lc -import opcode_util -import bytetype -from bytecode_visitor import BytecodeFlowVisitor -from byte_flow import BytecodeFlowBuilder -from byte_control import ControlFlowBuilder -from phi_injector import PhiInjector, synthetic_opname +from . import opcode_util +from . import bytetype +from .bytecode_visitor import BytecodeFlowVisitor +from .byte_flow import BytecodeFlowBuilder +from .byte_control import ControlFlowBuilder +from .phi_injector import PhiInjector, synthetic_opname # ______________________________________________________________________ # Module data diff --git a/llpython/bytecode_visitor.py b/llpython/bytecode_visitor.py index dcc3a0c..009d1a0 100644 --- a/llpython/bytecode_visitor.py +++ b/llpython/bytecode_visitor.py @@ -1,10 +1,10 @@ #! /usr/bin/env python # ______________________________________________________________________ - +from __future__ import absolute_import import itertools import opcode -from opcode_util import itercode +from .opcode_util import itercode # ______________________________________________________________________ diff --git a/llpython/gen_bytecode_visitor.py b/llpython/gen_bytecode_visitor.py index 7f922e2..b29bc56 100644 --- a/llpython/gen_bytecode_visitor.py +++ b/llpython/gen_bytecode_visitor.py @@ -1,7 +1,7 @@ #! /usr/bin/env python # ______________________________________________________________________ - -import opcode_util +from __future__ import absolute_import +from . import opcode_util # ______________________________________________________________________ diff --git a/llpython/nobitey.py b/llpython/nobitey.py index 014216b..68bde5f 100644 --- a/llpython/nobitey.py +++ b/llpython/nobitey.py @@ -1,6 +1,6 @@ #! /usr/bin/env python # ______________________________________________________________________ - +from __future__ import absolute_import import sys import os.path import imp @@ -10,9 +10,8 @@ import types import llvm.core as lc import llvm.ee as le -import bytetype -import byte_translator -from pyaddfunc import pyaddfunc +from . import bytetype, byte_translator +from .pyaddfunc import pyaddfunc LLVM_TO_INT_PARSE_STR_MAP = { 8 : 'b', diff --git a/llpython/phi_injector.py b/llpython/phi_injector.py index 6cccb66..ee28ab5 100644 --- a/llpython/phi_injector.py +++ b/llpython/phi_injector.py @@ -1,7 +1,7 @@ #! /usr/bin/env python # ______________________________________________________________________ -from bytecode_visitor import BytecodeFlowVisitor, BenignBytecodeVisitorMixin +from .bytecode_visitor import BytecodeFlowVisitor, BenignBytecodeVisitorMixin # ______________________________________________________________________ From bd129baa0a4413f5872baf8981a92c78ecd27a01 Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Mon, 11 Mar 2013 15:51:03 -0300 Subject: [PATCH 6/6] Reimplemented FunctionAlreadyExists and usage (Exceptions are not iterable in Python 3) --- llvm_cbuilder/builder.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm_cbuilder/builder.py b/llvm_cbuilder/builder.py index 9b970f4..648f384 100644 --- a/llvm_cbuilder/builder.py +++ b/llvm_cbuilder/builder.py @@ -14,7 +14,9 @@ from . import shortnames as types ### class FunctionAlreadyExists(NameError): - pass + + def __init__(self, func): + self.func = func def _is_int(ty): return isinstance(ty, lc.IntegerType) @@ -830,7 +832,7 @@ class CDefinition(object): try: func = self.define(module) except FunctionAlreadyExists as e: - (func,) = e + func = e.func return func def __getattr__(self, attr):