first rough cut at resurrecting the swig wrappers

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4989 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2001-07-25 02:00:55 +00:00
parent df40ad1b7e
commit b32debe906
6 changed files with 257 additions and 0 deletions

View File

@ -0,0 +1,10 @@
Makefile
.deps
.libs
*.lo
*.la
gnucash.engine.i
gnucash-engine-perl5_wrap.c
gnucash-engine-perl5_wrap_int.c
gnucash.engine_wrap.doc
gnucash.pm

View File

@ -0,0 +1,121 @@
SWIG = swig
docdir = ${GNC_DOC_INSTALL_DIR}
doc_DATA = \
gnucash.engine_wrap.doc
perlsharedir = ${GNC_SHAREDIR}/perl
perlshare_DATA = gnucash.pm
perllibdir = ${GNC_LIBDIR}/perl
perllib_LTLIBRARIES = libgncswig.la
libgncswig_la_SOURCES = \
helperfuncs.c \
gnucash-engine-perl5_wrap.c
libgncswig_la_LDFLAGS = -version-info 1:1:1
noinst_HEADERS = \
helperfuncs.h
EXTRA_DIST = \
.cvsignore \
examples/scan-acct.pl \
perl5_swig_annotations.i \
gnucash-swig-defines.c
CFLAGS = @CFLAGS@ -Dbool=char
#
# technically, the engine is independent of the gnome libs, however,
# we need to specify the inlcude path for glibconfig.h, and so this is the way
INCLUDES = \
-I@PERLINCL@/CORE \
${GNOME_INCLUDEDIR} \
-I${top_srcdir}/src/engine
libgncswig_la_LIBADD = \
@GLIB_LIBS@ \
${top_srcdir}/src/engine/Account.lo \
${top_srcdir}/src/engine/DateUtils.lo \
${top_srcdir}/src/engine/GNCId.lo \
${top_srcdir}/src/engine/Group.lo \
${top_srcdir}/src/engine/Query.lo \
${top_srcdir}/src/engine/Queue.lo \
${top_srcdir}/src/engine/Scrub.lo \
${top_srcdir}/src/engine/TransLog.lo \
${top_srcdir}/src/engine/Transaction.lo \
${top_srcdir}/src/engine/date.lo \
${top_srcdir}/src/engine/util.lo \
${top_srcdir}/src/engine/gnc-book.lo \
${top_srcdir}/src/engine/guid.lo \
${top_srcdir}/src/engine/md5.lo
SWIG_INPUT_HDRS := \
${top_srcdir}/src/engine/Account.h \
${top_srcdir}/src/engine/DateUtils.h \
${top_srcdir}/src/engine/GNCId.h \
${top_srcdir}/src/engine/Group.h \
${top_srcdir}/src/engine/Query.h \
${top_srcdir}/src/engine/Queue.h \
${top_srcdir}/src/engine/Scrub.h \
${top_srcdir}/src/engine/TransLog.h \
${top_srcdir}/src/engine/Transaction.h \
${top_srcdir}/src/engine/date.h \
${top_srcdir}/src/engine/gnc-book.h
## This is kinda ugly, but swig insists that the .so file be named the
## same as the .pm file, and automake won't tolerate libraries that
## aren't named lib*.so...
install-data-local: libgncswig.la
cd ${DESTDIR}${perllibdir} && rm -f gnucash.so
if [ -f ${DESTDIR}${perllibdir}/libgncswig.so ]; then \
cd ${DESTDIR}${perllibdir} && ln -s libgncswig.so gnucash.so; \
elif [ -f ${DESTDIR}${perllibdir}/libgncswig.so.1.1 ]; then \
cd ${DESTDIR}${perllibdir} && \
ln -s libgncswig.so.1.1 gnucash.so; \
else \
echo "Can't find libgncswig shared library!" \
exit 1; \
fi
uninstall-local:
rm -f ${DESTDIR}${perllibdir}/gnucash.so
gnucash.engine.i: ${SWIG_INPUT_HDRS} perl5_swig_annotations.i
@echo Making $@.
@echo "%module gnucash" > $@
@echo "%include perl5_swig_annotations.i" >> $@
@echo "%{" >> $@
@for file in ${SWIG_INPUT_HDRS}; \
do \
echo "#include <`basename $$file`>" >> $@; \
done
@echo "%}" >> $@
@for file in ${SWIG_INPUT_HDRS}; \
do \
echo "%include `basename $$file`" >> $@; \
done
CLEANFILES += gnucash.engine.i
gnucash.engine_wrap.doc gnucash-engine-perl5_wrap_int.c: gnucash.engine.i
${SWIG} -perl5 -I.. -I${top_srcdir}/src/engine -o $@ gnucash.engine.i
CLEANFILES += gnucash.engine_wrap.doc gnucash-engine-perl5_wrap_int.c
gnucash-engine-perl5_wrap.c: gnucash-swig-defines.c \
gnucash-engine-perl5_wrap_int.c
cat gnucash-swig-defines.c gnucash-engine-perl5_wrap_int.c > $@
CLEANFILES += gnucash-engine-perl5_wrap.c
CLEANFILES += gnucash.pm gnucash.so
# We have to do this because otherwise automake insists on putting
# these files into the dist tarfile. If there's a a better way,
# by all means, let us know...
dist-hook:
rm -f ${distdir}/gnucash-engine-perl5_wrap.c

20
src/optional/swig/README Normal file
View File

@ -0,0 +1,20 @@
This README needs some serious help.
SWIG is now used only to wrap perl5, and I make no guarantees about
the safety of the resulting interface. It may or may not have large
memory leaks and other problems. Anyone who wants to investigate this
is welcome to. (RLB)
The guile interface is now handled via g-wrap (../../lib/g-wrap). As
far as I know, it is reasonably solid. Anyone who wants to know why I
switched to g-wrap can ask, and I'll explain. Sooner or later I'll
probably generate a FAQ entry, but I want to get this out the door.
Part of the reason has to do with the fact the SWIG's guile interface
leaked memory like a sieve. (RLB)
./examples contains whatever examples we've accumulated to date.
----------------------
TBD:
-- modify configure to check perl paths

View File

@ -0,0 +1,3 @@
#define sv_undef PL_sv_undef
#define sv_yes PL_sv_yes
#define na PL_na

View File

@ -0,0 +1,26 @@
%module gnucash
%include perl5_swig_annotations.i
%{
#include <Account.h>
#include <DateUtils.h>
#include <GNCId.h>
#include <Group.h>
#include <Query.h>
#include <Queue.h>
#include <Scrub.h>
#include <TransLog.h>
#include <Transaction.h>
#include <date.h>
#include <gnc-book.h>
%}
%include Account.h
%include DateUtils.h
%include GNCId.h
%include Group.h
%include Query.h
%include Queue.h
%include Scrub.h
%include TransLog.h
%include Transaction.h
%include date.h
%include "gnc-book.h"

View File

@ -0,0 +1,77 @@
/*
* FILE:
* perl5_swig_annotations.i
*
* FUNCTION:
* clean up various aspects of the gnucash engine interface with
* respect to the SWIG-generated perl bindings. This includes:
* -- handling time_t values as ints
* -- converting C ** arrays to perl arrays
*
* HISTORY:
* Created by Linas Vepstas January 1999
* Copyright (c) 1999 Linas Vepstas
*/
#ifdef DOESNT_WORK_DONT_KNOW_WHY
%apply int {time_t }
#endif /* DOESNT_WORK_DONT_KNOW_WHY */
/* Convert the return values from the function to perl values */
/* specifically, create a new perl scalar and store the int value there */
%typemap(perl5, out) time_t {
$target = newSViv ((IV) *($source));
/*
* An alternate way of writing this code would have been ...
* $target = sv_newmortal ();
* sv_setiv ($target, (IV) $source);
*/
argvi ++;
// printf ("Info: converted return time_t secs to %d \n", (int) SvIV($target));
}
%typemap(perl5, in) time_t *(time_t temp) {
/* Convert function arguments from perl to the C represntation */
/* in particular, convert perl scalar into integer, then cast to time_t */
temp = (time_t) SvIV($source);
$target = &temp;
// printf ("Info: time_t input arg is %ld \n", * ($target));
}
/* --------------------------------------------------------- */
#ifdef DOESNT_WORK_DONT_KNOW_WHY
// well, this sort of works ... it does create an array,
// but it doesn't seem to be an array of SplitPtr,
// which is what we want if we are to have
// foreach $split (@splits) {...}
// Creates a new Perl array and places a Split ** into it
%typemap(perl5,out) Split ** {
AV *myav;
SV **svs;
int i = 0,len = 0;
/* Figure out how many elements we have */
while ($source[len]) len++;
svs = (SV **) malloc(len*sizeof(SV *));
printf ("Info: measured Split array length of len=%d\n", len);
/* fill in array of scalar values */
for (i = 0; i < len ; i++) {
svs[i] = sv_newmortal();
sv_setref_pv (svs[i], "SplitPtr", $source[i]);
};
/* convert array of scalars into perl array */
myav = av_make(len,svs);
free(svs);
// $target = myav;
$target = newRV((SV*)myav);
sv_2mortal($target);
argvi ++;
}
#endif /* DOESNT_WORK_DONT_KNOW_WHY */