Theme by nostrich, altered by Tyches.
Text
I had a need to use good old SYSV message queues to interoperate with a bunch of old C programs, straight from python. Come in sysv_ipc module to the rescue, which works great on a variety of systems, but I need it on AIX.
Using Perzl wonderful rpm packages for AIX, I was able to compile it with GCC 4.2 and setup it into Python 2.6.
Modify common.h to unset SHM_SIZE (Obsolete step as of sysv_ipc 0.6):
#undef SHM_SIZE
enum GET_SET_IDENTIFIERS {
Export those two vars:
LDSHARED="/opt/freeware/lib/python2.6/config/ld_so_aix gcc -bI:/opt/freeware/lib/python2.6/config/python.exp"
CC="gcc"
You can then go on and:
python setup.py install [--user]
Update: common.h should not be modified anymore.
Text
Based on the wave example from pyaudio:
import pyaudio
import mad
import sys
if len(sys.argv) < 2:
print "Plays a wave file.\n\n" +\
"Usage: %s filename.wav" % sys.argv[0]
sys.exit(-1)
mf = mad.MadFile(sys.argv[1])
p = pyaudio.PyAudio()
# open stream
stream = p.open(format =
p.get_format_from_width(pyaudio.paInt32),
channels = 2,
rate = mf.samplerate(),
output = True)
# read data
data = mf.read()
# play stream
while data != None:
stream.write(data)
data = mf.read()
stream.close()
p.terminate()
Text
This is for Mac OS X, adapt to your needs:
import mad, ao, sys
mf = mad.MadFile(sys.argv[1])
dev = ao.AudioDevice('macosx', bits=32, rate=mf.samplerate(), channels=2)
buf = mf.read()
while buf != None:
dev.play(buf, len(buf))
buf = mf.read()
Text
The author of pyogg goofed up on python object deletion in the wrapper. This was reported.
Unfortunately libao (0.82) is also affected, and there’s no action even on the previous pyogg bug. It causes a “glibc double-free” on Linux and a “pointer being freed was not allocated” on Mac OS X.
The project seems quite dead, but is merely a wrapper to the C libs where the real action takes place, so there’s not much of a fuss to have it unmaintained.
Here is the patch against pyao:
--- src/aomodule.c.orig 2010-04-07 19:06:45.000000000 +0200
+++ src/aomodule.c 2010-04-07 19:06:56.000000000 +0200
@@ -150,7 +150,7 @@
py_ao_dealloc(ao_Object *self)
{
ao_close(self->dev);
- PyMem_DEL(self);
+ PyObject_DEL(self);
}
static PyObject *
And for reference, the patch against pyogg:
Index: legacy/pyvorbis/pyvorbisfile.c
===================================================================
--- legacy/pyvorbis/pyvorbisfile.c (revision 20)
+++ legacy/pyvorbis/pyvorbisfile.c (working copy)
@@ -173,8 +173,7 @@
if (ret == NULL) {
PyMem_DEL(newobj);
return NULL;
- } else
- Py_DECREF(ret);
+ }
return (PyObject *) newobj;
}
@@ -191,11 +190,13 @@
close */
Py_DECREF(py_self->py_file);
} else {
- /* Otherwise, we opened the file and should close it. */
- fclose(py_self->c_file);
+ /* Do NOT close the file -- ov_open() takes ownership of the FILE*,
+ and ov_close() is responsible for closing it. */
}
- PyMem_DEL(self);
+ free(py_self->ovf);
+
+ PyObject_DEL(self);
}
static PyObject *
Text
Little script to easily uninstall either. Take care to adapt to your needs.
#activepython
sudo rm -R /Library/Frameworks/Python.framework /Applications/Python\ 3.1 /usr/local/bin/{2to3*,py*,idle*}
#activetcl
sudo rm -R /Library/Frameworks/{Tcl,Tk}.framework /Applications/Utilities/Wish\ 8.5.app /usr/local/bin/{tclsh8.5,wish8.5} /Library/Documentation/Help/ActiveTcl-8.5
Text
Lovely command to obtain the processes (or rather, PID) using a socket port (here 23) on AIX:
$ netstat -Aan | egrep '\.23 ' | awk '{print $1}' | \
sed -e 's/^\(.*\)$/sockinfo \1 tcpcb/' | kdb | egrep '^pvproc' | awk '{print $4}' | sort | uniq | \
sed 's/^\(.*\)$/hcal \1/' | kdb | grep Value | awk '{print $6}'
Useful when you don’t have lsof at hand.
Photo reblogged from I wish I had done everything on earth with you with 2 notes
Page 1 of 6