Skip to content

Commit 34214c3

Browse files
committed
use PyGILState_\*() functionality (enabled with PY_USE_GIL)
git-svn-id: https://svn.grrrr.org/ext/py/trunk@2370 4d9ac71a-51e6-0310-8455-cad1006bcd31
1 parent 4016118 commit 34214c3

28 files changed

+2708
-2641
lines changed

build/config-lnx.def

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ PYTHONVERSION=2.4
99
PY_NUMPY=1
1010
# PY_NUMARRAY=1
1111
# PY_NUMERIC=1
12+
13+
# use thread-safe GIL functionality (do this for python version >= 2.3!)
14+
PY_USE_GIL=1

build/config-mac.def

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
PY_NUMPY=1
44
# PY_NUMARRAY=1
55
# PY_NUMERIC=1
6+
7+
# use thread-safe GIL functionality (do this for python version >= 2.3!)
8+
PY_USE_GIL=1

build/config-win.def

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ PYTHONPATH=%programfiles%/python$(PYTHONVER)
99
PY_NUMPY=1
1010
# PY_NUMARRAY=1
1111
# PY_NUMERIC=1
12+
13+
# use thread-safe GIL functionality (do this for python version >= 2.3!)
14+
PY_USE_GIL=1

build/gnumake-lnx-gcc.inc

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ ifdef PY_NUMERIC
1212
DEFS += -DPY_NUMERIC
1313
endif
1414

15+
ifdef PY_USE_GIL
16+
DEFS += -DPY_USE_GIL
17+
endif

build/gnumake-mac-gcc.inc

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ ifdef PY_NUMERIC
1212
DEFS += -DPY_NUMERIC
1313
endif
1414

15+
ifdef PY_USE_GIL
16+
DEFS += -DPY_USE_GIL
17+
endif

build/gnumake-win-cygwin.inc

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ ifdef PY_NUMERIC
1313
DEFS += -DPY_NUMERIC
1414
endif
1515

16+
ifdef PY_USE_GIL
17+
DEFS += -DPY_USE_GIL
18+
endif

build/nmake-win-msvc.inc

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ DEFS = $(DEFS) /DPY_NUMPY
1414
DEFS = $(DEFS) /DPY_NUMERIC
1515
!endif
1616

17+
!ifdef PY_USE_GIL
18+
DEFS = $(DEFS) /DPY_USE_GIL
19+
!endif

package.txt

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
NAME=py
2-
3-
BUILDTYPE=multi
4-
BUILDDIR=build
5-
6-
SRCDIR=source
7-
PRECOMPILE=pyprefix.h
8-
9-
SRCS= \
10-
main.cpp \
11-
py.cpp pyext.cpp modmeth.cpp clmeth.cpp \
12-
register.cpp bound.cpp pyargs.cpp \
13-
pysymbol.cpp pybuffer.cpp pybundle.cpp pydsp.cpp \
14-
pyatom.cpp pybase.cpp pymeth.cpp
15-
16-
HDRS= pyprefix.h main.h pyext.h pysymbol.h pybuffer.h pybundle.h pyatom.h pybase.h
1+
NAME=py
2+
3+
BUILDTYPE=multi
4+
BUILDDIR=build
5+
6+
SRCDIR=source
7+
PRECOMPILE=pyprefix.h
8+
9+
SRCS= \
10+
main.cpp \
11+
py.cpp pyext.cpp modmeth.cpp clmeth.cpp \
12+
register.cpp bound.cpp pyargs.cpp \
13+
pysymbol.cpp pybuffer.cpp pybundle.cpp pydsp.cpp \
14+
pyatom.cpp pybase.cpp pymeth.cpp
15+
16+
HDRS= pyprefix.h main.h pyext.h pysymbol.h pybuffer.h pybundle.h pyatom.h pybase.h

py.xcodeproj/project.pbxproj

+12-2
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,12 @@
578578
isa = XCBuildConfiguration;
579579
buildSettings = {
580580
GCC_OPTIMIZATION_LEVEL = 0;
581-
GCC_PREPROCESSOR_DEFINITIONS = PY_NUMPY;
581+
GCC_PREPROCESSOR_DEFINITIONS = (
582+
"$(inherited)",
583+
_DEBUG,
584+
PY_NUMPY,
585+
PY_USE_GIL,
586+
);
582587
HEADER_SEARCH_PATHS = "/Library/Python/2.3/site-packages/numpy/core/include/";
583588
};
584589
name = Development;
@@ -591,7 +596,12 @@
591596
ppc,
592597
);
593598
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
594-
GCC_PREPROCESSOR_DEFINITIONS = PY_NUMPY;
599+
GCC_PREPROCESSOR_DEFINITIONS = (
600+
"$(inherited)",
601+
NDEBUG,
602+
PY_NUMPY,
603+
PY_USE_GIL,
604+
);
595605
HEADER_SEARCH_PATHS = "/Library/Python/2.3/site-packages/numpy/core/include/";
596606
};
597607
name = Deployment;

readme.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
py/pyext - python script objects for PD and Max/MSP
22

3-
Copyright (c)2002-2006 Thomas Grill (gr@grrrr.org)
3+
Copyright (c)2002-2007 Thomas Grill (gr@grrrr.org)
44
For information on usage and redistribution, and for a DISCLAIMER OF ALL
55
WARRANTIES, see the file, "license.txt," in this distribution.
66

@@ -16,8 +16,9 @@ For OS X keep things as the are - it has Python installed by default.
1616

1717

1818
The py/pyext package should run with Python version >= 2.1.
19-
It has been thoroughly tested with versions 2.2 to 2.4
19+
It has been thoroughly tested with versions 2.2 to 2.5
2020

21+
The default build setting using PY_USE_GIL requires Python version >= 2.3.
2122

2223
Check out the sample patches and scripts
2324

@@ -47,7 +48,6 @@ Known bugs:
4748
- With standard PD 0.37, threaded py scripts will cause "Stack overflows" under some circumstances
4849
-> use PD 0.38 or the devel_0_37 cvs branch instead
4950
- It has been reported that pyext crashes on AMD64 with SSE enabled (for these CPUs, disable the respective compiler flags)
50-
- Threading in pyext obviously crashes under linux with Python version 2.4.2 (only)
5151

5252
----------------------------------------------------------------------------
5353

@@ -120,6 +120,7 @@ Version history:
120120
- ADD: py.Bundle class to support flext message bundles
121121
- ADD: enable usage of compiled-only modules (.py[co])
122122
- ADD: enable usage of module packages (with module/__init__.py[co])
123+
- ADD: make use of the PyGILState_*() functions
123124

124125
0.2.0:
125126
- ADD: handling of Python threads

scripts/buffer.py

+60-60
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
# py/pyext - python script objects for PD and MaxMSP
2-
#
3-
# Copyright (c) 2002-2005 Thomas Grill (gr@grrrr.org)
4-
# For information on usage and redistribution, and for a DISCLAIMER OF ALL
5-
# WARRANTIES, see the file, "license.txt," in this distribution.
6-
#
7-
8-
"""This is an example script for the py/pyext object's buffer support.
9-
10-
PD/Max buffers can be mapped to Python arrays.
11-
Currently, there are three implementations:
12-
Numeric, numarray and Numeric3 (for all of them see http://numeric.scipy.org)
13-
"""
14-
15-
import sys
16-
17-
try:
18-
import pyext
19-
except:
20-
print "ERROR: This script must be loaded by the PD/Max py/pyext external"
21-
22-
try:
23-
from numarray import *
24-
except:
25-
print "Failed importing numarray module:",sys.exc_value
26-
27-
def mul(*args):
28-
# create buffer objects
29-
# as long as these variables live the underlying buffers are locked
30-
c = pyext.Buffer(args[0])
31-
a = pyext.Buffer(args[1])
32-
b = pyext.Buffer(args[2])
33-
34-
# slicing causes Python arrays (mapped to buffers) to be created
35-
# note the c[:] - to assign contents you must assign to a slice of the buffer
36-
c[:] = a[:]*b[:]
37-
38-
def add(*args):
39-
c = pyext.Buffer(args[0])
40-
a = pyext.Buffer(args[1])
41-
b = pyext.Buffer(args[2])
42-
43-
# this is also possible, but is probably slower
44-
# the + converts a into a Python array, the argument b is taken as a sequence
45-
# depending on the implementation this may be as fast
46-
# as above or not
47-
c[:] = a+b
48-
49-
def fadein(target):
50-
a = pyext.Buffer(target)
51-
# in place operations are ok
52-
a *= arange(len(a),type=Float32)/len(a)
53-
54-
def neg(target):
55-
a = pyext.Buffer(target)
56-
# in place transformation (see Python array ufuncs)
57-
negative(a[:],a[:])
58-
# must mark buffer content as dirty to update graph
59-
# (no explicit assignment occurred)
60-
a.dirty()
1+
# py/pyext - python script objects for PD and MaxMSP
2+
#
3+
# Copyright (c) 2002-2005 Thomas Grill (gr@grrrr.org)
4+
# For information on usage and redistribution, and for a DISCLAIMER OF ALL
5+
# WARRANTIES, see the file, "license.txt," in this distribution.
6+
#
7+
8+
"""This is an example script for the py/pyext object's buffer support.
9+
10+
PD/Max buffers can be mapped to Python arrays.
11+
Currently, there are three implementations:
12+
Numeric, numarray and Numeric3 (for all of them see http://numeric.scipy.org)
13+
"""
14+
15+
import sys
16+
17+
try:
18+
import pyext
19+
except:
20+
print "ERROR: This script must be loaded by the PD/Max py/pyext external"
21+
22+
try:
23+
from numarray import *
24+
except:
25+
print "Failed importing numarray module:",sys.exc_value
26+
27+
def mul(*args):
28+
# create buffer objects
29+
# as long as these variables live the underlying buffers are locked
30+
c = pyext.Buffer(args[0])
31+
a = pyext.Buffer(args[1])
32+
b = pyext.Buffer(args[2])
33+
34+
# slicing causes Python arrays (mapped to buffers) to be created
35+
# note the c[:] - to assign contents you must assign to a slice of the buffer
36+
c[:] = a[:]*b[:]
37+
38+
def add(*args):
39+
c = pyext.Buffer(args[0])
40+
a = pyext.Buffer(args[1])
41+
b = pyext.Buffer(args[2])
42+
43+
# this is also possible, but is probably slower
44+
# the + converts a into a Python array, the argument b is taken as a sequence
45+
# depending on the implementation this may be as fast
46+
# as above or not
47+
c[:] = a+b
48+
49+
def fadein(target):
50+
a = pyext.Buffer(target)
51+
# in place operations are ok
52+
a *= arange(len(a),type=Float32)/len(a)
53+
54+
def neg(target):
55+
a = pyext.Buffer(target)
56+
# in place transformation (see Python array ufuncs)
57+
negative(a[:],a[:])
58+
# must mark buffer content as dirty to update graph
59+
# (no explicit assignment occurred)
60+
a.dirty()

0 commit comments

Comments
 (0)