Random problems and solutions
The old list of computer problems/solutions is also available.
- How to wrap an STL vector of pairs in Boost.Python
- The VideoLAN client won't compile when FFMPEG is not a static library
- Mediawiki redirects the parent window when loaded in a frameset or
iframe
How to wrap an STL vector of pairs in Boost.Python
The following headers are required:
#include <boost/python/suite/indexing/indexing_suite.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
Add a struct with a convert method which maps std::pair instances onto Python tuples:
template<class T1, class T2>
struct PairToTupleConverter {
static PyObject* convert(std::pair<T1, T2> const& pair) {
return incref(make_tuple(pair.first, pair.second).ptr());
}
static PyTypeObject const *get_pytype() {return &PyTuple_Type;}
};
Inside the BOOST_PYTHON_MODULE declaration, instantiate a to_python_converter for each pair type you use:
to_python_converter< std::pair< uint32_t, uint16_t >, PairToTupleConverter< uint32_t, uint16_t <, true <();
to_python_converter< std::pair< uint16_t, uint16_t >, PairToTupleConverter< uint16_t, uint16_t <, true <();
Now declare wrappers for vectors of these elements:
// Vector of uint32_t, uint16_t pairs
class_< std::vector< std::pair< uint32_t, uint16_t > > > ("vector_pair_offset_len")
.def(vector_indexing_suite< std::vector< std::pair< uint32_t, uint16_t > >, true >())
;
The final template argument to vector_indexing_suite, bool NoProxy, is important because it stops values from the vector being returned by proxy (see the full documentation on the vector_indexing_suite class).
The VideoLAN client won't compile when FFMPEG is not a static library
If you are compiling VLC and need to link your compiled version of FFMPEG dynamically rather than statically, you may encounter a problem where VLC's libavcodec, libavutil, libpostproc, libswscale and libavformat but the build process fails when you make VLC.
These instructions may be useful if
- you need to be able to make changes to FFMPEG (e.g. in libavcodec) and see the effects in VLC, so you want to compile FFMPEG as a shared library;
- you don't want to
make installyour compiled FFMPEG binaries; - an error occurs during VLC's build process, saying that libavcodec.a (for example) can't be found.
To compile FFMPEG to shared libraries only, run ./configure --disable-static --enable-shared. It will then only produce {libavcodec, libswscale, ...}.so (and not the corresponding .a files).
VLC uses pkg-config to find the compiled FFMPEG binaries. If you don't want to make install your FFMPEG binaries, you can override pkg-config's search to find your compiled binaries by setting the environment variable PKG_CONFIG_PATH.For example,
$ PKG_CONFIG_PATH=${FFMPEG_PREFIX}/libavcodec/:${FFMPEG_PREFIX}/libavutil:[etc.] ./configure --enable-debugIf you run make in the VLC directory now, you will get an error, because VLC will search for static .a files rather than .so shared libraries.
The only way I could find to fix this is to create static .a files linking back to the .so files, which tricks VLC into compiling with them shared libraries.
#!/bin/sh
FFMPEG_PREFIX=/path/to/ffmpeg/source/root
for L in libavcodec libswscale libpostproc libavformat libavutil
do
mv ${FFMPEG_PREFIX}/$L/$L.so ${FFMPEG_FFMPEG}/$L/$L.a
done;Don't forget to set LD_LIBRARY_PATH to point to your .so libraries when you run VLC.
Mediawiki redirects the parent window when loaded in a frameset or iframe
Have a look at [/usr/share/mediawiki/]skins/common/wikibits.js, and search for 'framesets'. The skin's javascript is set to redirect the location of the parent window to get out of an iframe. To stop this happening, comment out the two lines:
// Un-trap us from framesets
//if (window.top != window)
// window.top.location = window.location;