Giter Site home page Giter Site logo

bitey's People

Contributors

dabeaz avatar takluyver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitey's Issues

segfault if py_module gets garbage collected

I was working on an IPython extension which provides a cell magic for running C code via bitey, e.g.:

In [4]: %load_ext biteymagic

In [5]: %%bitey
   ...: int life() { return 42; }
   ...: 

In [6]: life()
Out[6]: 42

However I was running into random segfaults, often after running %timeit or similar, indicating that garbage collection was likely to blame. To cut to the chase, the issue was because I called bitey.loader.build_module to build a module, extracted the functions into the current namespace, but never saved the built module in sys.modules. When the module was garbage collected (and hence _llvm_engine/_llvm_module get deleted).... BOOM!

To fix the bug, either of the following would be sufficient:

  1. I could add the module to sys.modules. In this case, I'd suggest a short note in the docstring.
  2. Keep a reference in the python wrapper function object to the execution engine, i.e. set _llvm_engine and _llvm_module as attributes.

Patch to make biteymagic work w/o spawning CLI window on Windows

While executing with biteymagic on Windows, command line window pops (calling clang action) which can be improved (disabled) by adding couple of lines:

--- biteymagic.bak  2012-11-10 22:34:43.406173200 +0100
+++ biteymagic.py   2012-11-10 22:30:38.421798200 +0100
@@ -75,10 +75,19 @@

         if not os.path.exists(o_path):
             try:
-                subprocess.check_output(['clang', '-c', '-emit-llvm'] +
-                                        line.split() + [c_name],
-                                        stderr=subprocess.STDOUT,
-                                        cwd=lib_dir)
+                if sys.platform == "win32":
+                    startupinfo = subprocess.STARTUPINFO()
+                    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
+                    subprocess.check_output(['clang', '-c', '-emit-llvm'] +
+                                            line.split() + [c_name],
+                                            stderr=subprocess.STDOUT,
+                                            cwd=lib_dir,
+                                            startupinfo=startupinfo)
+                else:
+                    subprocess.check_output(['clang', '-c', '-emit-llvm'] +
+                                            line.split() + [c_name],
+                                            stderr=subprocess.STDOUT,
+                                            cwd=lib_dir)
             except subprocess.CalledProcessError as e:
                 print(e.output, file=sys.stderr)
                 print("ERROR: command `%s` failed." %

Magic number checking code in loader.py seems wrong

In _check_magic you have:

magic = open(filename,"rb").read(4)

And then:

`elif magic == b'\x42\x43':``

It seems wrong to me. magic is 4 bytes long! You maybe meant:

elif magic[:2] == b'\x42\x43 ?

Without this change bitey examples don't run

python dumps core on "import fib" in "typical" install

The question is: which versions of the libs are required?

I've tried to install things in "dumb user" way (in Ubuntu 12.04):

sudo apt-get install clang llvm-dev python-llvm \  
&& git clone https://github.com/dabeaz/bitey.git \  
&& cd bitey \  
&& python ./setup.py build \  
&& sudo python ./setup.py install  \  
&& python  
Python 2.7.3 (default, Aug  1 2012, 05:16:07)   
[GCC 4.6.3] on linux2  
Type "help", "copyright", "credits" or "license" for more information.  
>>> import bitey  
>>> import fib  
Segmentation fault (core dumped)

where

$ cat fib.c
/* fib.c */
int fib(int n) {
    if (n < 3) {
       return 1;
    } else {
       return fib(n-1) + fib(n-2);
    }
}
$ file fib.*
fib.c: ASCII text
fib.o: LLVM bitcode
$ dpkg -l | egrep 'clang|llvm-dev|python-llvm'
ii  clang                                   3.0-6ubuntu3                            Low-Level Virtual Machine (LLVM), C language family frontend
ii  libclang-common-dev                     3.0-6ubuntu3                            clang library - Common development package
ii  llvm-dev                                2.9-7                                   Low-Level Virtual Machine (LLVM), libraries and headers
ii  python-llvm                             0.6+svn105-1                            Python bindings for LLVM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.