[GRASS-SVN] r35291 - in grass/trunk: . include/Make swig/python

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 8 16:35:50 EST 2009


Author: glynn
Date: 2009-01-08 16:35:50 -0500 (Thu, 08 Jan 2009)
New Revision: 35291

Added:
   grass/trunk/include/Make/Python.make
   grass/trunk/swig/python/date.i
   grass/trunk/swig/python/utils.i
Removed:
   grass/trunk/swig/python/renames.i
Modified:
   grass/trunk/Makefile
   grass/trunk/include/Make/Compile.make
   grass/trunk/swig/python/
   grass/trunk/swig/python/Makefile
   grass/trunk/swig/python/__init__.py
   grass/trunk/swig/python/common.i
   grass/trunk/swig/python/display.i
   grass/trunk/swig/python/grass.i
   grass/trunk/swig/python/imagery.i
   grass/trunk/swig/python/math.i
   grass/trunk/swig/python/my_typemaps.i
   grass/trunk/swig/python/proj.i
   grass/trunk/swig/python/raster.i
   grass/trunk/swig/python/stats.i
   grass/trunk/swig/python/vector.i
Log:
Move Python rules into Python.make
Add per-file compile/link flags
SWIG/Python clean-up, reorganisation


Modified: grass/trunk/Makefile
===================================================================
--- grass/trunk/Makefile	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/Makefile	2009-01-08 21:35:50 UTC (rev 35291)
@@ -52,6 +52,7 @@
 	locale \
 	tools \
 	man \
+	swig \
 	gem \
 	macosx
 

Modified: grass/trunk/include/Make/Compile.make
===================================================================
--- grass/trunk/include/Make/Compile.make	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/include/Make/Compile.make	2009-01-08 21:35:50 UTC (rev 35291)
@@ -17,26 +17,26 @@
 # default cc rules
 ifeq ($(BROKEN_MAKE),)
 
-$(OBJDIR)/%.o : %.c $(LOCAL_HEADERS) $(EXTRA_HEADERS) | $(OBJDIR)
+$(OBJDIR)/%.o : %.c $(LOCAL_HEADERS) $(EXTRA_HEADERS) $($*_c_FLAGS) | $(OBJDIR)
 	$(call compiler_c)
 
-$(OBJDIR)/%.o : %.cc $(LOCAL_HEADERS) $(EXTRA_HEADERS) | $(OBJDIR)
+$(OBJDIR)/%.o : %.cc $(LOCAL_HEADERS) $(EXTRA_HEADERS) $($*_cc_FLAGS) | $(OBJDIR)
 	$(call compiler_cxx)
 
-$(OBJDIR)/%.o : %.cpp $(LOCAL_HEADERS) $(EXTRA_HEADERS) | $(OBJDIR)
+$(OBJDIR)/%.o : %.cpp $(LOCAL_HEADERS) $(EXTRA_HEADERS) $($*_cpp_FLAGS) | $(OBJDIR)
 	$(call compiler_cxx)
 
 else
 
-$(OBJDIR)/%.o : %.c $(LOCAL_HEADERS) $(EXTRA_HEADERS)
+$(OBJDIR)/%.o : %.c $(LOCAL_HEADERS) $(EXTRA_HEADERS) $($*_c_FLAGS)
 	$(MAKE) $(OBJDIR)
 	$(call compiler_c)
 
-$(OBJDIR)/%.o : %.cc $(LOCAL_HEADERS) $(EXTRA_HEADERS)
+$(OBJDIR)/%.o : %.cc $(LOCAL_HEADERS) $(EXTRA_HEADERS) $($*_cc_FLAGS)
 	$(MAKE) $(OBJDIR)
 	$(call compiler_cxx)
 
-$(OBJDIR)/%.o : %.cpp $(LOCAL_HEADERS) $(EXTRA_HEADERS)
+$(OBJDIR)/%.o : %.cpp $(LOCAL_HEADERS) $(EXTRA_HEADERS) $($*_cpp_FLAGS)
 	$(MAKE) $(OBJDIR)
 	$(call compiler_cxx)
 

Added: grass/trunk/include/Make/Python.make
===================================================================
--- grass/trunk/include/Make/Python.make	                        (rev 0)
+++ grass/trunk/include/Make/Python.make	2009-01-08 21:35:50 UTC (rev 35291)
@@ -0,0 +1,14 @@
+
+PYTHON = python
+PYMOD_LD = $(SHLIB_LD)
+PYMOD_LDFLAGS = $(SHLIB_LDFLAGS) -L$(ARCH_LIBDIR) $(PYTHONLDFLAGS)
+PYMOD_CFLAGS = $(SHLIB_CFLAGS) $(PYTHONINC) $(PYTHON_CFLAGS)
+
+%.pyc: %.py
+	$(PYTHON) -m py_compile $<
+
+%_wrap.c %.py: %.i $(EXTRA_SWIG)
+	$(SWIG) $(ARCH_INC) -python -module $* -shadow $<
+
+_%.so: $(OBJDIR)/%_wrap.o $(_%_so_FILES)
+	$(PYMOD_LD) -o $@ $(LDFLAGS) $(EXTRA_LDFLAGS) $(PYMOD_LDFLAGS) $(filter %.o,$^) $($*_LIBS) $(LIBES) $(EXTRA_LIBS)


Property changes on: grass/trunk/swig/python
___________________________________________________________________
Name: svn:ignore
   - _python_grass7.so
python_grass7.py
python_grass7.pyc
python_grass7_wrap.c

   + *OBJ.*
_*.so
*.py
*.pyc
*_wrap.c


Modified: grass/trunk/swig/python/Makefile
===================================================================
--- grass/trunk/swig/python/Makefile	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/Makefile	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,72 +1,78 @@
 MODULE_TOPDIR = ../..
 
-include $(MODULE_TOPDIR)/include/Make/Lib.make
+PACKAGE = "grasslibs"
+
+include $(MODULE_TOPDIR)/include/Make/Other.make
+include $(MODULE_TOPDIR)/include/Make/Compile.make
 include $(MODULE_TOPDIR)/include/Make/Doxygen.make
 
-CFLAGS=-c -fpic -I. $(ARCH_INC) $(GDALCFLAGS) $(PYTHONCFLAGS)
-LDFLAGS=-shared -L$(ARCH_LIBDIR) $(GDALLIBS) $(PYTHONLDFLAGS)
+# doxygen:
+DOXNAME=
+DOXINPUT=grasspython.dox
 
-MODULES = grass math imagery vector proj raster display stats
+MODULES = utils date grass math proj imagery vector raster display stats
 
-vector_LIBS = $(VECTLIB)
+date_LIBS    = $(DATETIMELIB)
+grass_LIBS   = $(GISLIB)
+math_LIBS    = $(GMATHLIB)
+proj_LIBS    = $(GPROJLIB)
 imagery_LIBS = $(IMAGERYLIB)
-grass_LIBS = $(GISLIB)
-math_LIBS = $(GMATHLIB)
-proj_LIBS = $(GPROJLIB)
-raster_LIBS = $(RASTERLIB)
+vector_LIBS  = $(VECTLIB)
+raster_LIBS  = $(RASTERLIB)
 display_LIBS = $(DISPLAYLIB)
-stats_LIBS = $(STATSLIB)
+stats_LIBS   = $(STATSLIB)
 
+vector_wrap_c_FLAGS = $(VECT_INC)
+proj_wrap_c_FLAGS = $(PROJINC) $(GDALCFLAGS)
+
+EXTRA_SWIG = my_typemaps.i common.i
+EXTRA_CFLAGS = $(PYMOD_CFLAGS)
 EXTRA_CLEAN_FILES := $(foreach M,$(MODULES),$(M)_wrap.o $(M)_wrap.c $(M).pyc $(M).py)
 CLEAN_SUBDIRS = NumPtr
 
+include $(MODULE_TOPDIR)/include/Make/Python.make
+
 DSTDIR = $(ARCH_DISTDIR)/etc/python/swig
 
 LIBFILES := $(patsubst %,$(DSTDIR)/_%.so,$(MODULES))
-PYFILES  := $(patsubst %,$(DSTDIR)/%.py,$(MODULES))
-PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES))
+PYFILES  := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
+PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)
 
-default: $(LIBFILES) $(PYFILES) $(DSTDIR)/__init__.pyc numptr
+default:
+	$(MAKE) $(DSTDIR)
+	$(MAKE) $(LIBFILES) $(PYFILES) $(PYCFILES)
 
-%_wrap.c %.py: %.i my_typemaps.i renames.i common.i
-	$(SWIG) $(ARCH_INC) -python -shadow $<
+$(DSTDIR):
+	test -d $@ || $(MKDIR) -p $@
 
-$(OBJDIR)/%_wrap.o: %_wrap.c
-	test -d $(OBJDIR) || $(MKDIR) -p $(OBJDIR)
-	$(CC) $(CFLAGS) $(INCLUDE_DIRS) -o $@ $<
+$(DSTDIR)/_%.so: _%.so
+	$(INSTALL) $< $@
 
-$(DSTDIR)/_%.so: $(OBJDIR)/%_wrap.o
-	test -d $(DSTDIR) || $(MKDIR) -p $(DSTDIR)
-	$(SHLIB_LD) -o $@ $(LDFLAGS) $^ $($*_LIBS)
-
 $(DSTDIR)/%.py: %.py
-	test -d $(DSTDIR) || $(MKDIR) -p $(DSTDIR)
 	$(INSTALL_DATA) $< $@
 
-$(DSTDIR)/%.pyc: $(DSTDIR)/%.py $(DSTDIR)/_%.so
-	cd $(DSTDIR) && echo "import $*" | python; true
+$(DSTDIR)/%.pyc: %.pyc
+	$(INSTALL_DATA) $< $@
 
-$(DSTDIR)/__init__.pyc: $(DSTDIR)/__init__.py $(LIBFILES) $(PYCFILES)
-	cd $(DSTDIR) && echo "import __init__" | python; true
-
 numptr:
 	$(MAKE) -C NumPtr
 
 .PHONY: numptr
 
-# doxygen:
-DOXNAME=
-DOXINPUT=grasspython.dox
+.KEEP: $(patsubst %,$(OBJDIR)/%_wrap.o,$(MODULES))
 
-display_wrap.c: $(ARCH_INCDIR)/display.h
+date_wrap.c: $(ARCH_INCDIR)/datetime.h
+date_wrap.c: $(ARCH_INCDIR)/P_datetime.h
 grass_wrap.c: $(ARCH_INCDIR)/gis.h
 grass_wrap.c: $(ARCH_INCDIR)/gisdefs.h
+math_wrap.c: $(ARCH_INCDIR)/gmath.h
+proj_wrap.c: $(ARCH_INCDIR)/gprojects.h
 imagery_wrap.c: $(ARCH_INCDIR)/imagedefs.h
 imagery_wrap.c: $(ARCH_INCDIR)/imagery.h
-math_wrap.c: $(ARCH_INCDIR)/gmath.h
-proj_wrap.c: $(ARCH_INCDIR)/gprojects.h
-raster_wrap.c: $(ARCH_INCDIR)/raster.h
-stats_wrap.c: $(ARCH_INCDIR)/stats.h
 vector_wrap.c: $(ARCH_INCDIR)/Vect.h
 vector_wrap.c: $(ARCH_INCDIR)/vect/dig_defines.h
 vector_wrap.c: $(ARCH_INCDIR)/vect/dig_structs.h
+raster_wrap.c: $(ARCH_INCDIR)/raster.h
+display_wrap.c: $(ARCH_INCDIR)/display.h
+stats_wrap.c: $(ARCH_INCDIR)/stats.h
+utils_wrap.c:

Modified: grass/trunk/swig/python/__init__.py
===================================================================
--- grass/trunk/swig/python/__init__.py	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/__init__.py	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,3 +1,4 @@
+import date
 import grass
 import math
 import imagery
@@ -6,3 +7,4 @@
 import stats
 import raster
 import display
+import utils

Modified: grass/trunk/swig/python/common.i
===================================================================
--- grass/trunk/swig/python/common.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/common.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -3,5 +3,9 @@
 #include <grass/gis.h>
 %}
 
+%rename(my_def) def;
+//%rename(my_class) class;
+
+%include "file.i"
+
 %include "my_typemaps.i"
-%include "renames.i"

Added: grass/trunk/swig/python/date.i
===================================================================
--- grass/trunk/swig/python/date.i	                        (rev 0)
+++ grass/trunk/swig/python/date.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -0,0 +1,9 @@
+
+%include "common.i"
+
+%{
+#include <grass/datetime.h>
+%}
+
+%include "grass/datetime.h"
+%include "grass/P_datetime.h"

Modified: grass/trunk/swig/python/display.i
===================================================================
--- grass/trunk/swig/python/display.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/display.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,4 +1,3 @@
-%module display
 
 %include "common.i"
 

Modified: grass/trunk/swig/python/grass.i
===================================================================
--- grass/trunk/swig/python/grass.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/grass.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,22 +1,31 @@
-%module grass
 
 %include "common.i"
 
-%include "carrays.i"
-%array_functions(int, intArray);
-%array_functions(float, floatArray);
-%array_functions(double, doubleArray);
-
-%include "cpointer.i"
-%pointer_functions(int, intp);
-%pointer_functions(float, floatp);
-%pointer_functions(double, doublep);
-
 %include "grass/gis.h"
 %include "grass/gisdefs.h"
 
 %pythoncode %{
+import sys
+
 def G_gisinit(pgm):
-    G__gisinit(GIS_H_VERSION, pgm)
+	G__gisinit(GIS_H_VERSION, pgm)
 
+def G__get_trace():
+	f = sys._getframe(1)
+	ln = f.f_lineno
+	fi = f.f_code.co_filename
+	return fi, ln
+
+def G_malloc(n):
+	fi, ln = G__get_trace()
+	return G__malloc(fi, ln, n)
+
+def G_calloc(m, n):
+	fi, ln = G__get_trace()
+	return G__calloc(fi, ln, m, n)
+
+def G_realloc(p, n):
+	fi, ln = G__get_trace()
+	return G__realloc(fi, ln, p, n)
 %}
+

Modified: grass/trunk/swig/python/imagery.i
===================================================================
--- grass/trunk/swig/python/imagery.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/imagery.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,10 +1,8 @@
-%module imagery
 
 %include "common.i"
 
 %{
 #include <grass/imagery.h>
-#include <grass/imagedefs.h>
 %}
 
 %include "grass/imagery.h"

Modified: grass/trunk/swig/python/math.i
===================================================================
--- grass/trunk/swig/python/math.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/math.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,4 +1,3 @@
-%module math
 
 %include "common.i"
 

Modified: grass/trunk/swig/python/my_typemaps.i
===================================================================
--- grass/trunk/swig/python/my_typemaps.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/my_typemaps.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,4 +1,5 @@
 #ifdef SWIGPYTHON
+
 %typemap(in) string_allows_none {
 	if($input==Py_None) {
 		$1=NULL;
@@ -38,77 +39,136 @@
 //		G_free_list($1);
 	}
 }
-%typemap(in,numinputs=0) return_string (char * temp) {
-	temp=NULL;
-	$1=&temp;
+
+%typemap(argout) return_string (char * temp) {
+	if($1 && *$1) {
+		$result=t_output_helper($result,PyString_FromString(*$1));
+		G_free(*$1);
+	} else {
+		$result=t_output_helper($result,Py_None);
+		Py_INCREF(Py_None);
+	}
+	
 }
 
+%inline %{
+typedef char ** return_string;
+%}
 
-%typemap(argout) CELL * {
-		int len=0,i;
-		len=G_window_cols();
-		$result=PyList_New(len);
-                for(i=0;i<len;i++)
-                {
-                  PyList_SetItem($result,i,PyInt_FromLong($1[i]));
-                }
-}
+#undef __attribute__
+#define __attribute__(x)
 
-%typemap(argout) FCELL * {
-		int len=0,i;
-		len=G_window_cols();
-                $result=PyList_New(len);
-                for(i=0;i<len;i++)
-                {
-                  PyList_SetItem($result,i,PyFloat_FromDouble($1[i]) );
-                }                
-}
+%{
 
-%typemap(argout) DCELL * {
-		int len=0,i;
-		len=G_window_cols();
-		$result=PyList_New(len);
-                for(i=0;i<len;i++)
-                {
-                  PyList_SetItem($result,i,PyFloat_FromDouble($1[i]));
-                }                
+static void *pyseq_to_ptr(PyObject *input, int data_type) __attribute__ ((unused));
+static void *pyobj_to_ptr(PyObject *input, int data_type) __attribute__ ((unused));
+
+static void *pyseq_to_ptr(PyObject *input, int data_type)
+{
+	size_t size;
+	Py_ssize_t len;
+	void *array;
+	int i;
+
+	if (!PySequence_Check(input)) {
+		PyErr_SetString(PyExc_ValueError,"Expected a CObject, buffer or sequence");
+		return NULL;
+	}
+
+	switch (data_type) {
+	case (int) 'c':	size = sizeof(char		);	break;
+	case (int) 'b':	size = sizeof(signed char 	);	break;
+	case (int) 'B':	size = sizeof(unsigned char 	);	break;
+	case (int) 'u':	size = sizeof(Py_UNICODE 	);	break;
+	case (int) 'h':	size = sizeof(signed short 	);	break;
+	case (int) 'H':	size = sizeof(unsigned short 	);	break;
+	case (int) 'i':	size = sizeof(signed int 	);	break;
+	case (int) 'I':	size = sizeof(unsigned int 	);	break;
+	case (int) 'l':	size = sizeof(signed long 	);	break;
+	case (int) 'L':	size = sizeof(unsigned long 	);	break;
+	case (int) 'f':	size = sizeof(float		);	break;
+	case (int) 'd':	size = sizeof(double		);	break;
+	default:
+		PyErr_SetString(PyExc_ValueError,"Invalid type code; must be one of [cbBuhHiIlLfd]");
+		return NULL;
+	}
+
+	len = PySequence_Length(input);
+	array = malloc(len * size);
+
+	fprintf(stderr, "sequence length is %d\n", len);
+
+	for (i = 0; i < len; i++) {
+		PyObject *val = PySequence_GetItem(input, i);
+		DCELL n;
+
+		if (!PyNumber_Check(val)) {
+			PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");
+			Py_XDECREF(val);
+			return NULL;
+		}
+
+		n = PyFloat_AsDouble(val);
+		if (PyErr_Occurred()) {
+			PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");
+			Py_XDECREF(val);
+			return NULL;
+		}
+
+		Py_DECREF(val);
+
+		switch (data_type) {
+		case (int) 'c': ((char		*) array)[i] = (char		) n;	break;
+		case (int) 'b': ((signed char	*) array)[i] = (signed char	) n;	break;
+		case (int) 'B': ((unsigned char	*) array)[i] = (unsigned char	) n;	break;
+		case (int) 'u': ((Py_UNICODE	*) array)[i] = (Py_UNICODE	) n;	break;
+		case (int) 'h': ((signed short	*) array)[i] = (signed short	) n;	break;
+		case (int) 'H': ((unsigned short*) array)[i] = (unsigned short	) n;	break;
+		case (int) 'i': ((signed int	*) array)[i] = (signed int	) n;	break;
+		case (int) 'I': ((unsigned int	*) array)[i] = (unsigned int	) n;	break;
+		case (int) 'l': ((signed long	*) array)[i] = (signed long	) n;	break;
+		case (int) 'L': ((unsigned long	*) array)[i] = (unsigned long	) n;	break;
+		case (int) 'f': ((float		*) array)[i] = (float		) n;	break;
+		case (int) 'd': ((double	*) array)[i] = (double		) n;	break;
+		default:
+		    PyErr_SetString(PyExc_ValueError,"Invalid type code; must be one of [cbBuhHiIlLfd]");
+		    return NULL;
+		}
+	}
+
+	return array;
 }
 
+static void *pyobj_to_ptr(PyObject *input, int data_type)
+{
+	const void *cbuffer;
+	void *buffer;
+	Py_ssize_t len;
 
-%typemap(in)CELL  * {
-		int len=0,i=0; CELL *tmp;
-		PyObject obj;
-		len=G_window_cols();
-		$1=G_allocate_cell_buf();
+	if (PyCObject_Check(input))
+		return PyCObject_AsVoidPtr(input);
+
+	if (PyObject_AsWriteBuffer(input, &buffer, &len) == 0)
+		return buffer;
+
+	if (PyObject_AsReadBuffer(input, &cbuffer, &len) == 0)
+		return (void *) cbuffer;
+
+	return pyseq_to_ptr(input, data_type);
 }
 
-%typemap(in)FCELL  * {
-		int len=0,i=0; FCELL *tmp;
-		PyObject obj;
-		len=G_window_cols();
-		$1=G_allocate_f_raster_buf();
+%}
+
+%typemap(in) CELL * {
+	$1 = (CELL *) pyobj_to_ptr($input, 'i');
 }
 
-%typemap(in)DCELL  * {
-		int len=0,i=0; FCELL *tmp;
-		PyObject obj;
-		len=G_window_cols();
-		$1=G_allocate_d_raster_buf();
+%typemap(in) FCELL * {
+	$1 = (FCELL *) pyobj_to_ptr($input, 'f');
 }
 
-
-%typemap(argout) return_string (char * temp) {
-	if($1 && *$1) {
-		$result=t_output_helper($result,PyString_FromString(*$1));
-		G_free(*$1);
-	} else {
-		$result=t_output_helper($result,Py_None);
-		Py_INCREF(Py_None);
-	}
-	
+%typemap(in) DCELL * {
+	$1 = (DCELL *) pyobj_to_ptr($input, 'd');
 }
 
-%inline %{
-typedef char ** return_string;
-%}
 #endif

Modified: grass/trunk/swig/python/proj.i
===================================================================
--- grass/trunk/swig/python/proj.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/proj.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,4 +1,3 @@
-%module proj
 
 %include "common.i"
 

Modified: grass/trunk/swig/python/raster.i
===================================================================
--- grass/trunk/swig/python/raster.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/raster.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,4 +1,3 @@
-%module raster
 
 %include "common.i"
 

Deleted: grass/trunk/swig/python/renames.i
===================================================================
--- grass/trunk/swig/python/renames.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/renames.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,2 +0,0 @@
-%rename(my_def) def;
-%rename(my_class) class;

Modified: grass/trunk/swig/python/stats.i
===================================================================
--- grass/trunk/swig/python/stats.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/stats.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,4 +1,3 @@
-%module stats
 
 %include "common.i"
 

Added: grass/trunk/swig/python/utils.i
===================================================================
--- grass/trunk/swig/python/utils.i	                        (rev 0)
+++ grass/trunk/swig/python/utils.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -0,0 +1,72 @@
+
+%include "common.i"
+
+%include "carrays.i"
+%array_functions(int, intArray);
+%array_functions(float, floatArray);
+%array_functions(double, doubleArray);
+
+%include "cpointer.i"
+%pointer_functions(int, intp);
+%pointer_functions(float, floatp);
+%pointer_functions(double, doublep);
+
+PyObject *ptr_to_cobj(void *p);
+void *cobj_to_ptr(PyObject *o);
+PyObject *ptr_to_buffer_const(const void *p, int size);
+PyObject *ptr_to_buffer(void *p, int size);
+const void *buffer_to_ptr_const(PyObject *o);
+void *buffer_to_ptr(PyObject *o);
+
+%{
+
+static PyObject *ptr_to_cobj(void *p)
+{
+	return PyCObject_FromVoidPtr(p, NULL);
+}
+
+static void *cobj_to_ptr(PyObject *o)
+{
+	if (PyCObject_Check(o))
+		return PyCObject_AsVoidPtr(o);
+
+	PyErr_SetString(PyExc_ValueError,"CObject Expected");
+	return NULL;
+}
+
+static PyObject *ptr_to_buffer_const(const void *p, int size)
+{
+	return PyBuffer_FromMemory((void *) p, size);
+}
+
+static PyObject *ptr_to_buffer(void *p, int size)
+{
+	return PyBuffer_FromReadWriteMemory(p, size);
+}
+
+static const void *buffer_to_ptr_const(PyObject *o)
+{
+	const void *p;
+	Py_ssize_t len;
+
+	if (PyObject_AsReadBuffer(o, &p, &len) == 0)
+		return p;
+
+	PyErr_SetString(PyExc_ValueError,"buffer object expected");
+	return NULL;
+}
+
+static void *buffer_to_ptr(PyObject *o)
+{
+	void *p;
+	Py_ssize_t len;
+	
+	if (PyObject_AsWriteBuffer(o, &p, &len) == 0)
+		return p;
+
+	PyErr_SetString(PyExc_ValueError,"buffer object expected");
+	return NULL;
+}
+
+%}
+

Modified: grass/trunk/swig/python/vector.i
===================================================================
--- grass/trunk/swig/python/vector.i	2009-01-08 16:20:28 UTC (rev 35290)
+++ grass/trunk/swig/python/vector.i	2009-01-08 21:35:50 UTC (rev 35291)
@@ -1,4 +1,3 @@
-%module vector
 
 %include "common.i"
 



More information about the grass-commit mailing list