Skip to content

Commit a001221

Browse files
committed
SWIG python minimal example
1 parent ba9fcc4 commit a001221

14 files changed

Lines changed: 119 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ C and C++ minimal examples. Asserts used wherever possible. Cheatsheets, tutoria
2121
1. [C from C++](c-from-cpp/)
2222
1. [C++ from C](cpp-from-c/)
2323
1. [Fortran from C](fortran-from-c/)
24+
1. [SWIG](swig.md)
2425
1. Profiling
2526
1. [gprof](gprof.md)
2627
1. [Valgrind](valgrind.md)
2728
1. [perf](perf.md)
2829
1. Analysis tools
2930
1. [GDB](gdb/)
3031
1. [cflow](cflow.md)
32+
1. Media
33+
1. [FFmpeg](ffmpeg/)
3134
1. [Linting tools](linting-tools.md)
3235
1. [Frama-C](frama-c/)
3336
1. [Boost](boost/)

‎ffmpeg/README.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# FFmpeg
2+
3+
<https://en.wikipedia.org/wiki/FFmpeg>
4+
5+
Offers a high level API to abstract multiple codecs.
6+
7+
Codecs are algorithms that compress audio and video.
8+
9+
You want to compress them to:
10+
11+
- save disk space, e.g. when you save a film to disk. The container (e.g. OGG), contains a coded video file.
12+
13+
- save bandwidth when it is limited. E.g. networks, USB cables (there are professional cameras that encode video to send higher quality over the cable)
14+
15+
FFmpeg also takes care of breaking up the decoding into packages and sending / receiving it.
16+
17+
Video / audio compression is different form that of images since multiple images can be compressed together as they differ very little between them.
18+
19+
## libav
20+
21+
Fork because of war. Still highly compatible.
22+
23+
History of the fork: https://en.wikipedia.org/wiki/Libav#History
24+
25+
libav is going to die now that Debian switched back to FFmpeg.

‎opengl/alternatives.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Alternatives
2+
3+
- <https://en.wikipedia.org/wiki/Vulkan_%28API%29>
4+
5+
<http://gamedev.stackexchange.com/questions/96014/what-is-vulkan-and-how-does-it-differ-from-opengl>

‎swig/README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SWIG
2+
3+
Tested on Ubuntu 15.10, SWIG 2.0.12, Python 2.7.
4+
5+
1. [Introduction](introduction.md)
6+
1. Examples
7+
1. [Python](python/)

‎swig/configure‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
sudo aptitude update
3+
sudo aptitude install -y libpython2.7-dev swig

‎swig/introduction.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Introduction
2+
3+
<https://en.wikipedia.org/wiki/SWIG>
4+
5+
<http://www.swig.org/doc.html>
6+
7+
Write C/C++ with some extra magic annotations, and generate bindings for several languages, including Python and Java.
8+
9+
Awesome because it can parse your **existing** headers and generate bindings to a ton of languages. Almost no need to touch your C / C++ code.

‎swig/python/.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.pyc
2+
*.so
3+
build
4+
example.py
5+
example_wrap.c

‎swig/python/Makefile‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.POSIX:
2+
3+
.PHONY: all clean
4+
5+
all:
6+
swig -python example.i
7+
python setup.py build_ext --inplace
8+
9+
clean:
10+
rm -rf build example_wrap.c example.py *.pyc *.so
11+
12+
test: all
13+
[ "$$(python main.py)" = '24' ]

‎swig/python/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Python
2+
3+
Python SWIG example. Taken from: <http://www.swig.org/Doc2.0/Python.html#Python_nn3>

‎swig/python/example.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "example.h"
2+
3+
int fact(int n) {
4+
if (n < 0){ /* This should probably return an error, but this is simpler */
5+
return 0;
6+
}
7+
if (n == 0) {
8+
return 1;
9+
}
10+
else {
11+
/* testing for overflow would be a good idea here */
12+
return n * fact(n-1);
13+
}
14+
}

0 commit comments

Comments
 (0)