dabeaz / bitey Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
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:
sys.modules
. In this case, I'd suggest a short note in the docstring._llvm_engine
and _llvm_module
as attributes.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." %
I think many people will concern this.
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
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
One of bitey dependencies - llvm-py (https://github.com/llvmpy/llvmpy) is now deprecated and is replaced with llvmlite (https://github.com/numba/llvmlite). Are there any plans to migrate bitey from llvm-py to llvmlite? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.