Revert rev 11187 "Merged with recent changes from trunk."
This reverts commit c595e4d90ebfd63eb55430c735bb121cf690bd59. Conflicts: Source/Modules/c.cxx From: William S Fulton <wsf@fultondesigns.co.uk> git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13033 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
34a628c7c7
commit
d6b81eb831
703 changed files with 9266 additions and 21128 deletions
22
ANNOUNCE
22
ANNOUNCE
|
|
@ -1,11 +1,11 @@
|
|||
*** ANNOUNCE: SWIG 1.3.40 (in progress) ***
|
||||
*** ANNOUNCE: SWIG 1.3.36 (24 June 2008) ***
|
||||
|
||||
http://www.swig.org
|
||||
|
||||
|
||||
We're pleased to announce SWIG-1.3.40, the latest installment in the
|
||||
SWIG development effort. SWIG-1.3.40 includes a number of bug fixes
|
||||
and enhancements.
|
||||
We're pleased to announce SWIG-1.3.36, the latest installment in the
|
||||
SWIG development effort. SWIG-1.3.36 includes a number of bug fixes
|
||||
and large number of enhancements throughout.
|
||||
|
||||
What is SWIG?
|
||||
-------------
|
||||
|
|
@ -24,11 +24,21 @@ Availability:
|
|||
-------------
|
||||
The release is available for download on Sourceforge at
|
||||
|
||||
http://prdownloads.sourceforge.net/swig/swig-1.3.40.tar.gz
|
||||
http://prdownloads.sourceforge.net/swig/swig-1.3.36.tar.gz
|
||||
|
||||
A Windows version is also available at
|
||||
|
||||
http://prdownloads.sourceforge.net/swig/swigwin-1.3.40.zip
|
||||
http://prdownloads.sourceforge.net/swig/swigwin-1.3.36.zip
|
||||
|
||||
Release numbers
|
||||
---------------
|
||||
With SWIG-1.3, we are adopting an odd/even version numbering scheme for
|
||||
SWIG. Odd version numbers (1.3, 1.5, 1.7, etc...) are considered to
|
||||
be development releases. Even numbers (1.4,1.6,1.8) are stable
|
||||
releases. The current 1.3 effort is working to produce a stable 2.0
|
||||
release. A stable 2.0 release will not be made until it can
|
||||
accompanied by fully updated documentation. In the meantime, we will
|
||||
continue to make periodic 1.3.x releases.
|
||||
|
||||
Please report problems with this release to the swig-dev mailing list,
|
||||
details at http://www.swig.org/mail.html.
|
||||
|
|
|
|||
339
CCache/COPYING
339
CCache/COPYING
|
|
@ -1,339 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
675 Mass Ave, Cambridge, MA 02139, USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Appendix: How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 19yy <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
datarootdir = @datarootdir@
|
||||
srcdir=@srcdir@
|
||||
VPATH=@srcdir@
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
bindir=@bindir@
|
||||
mandir=@mandir@
|
||||
INSTALLCMD=@INSTALL@
|
||||
PACKAGE_NAME=@PACKAGE_NAME@
|
||||
# Soft link test can be skipped on systems that don't support soft linking
|
||||
NOSOFTLINKSTEST=
|
||||
|
||||
CC=@CC@
|
||||
CFLAGS=@CFLAGS@ -I.
|
||||
SWIG=swig
|
||||
SWIG_LIB=../../Lib
|
||||
EXEEXT=@EXEEXT@
|
||||
|
||||
# Use standard autoconf approach to transform executable name using --program-prefix and --program-suffix
|
||||
transform = @program_transform_name@
|
||||
|
||||
LIBS= @LIBS@
|
||||
OBJS= ccache.o mdfour.o hash.o execute.o util.o args.o stats.o \
|
||||
cleanup.o snprintf.o unify.o
|
||||
HEADERS = ccache.h mdfour.h
|
||||
|
||||
all: $(PACKAGE_NAME)$(EXEEXT)
|
||||
|
||||
# Note that HTML documentation is actually generated and used from the main SWIG documentation Makefile
|
||||
docs: $(PACKAGE_NAME).1 web/ccache-man.html
|
||||
|
||||
$(PACKAGE_NAME)$(EXEEXT): $(OBJS) $(HEADERS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||
|
||||
$(PACKAGE_NAME).1: ccache.yo
|
||||
-yodl2man -o $(PACKAGE_NAME).1 ccache.yo
|
||||
|
||||
web/ccache-man.html: ccache.yo
|
||||
mkdir -p man
|
||||
yodl2html -o web/ccache-man.html ccache.yo
|
||||
|
||||
install: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1
|
||||
${INSTALLCMD} -d $(DESTDIR)${bindir}
|
||||
${INSTALLCMD} -m 755 $(PACKAGE_NAME)$(EXEEXT) $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT)
|
||||
${INSTALLCMD} -d $(DESTDIR)${mandir}/man1
|
||||
${INSTALLCMD} -m 644 ${srcdir}/$(PACKAGE_NAME).1 $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1
|
||||
|
||||
uninstall: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1
|
||||
rm -f $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT)
|
||||
rm -f $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1
|
||||
|
||||
clean:
|
||||
/bin/rm -f $(OBJS) *~ $(PACKAGE_NAME)$(EXEEXT)
|
||||
|
||||
clean-docs:
|
||||
rm -f $(PACKAGE_NAME).1 web/ccache-man.html
|
||||
|
||||
check : test
|
||||
|
||||
test: test.sh
|
||||
SWIG_LIB='$(SWIG_LIB)' PATH=../..:$$PATH SWIG='$(SWIG)' CC='$(CC)' NOSOFTLINKSTEST='$(NOSOFTLINKSTEST)' ./test.sh
|
||||
|
||||
check: test
|
||||
|
||||
distclean: clean
|
||||
/bin/rm -f Makefile config.h config.sub config.log build-stamp config.status configure config.h
|
||||
|
||||
# FIXME: To fix this, test.sh needs to be able to take ccache from the
|
||||
# installed prefix, not from the source dir.
|
||||
installcheck:
|
||||
@echo "WARNING! This is not really \"installcheck\" yet."
|
||||
$(MAKE) check
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
This is a re-implementation of "compilercache" in C
|
||||
|
||||
The original compilercache scripts were by Erik Thiele
|
||||
(erikyyy@erikyyy.de) and I would like to thank him for an excellent
|
||||
piece of work. See http://www.erikyyy.de/compilercache/ for the
|
||||
original shell scripts.
|
||||
|
||||
I wrote ccache because I wanted to get a bit more speed out of a
|
||||
compiler cache and I wanted to remove some of the limitations of the
|
||||
shell-script version.
|
||||
|
||||
Please see the manual page and documentation at
|
||||
http://ccache.samba.org/
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
Please run:
|
||||
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
|
||||
then read the ccache manual page
|
||||
|
||||
-----------
|
||||
|
||||
Andrew Tridgell
|
||||
http://samba.org/~tridge/
|
||||
bugs@ccache.samba.org
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
This directory contains a version of ccache. The initial version was based on ccache-2.4 plus
|
||||
debian patches 01-02, 04-14, see the debian/patches subdirectory. The ccache-win32-2.4 modifications
|
||||
to ccache-2.4 have also been merged in.
|
||||
|
||||
Changes have been made to support cacheing the output from SWIG. The ability to cache c/c++ compiler
|
||||
output has been retained.
|
||||
|
||||
Additional features added are the CCACHE_VERBOSE and CCACHE_SWIG environment variables, see docs.
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
convenient routines for argument list handling
|
||||
|
||||
Copyright (C) Andrew Tridgell 2002
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "ccache.h"
|
||||
|
||||
ARGS *args_init(int init_argc, char **init_args)
|
||||
{
|
||||
ARGS *args;
|
||||
int i;
|
||||
args = (ARGS *)x_malloc(sizeof(ARGS));
|
||||
args->argc = 0;
|
||||
args->argv = (char **)x_malloc(sizeof(char *));
|
||||
args->argv[0] = NULL;
|
||||
for (i=0;i<init_argc;i++) {
|
||||
args_add(args, init_args[i]);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
void args_add(ARGS *args, const char *s)
|
||||
{
|
||||
args->argv = (char**)x_realloc(args->argv, (args->argc + 2) * sizeof(char *));
|
||||
args->argv[args->argc] = x_strdup(s);
|
||||
args->argc++;
|
||||
args->argv[args->argc] = NULL;
|
||||
}
|
||||
|
||||
/* pop the last element off the args list */
|
||||
void args_pop(ARGS *args, int n)
|
||||
{
|
||||
while (n--) {
|
||||
args->argc--;
|
||||
free(args->argv[args->argc]);
|
||||
args->argv[args->argc] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* remove the first element of the argument list */
|
||||
void args_remove_first(ARGS *args)
|
||||
{
|
||||
free(args->argv[0]);
|
||||
memmove(&args->argv[0],
|
||||
&args->argv[1],
|
||||
args->argc * sizeof(args->argv[0]));
|
||||
args->argc--;
|
||||
}
|
||||
|
||||
/* add an argument into the front of the argument list */
|
||||
void args_add_prefix(ARGS *args, const char *s)
|
||||
{
|
||||
args->argv = (char**)x_realloc(args->argv, (args->argc + 2) * sizeof(char *));
|
||||
memmove(&args->argv[1], &args->argv[0],
|
||||
(args->argc+1) * sizeof(args->argv[0]));
|
||||
args->argv[0] = x_strdup(s);
|
||||
args->argc++;
|
||||
}
|
||||
|
||||
/* strip any arguments beginning with the specified prefix */
|
||||
void args_strip(ARGS *args, const char *prefix)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<args->argc; ) {
|
||||
if (strncmp(args->argv[i], prefix, strlen(prefix)) == 0) {
|
||||
free(args->argv[i]);
|
||||
memmove(&args->argv[i],
|
||||
&args->argv[i+1],
|
||||
args->argc * sizeof(args->argv[i]));
|
||||
args->argc--;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
1388
CCache/ccache.c
1388
CCache/ccache.c
File diff suppressed because it is too large
Load diff
205
CCache/ccache.h
205
CCache/ccache.h
|
|
@ -1,205 +0,0 @@
|
|||
#include "ccache_swig_config.h"
|
||||
|
||||
#define CCACHE_VERSION SWIG_VERSION
|
||||
|
||||
#ifndef _WIN32
|
||||
#include "config.h"
|
||||
#else
|
||||
#include <sys/locking.h>
|
||||
#define PACKAGE_NAME "ccache-swig.exe"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/wait.h>
|
||||
#include <sys/mman.h>
|
||||
#else
|
||||
#define _WIN32_WINNT 0x0500
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#include <sys/file.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <utime.h>
|
||||
#include <stdarg.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#ifdef HAVE_PWD_H
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_ZLIB
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#define STATUS_NOTFOUND 3
|
||||
#define STATUS_FATAL 4
|
||||
#define STATUS_NOCACHE 5
|
||||
|
||||
#define MYNAME PACKAGE_NAME
|
||||
|
||||
#define LIMIT_MULTIPLE 0.8
|
||||
|
||||
/* default maximum cache size */
|
||||
#ifndef DEFAULT_MAXSIZE
|
||||
#define DEFAULT_MAXSIZE (1000*1000)
|
||||
#endif
|
||||
|
||||
/* file copy mode */
|
||||
#ifdef ENABLE_ZLIB
|
||||
#define COPY_UNCOMPRESSED 0
|
||||
#define COPY_FROM_CACHE 1
|
||||
#define COPY_TO_CACHE 2
|
||||
#endif
|
||||
|
||||
enum stats {
|
||||
STATS_NONE=0,
|
||||
STATS_STDOUT,
|
||||
STATS_STATUS,
|
||||
STATS_ERROR,
|
||||
STATS_TOCACHE,
|
||||
STATS_PREPROCESSOR,
|
||||
STATS_COMPILER,
|
||||
STATS_MISSING,
|
||||
STATS_CACHED,
|
||||
STATS_ARGS,
|
||||
STATS_LINK,
|
||||
STATS_NUMFILES,
|
||||
STATS_TOTALSIZE,
|
||||
STATS_MAXFILES,
|
||||
STATS_MAXSIZE,
|
||||
STATS_NOTC,
|
||||
STATS_DEVICE,
|
||||
STATS_NOINPUT,
|
||||
STATS_ENVIRONMMENT,
|
||||
STATS_MULTIPLE,
|
||||
STATS_CONFTEST,
|
||||
STATS_UNSUPPORTED,
|
||||
STATS_OUTSTDOUT,
|
||||
|
||||
STATS_END
|
||||
};
|
||||
|
||||
typedef unsigned uint32;
|
||||
|
||||
#include "mdfour.h"
|
||||
|
||||
void hash_start(void);
|
||||
void hash_string(const char *s);
|
||||
void hash_int(int x);
|
||||
void hash_file(const char *fname);
|
||||
char *hash_result(void);
|
||||
void hash_buffer(const char *s, int len);
|
||||
|
||||
void cc_log(const char *format, ...);
|
||||
void fatal(const char *msg);
|
||||
|
||||
void copy_fd(int fd_in, int fd_out);
|
||||
int safe_rename(const char* oldpath, const char* newpath);
|
||||
int move_file(const char *src, const char *dest);
|
||||
int test_if_compressed(const char *filename);
|
||||
|
||||
int commit_to_cache(const char *src, const char *dest, int hardlink);
|
||||
int retrieve_from_cache(const char *src, const char *dest, int hardlink);
|
||||
|
||||
int create_dir(const char *dir);
|
||||
int create_cachedirtag(const char *dir);
|
||||
void x_asprintf(char **ptr, const char *format, ...);
|
||||
char *x_strdup(const char *s);
|
||||
void *x_realloc(void *ptr, size_t size);
|
||||
void *x_malloc(size_t size);
|
||||
void traverse(const char *dir, void (*fn)(const char *, struct stat *));
|
||||
char *str_basename(const char *s);
|
||||
char *dirname(char *s);
|
||||
int lock_fd(int fd);
|
||||
size_t file_size(struct stat *st);
|
||||
int safe_open(const char *fname);
|
||||
char *x_realpath(const char *path);
|
||||
char *gnu_getcwd(void);
|
||||
int create_empty_file(const char *fname);
|
||||
const char *get_home_directory(void);
|
||||
int x_utimes(const char *filename);
|
||||
#ifdef _WIN32
|
||||
void perror_win32(LPTSTR pszFunction);
|
||||
#endif
|
||||
|
||||
void stats_update(enum stats stat);
|
||||
void stats_zero(void);
|
||||
void stats_summary(void);
|
||||
void stats_tocache(size_t size, size_t numfiles);
|
||||
void stats_read(const char *stats_file, unsigned counters[STATS_END]);
|
||||
int stats_set_limits(long maxfiles, long maxsize);
|
||||
size_t value_units(const char *s);
|
||||
void display_size(unsigned v);
|
||||
void stats_set_sizes(const char *dir, size_t num_files, size_t total_size);
|
||||
|
||||
int unify_hash(const char *fname);
|
||||
|
||||
#ifndef HAVE_VASPRINTF
|
||||
int vasprintf(char **, const char *, va_list );
|
||||
#endif
|
||||
#ifndef HAVE_ASPRINTF
|
||||
int asprintf(char **ptr, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
int snprintf(char *,size_t ,const char *, ...);
|
||||
#endif
|
||||
|
||||
void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize);
|
||||
void cleanup_all(const char *dir);
|
||||
void wipe_all(const char *dir);
|
||||
|
||||
#ifdef _WIN32
|
||||
char *argvtos(char **argv);
|
||||
#endif
|
||||
int execute(char **argv,
|
||||
const char *path_stdout,
|
||||
const char *path_stderr);
|
||||
char *find_executable(const char *name, const char *exclude_name);
|
||||
void display_execute_args(char **argv);
|
||||
|
||||
typedef struct {
|
||||
char **argv;
|
||||
int argc;
|
||||
} ARGS;
|
||||
|
||||
|
||||
ARGS *args_init(int , char **);
|
||||
void args_add(ARGS *args, const char *s);
|
||||
void args_add_prefix(ARGS *args, const char *s);
|
||||
void args_pop(ARGS *args, int n);
|
||||
void args_strip(ARGS *args, const char *prefix);
|
||||
void args_remove_first(ARGS *args);
|
||||
|
||||
extern int ccache_verbose;
|
||||
|
||||
#if HAVE_COMPAR_FN_T
|
||||
#define COMPAR_FN_T __compar_fn_t
|
||||
#else
|
||||
typedef int (*COMPAR_FN_T)(const void *, const void *);
|
||||
#endif
|
||||
|
||||
/* work with silly DOS binary open */
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
/* mkstemp() on some versions of cygwin don't handle binary files, so
|
||||
override */
|
||||
#ifdef __CYGWIN__
|
||||
#undef HAVE_MKSTEMP
|
||||
#endif
|
||||
422
CCache/ccache.yo
422
CCache/ccache.yo
|
|
@ -1,422 +0,0 @@
|
|||
whenman(
|
||||
COMMENT(html output not great if included when using html2doc)
|
||||
manpage(ccache-swig)(1)()()()
|
||||
)
|
||||
|
||||
whenhtml(htmlcommand(
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>ccache-swig(1) manpage</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="CCache"></a>Using SWIG with ccache - ccache-swig(1) manpage</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<!-- INDEX -->
|
||||
|
||||
))
|
||||
|
||||
|
||||
manpagename(ccache-swig)(a fast compiler cache)
|
||||
|
||||
whenhtml(htmlcommand(
|
||||
ccache-swig - a fast compiler cache
|
||||
))
|
||||
|
||||
manpagesynopsis()
|
||||
|
||||
ccache-swig [OPTION]
|
||||
|
||||
ccache-swig <compiler> [COMPILER OPTIONS]
|
||||
|
||||
<compiler> [COMPILER OPTIONS]
|
||||
|
||||
manpagedescription()
|
||||
|
||||
ccache-swig is a compiler cache. It speeds up re-compilation of C/C++/SWIG code
|
||||
by caching previous compiles and detecting when the same compile is
|
||||
being done again. ccache-swig is ccache plus support for SWIG. ccache
|
||||
and ccache-swig are used interchangeably in this document.
|
||||
|
||||
manpagesection(OPTIONS SUMMARY)
|
||||
|
||||
Here is a summary of the options to ccache-swig.
|
||||
|
||||
verb(
|
||||
-s show statistics summary
|
||||
-z zero statistics
|
||||
-c run a cache cleanup
|
||||
-C clear the cache completely
|
||||
-F <n> set maximum files in cache
|
||||
-M <n> set maximum size of cache (use G, M or K)
|
||||
-h this help page
|
||||
-V print version number
|
||||
)
|
||||
|
||||
manpageoptions()
|
||||
|
||||
These options only apply when you invoke ccache as "ccache-swig". When
|
||||
invoked as a compiler none of these options apply. In that case your
|
||||
normal compiler options apply and you should refer to your compilers
|
||||
documentation.
|
||||
|
||||
startdit()
|
||||
dit(bf(-h)) Print a options summary page
|
||||
|
||||
dit(bf(-s)) Print the current statistics summary for the cache. The
|
||||
statistics are stored spread across the subdirectories of the
|
||||
cache. Using "ccache-swig -s" adds up the statistics across all
|
||||
subdirectories and prints the totals.
|
||||
|
||||
dit(bf(-z)) Zero the cache statistics.
|
||||
|
||||
dit(bf(-V)) Print the ccache version number
|
||||
|
||||
dit(bf(-c)) Clean the cache and re-calculate the cache file count and
|
||||
size totals. Normally the -c option should not be necessary as ccache
|
||||
keeps the cache below the specified limits at runtime and keeps
|
||||
statistics up to date on each compile. This option is mostly useful
|
||||
if you manually modify the cache contents or believe that the cache
|
||||
size statistics may be inaccurate.
|
||||
|
||||
dit(bf(-C)) Clear the entire cache, removing all cached files.
|
||||
|
||||
dit(bf(-F <maxfiles>)) This sets the maximum number of files allowed in
|
||||
the cache. The value is stored inside the cache directory and applies
|
||||
to all future compiles. Due to the way the value is stored the actual
|
||||
value used is always rounded down to the nearest multiple of 16.
|
||||
|
||||
dit(bf(-M <maxsize>)) This sets the maximum cache size. You can specify
|
||||
a value in gigabytes, megabytes or kilobytes by appending a G, M or K
|
||||
to the value. The default is gigabytes. The actual value stored is
|
||||
rounded down to the nearest multiple of 16 kilobytes.
|
||||
|
||||
enddit()
|
||||
|
||||
manpagesection(INSTALLATION)
|
||||
|
||||
There are two ways to use ccache. You can either prefix your compile
|
||||
commands with "ccache-swig" or you can create a symbolic link between
|
||||
ccache-swig and the names of your compilers. The first method is most
|
||||
convenient if you just want to try out ccache or wish to use it for
|
||||
some specific projects. The second method is most useful for when you
|
||||
wish to use ccache for all your compiles.
|
||||
|
||||
To install for usage by the first method just copy ccache-swig to somewhere
|
||||
in your path.
|
||||
|
||||
To install for the second method do something like this:
|
||||
verb(
|
||||
cp ccache-swig /usr/local/bin/
|
||||
ln -s /usr/local/bin/ccache-swig /usr/local/bin/gcc
|
||||
ln -s /usr/local/bin/ccache-swig /usr/local/bin/g++
|
||||
ln -s /usr/local/bin/ccache-swig /usr/local/bin/cc
|
||||
ln -s /usr/local/bin/ccache-swig /usr/local/bin/swig
|
||||
)
|
||||
This will work as long as /usr/local/bin comes before the path to gcc
|
||||
(which is usually in /usr/bin). After installing you may wish to run
|
||||
"which gcc" to make sure that the correct link is being used.
|
||||
|
||||
Note! Do not use a hard link, use a symbolic link. A hardlink will
|
||||
cause "interesting" problems.
|
||||
|
||||
manpagesection(EXTRA OPTIONS)
|
||||
|
||||
When run as a compiler front end ccache usually just takes the same
|
||||
command line options as the compiler you are using. The only exception
|
||||
to this is the option '--ccache-skip'. That option can be used to tell
|
||||
ccache that the next option is definitely not a input filename, and
|
||||
should be passed along to the compiler as-is.
|
||||
|
||||
The reason this can be important is that ccache does need to parse the
|
||||
command line and determine what is an input filename and what is a
|
||||
compiler option, as it needs the input filename to determine the name
|
||||
of the resulting object file (among other things). The heuristic
|
||||
ccache uses in this parse is that any string on the command line that
|
||||
exists as a file is treated as an input file name (usually a C
|
||||
file). By using --ccache-skip you can force an option to not be
|
||||
treated as an input file name and instead be passed along to the
|
||||
compiler as a command line option.
|
||||
|
||||
manpagesection(ENVIRONMENT VARIABLES)
|
||||
|
||||
ccache uses a number of environment variables to control operation. In
|
||||
most cases you won't need any of these as the defaults will be fine.
|
||||
|
||||
startdit()
|
||||
|
||||
dit(bf(CCACHE_DIR)) the CCACHE_DIR environment variable specifies
|
||||
where ccache will keep its cached compiler output. The default is
|
||||
"$HOME/.ccache".
|
||||
|
||||
dit(bf(CCACHE_TEMPDIR)) the CCACHE_TEMPDIR environment variable specifies
|
||||
where ccache will put temporary files. The default is the same as
|
||||
CCACHE_DIR. Note that the CCACHE_TEMPDIR path must be on the same
|
||||
filesystem as the CCACHE_DIR path, so that renames of files between
|
||||
the two directories can work.
|
||||
|
||||
dit(bf(CCACHE_LOGFILE)) If you set the CCACHE_LOGFILE environment
|
||||
variable then ccache will write some log information on cache hits
|
||||
and misses in that file. This is useful for tracking down problems.
|
||||
|
||||
dit(bf(CCACHE_VERBOSE)) If you set the CCACHE_VERBOSE environment
|
||||
variable then ccache will display on stdout all the compiler invocations
|
||||
that it makes. This can useful for debugging unexpected problems.
|
||||
|
||||
dit(bf(CCACHE_PATH)) You can optionally set CCACHE_PATH to a colon
|
||||
separated path where ccache will look for the real compilers. If you
|
||||
don't do this then ccache will look for the first executable matching
|
||||
the compiler name in the normal PATH that isn't a symbolic link to
|
||||
ccache itself.
|
||||
|
||||
dit(bf(CCACHE_CC)) You can optionally set CCACHE_CC to force the name
|
||||
of the compiler to use. If you don't do this then ccache works it out
|
||||
from the command line.
|
||||
|
||||
dit(bf(CCACHE_PREFIX)) This option adds a prefix to the command line
|
||||
that ccache runs when invoking the compiler. Also see the section
|
||||
below on using ccache with distcc.
|
||||
|
||||
dit(bf(CCACHE_DISABLE)) If you set the environment variable
|
||||
CCACHE_DISABLE then ccache will just call the real compiler,
|
||||
bypassing the cache completely.
|
||||
|
||||
dit(bf(CCACHE_READONLY)) the CCACHE_READONLY environment variable
|
||||
tells ccache to attempt to use existing cached object files, but not
|
||||
to try to add anything new to the cache. If you are using this because
|
||||
your CCACHE_DIR is read-only, then you may find that you also need to
|
||||
set CCACHE_TEMPDIR as otherwise ccache will fail to create the
|
||||
temporary files.
|
||||
|
||||
dit(bf(CCACHE_CPP2)) If you set the environment variable CCACHE_CPP2
|
||||
then ccache will not use the optimisation of avoiding the 2nd call to
|
||||
the pre-processor by compiling the pre-processed output that was used
|
||||
for finding the hash in the case of a cache miss. This is primarily a
|
||||
debugging option, although it is possible that some unusual compilers
|
||||
will have problems with the intermediate filename extensions used in
|
||||
this optimisation, in which case this option could allow ccache to be
|
||||
used.
|
||||
|
||||
dit(bf(CCACHE_NOCOMPRESS)) If you set the environment variable
|
||||
CCACHE_NOCOMPRESS then there is no compression used on files that go
|
||||
into the cache. However, this setting has no effect on how files are
|
||||
retrieved from the cache, compressed results will still be usable.
|
||||
|
||||
dit(bf(CCACHE_NOSTATS)) If you set the environment variable
|
||||
CCACHE_NOSTATS then ccache will not update the statistics files on
|
||||
each compile.
|
||||
|
||||
dit(bf(CCACHE_NLEVELS)) The environment variable CCACHE_NLEVELS allows
|
||||
you to choose the number of levels of hash in the cache directory. The
|
||||
default is 2. The minimum is 1 and the maximum is 8.
|
||||
|
||||
dit(bf(CCACHE_HARDLINK)) If you set the environment variable
|
||||
CCACHE_HARDLINK then ccache will attempt to use hard links from the
|
||||
cache directory when creating the compiler output rather than using a
|
||||
file copy. Using hard links is faster, but can confuse programs like
|
||||
'make' that rely on modification times. Hard links are never made for
|
||||
compressed cache files.
|
||||
|
||||
dit(bf(CCACHE_RECACHE)) This forces ccache to not use any cached
|
||||
results, even if it finds them. New results are still cached, but
|
||||
existing cache entries are ignored.
|
||||
|
||||
dit(bf(CCACHE_UMASK)) This sets the umask for ccache and all child
|
||||
processes (such as the compiler). This is mostly useful when you wish
|
||||
to share your cache with other users. Note that this also affects the
|
||||
file permissions set on the object files created from your
|
||||
compilations.
|
||||
|
||||
dit(bf(CCACHE_HASHDIR)) This tells ccache to hash the current working
|
||||
directory when calculating the hash that is used to distinguish two
|
||||
compiles. This prevents a problem with the storage of the current
|
||||
working directory in the debug info of a object file, which can lead
|
||||
ccache to give a cached object file that has the working directory in
|
||||
the debug info set incorrectly. This option is off by default as the
|
||||
incorrect setting of this debug info rarely causes problems. If you
|
||||
strike problems with gdb not using the correct directory then enable
|
||||
this option.
|
||||
|
||||
dit(bf(CCACHE_UNIFY)) If you set the environment variable CCACHE_UNIFY
|
||||
then ccache will use the C/C++ unifier when hashing the pre-processor
|
||||
output if -g is not used in the compile. The unifier is slower than a
|
||||
normal hash, so setting this environment variable loses a little bit
|
||||
of speed, but it means that ccache can take advantage of not
|
||||
recompiling when the changes to the source code consist of
|
||||
reformatting only. Note that using CCACHE_UNIFY changes the hash, so
|
||||
cached compiles with CCACHE_UNIFY set cannot be used when
|
||||
CCACHE_UNIFY is not set and vice versa. The reason the unifier is off
|
||||
by default is that it can give incorrect line number information in
|
||||
compiler warning messages.
|
||||
|
||||
dit(bf(CCACHE_EXTENSION)) Normally ccache tries to automatically
|
||||
determine the extension to use for intermediate C pre-processor files
|
||||
based on the type of file being compiled. Unfortunately this sometimes
|
||||
doesn't work, for example when using the aCC compiler on HP-UX. On
|
||||
systems like this you can use the CCACHE_EXTENSION option to override
|
||||
the default. On HP-UX set this environment variable to "i" if you use
|
||||
the aCC compiler.
|
||||
|
||||
dit(bf(CCACHE_STRIPC)) If you set the environment variable
|
||||
CCACHE_STRIPC then ccache will strip the -c option when invoking
|
||||
the preprocessor. This option is primarily for the Sun Workshop
|
||||
C++ compiler as without this option an unwarranted warning is displayed:
|
||||
CC: Warning: "-E" redefines product from "object" to "source (stdout)"
|
||||
when -E and -c is used together.
|
||||
|
||||
dit(bf(CCACHE_SWIG)) When using SWIG as the compiler and it does not
|
||||
have 'swig' in the executable name, then the CCACHE_SWIG environment
|
||||
variable needs to be set in order for ccache to work correctly with
|
||||
SWIG. The use of CCACHE_CPP2 is also recommended for SWIG due to some
|
||||
preprocessor quirks, however, use of CCACHE_CPP2 can often be skipped
|
||||
-- check your generated code with and without this option set. Known
|
||||
problems are using preprocessor directives within %inline blocks and
|
||||
the use of '#pragma SWIG'.
|
||||
|
||||
enddit()
|
||||
|
||||
manpagesection(CACHE SIZE MANAGEMENT)
|
||||
|
||||
By default ccache has a one gigabyte limit on the cache size and no
|
||||
maximum number of files. You can set a different limit using the
|
||||
"ccache -M" and "ccache -F" options, which set the size and number of
|
||||
files limits.
|
||||
|
||||
When these limits are reached ccache will reduce the cache to 20%
|
||||
below the numbers you specified in order to avoid doing the cache
|
||||
clean operation too often.
|
||||
|
||||
manpagesection(CACHE COMPRESSION)
|
||||
|
||||
By default on most platforms ccache will compress all files it puts
|
||||
into the cache
|
||||
using the zlib compression. While this involves a negligible
|
||||
performance slowdown, it significantly increases the number of files
|
||||
that fit in the cache. You can turn off compression setting the
|
||||
CCACHE_NOCOMPRESS environment variable.
|
||||
|
||||
manpagesection(HOW IT WORKS)
|
||||
|
||||
The basic idea is to detect when you are compiling exactly the same
|
||||
code a 2nd time and use the previously compiled output. You detect
|
||||
that it is the same code by forming a hash of:
|
||||
|
||||
itemization(
|
||||
it() the pre-processor output from running the compiler with -E
|
||||
it() the command line options
|
||||
it() the real compilers size and modification time
|
||||
it() any stderr output generated by the compiler
|
||||
)
|
||||
|
||||
These are hashed using md4 (a strong hash) and a cache file is formed
|
||||
based on that hash result. When the same compilation is done a second
|
||||
time ccache is able to supply the correct compiler output (including
|
||||
all warnings etc) from the cache.
|
||||
|
||||
ccache has been carefully written to always produce exactly the same
|
||||
compiler output that you would get without the cache. If you ever
|
||||
discover a case where ccache changes the output of your compiler then
|
||||
please let me know.
|
||||
|
||||
manpagesection(USING CCACHE WITH DISTCC)
|
||||
|
||||
distcc is a very useful program for distributing compilation across a
|
||||
range of compiler servers. It is often useful to combine distcc with
|
||||
ccache, so that compiles that are done are sped up by distcc, but that
|
||||
ccache avoids the compile completely where possible.
|
||||
|
||||
To use distcc with ccache I recommend using the CCACHE_PREFIX
|
||||
option. You just need to set the environment variable CCACHE_PREFIX to
|
||||
'distcc' and ccache will prefix the command line used with the
|
||||
compiler with the command 'distcc'.
|
||||
|
||||
manpagesection(SHARING A CACHE)
|
||||
|
||||
A group of developers can increase the cache hit rate by sharing a
|
||||
cache directory. The hard links however cause unwanted side effects,
|
||||
as all links to a cached file share the file's modification timestamp.
|
||||
This results in false dependencies to be triggered by timestamp-based
|
||||
build systems whenever another user links to an existing
|
||||
file. Typically, users will see that their libraries and binaries are
|
||||
relinked without reason. To share a cache without side effects, the
|
||||
following conditions need to be met:
|
||||
|
||||
itemization(
|
||||
it() Use the same bf(CCACHE_DIR) environment variable setting
|
||||
it() Unset the bf(CCACHE_HARDLINK) environment variable
|
||||
it() Make sure everyone sets the CCACHE_UMASK environment variable
|
||||
to 002, this ensures that cached files are accessible to everyone in
|
||||
the group.
|
||||
it() Make sure that all users have write permission in the entire
|
||||
cache directory (and that you trust all users of the shared cache).
|
||||
it() Make sure that the setgid bit is set on all directories in the
|
||||
cache. This tells the filesystem to inherit group ownership for new
|
||||
directories. The command "chmod g+s `find $CCACHE_DIR -type d`" might
|
||||
be useful for this.
|
||||
it() Set bf(CCACHE_NOCOMPRESS) for all users, if there are users with
|
||||
versions of ccache that do not support compression.
|
||||
)
|
||||
|
||||
manpagesection(HISTORY)
|
||||
|
||||
ccache was inspired by the compilercache shell script script written
|
||||
by Erik Thiele and I would like to thank him for an excellent piece of
|
||||
work. See
|
||||
url(http://www.erikyyy.de/compilercache/)(http://www.erikyyy.de/compilercache/)
|
||||
for the Erik's scripts.
|
||||
ccache-swig is a port of the original ccache with support added for use
|
||||
with SWIG.
|
||||
|
||||
I wrote ccache because I wanted to get a bit more speed out of a
|
||||
compiler cache and I wanted to remove some of the limitations of the
|
||||
shell-script version.
|
||||
|
||||
manpagesection(DIFFERENCES FROM COMPILERCACHE)
|
||||
|
||||
The biggest differences between Erik's compilercache script and ccache
|
||||
are:
|
||||
itemization(
|
||||
it() ccache is written in C, which makes it a bit faster (calling out to
|
||||
external programs is mostly what slowed down the scripts).
|
||||
it() ccache can automatically find the real compiler
|
||||
it() ccache keeps statistics on hits/misses
|
||||
it() ccache can do automatic cache management
|
||||
it() ccache can cache compiler output that includes warnings. In many
|
||||
cases this gives ccache a much higher cache hit rate.
|
||||
it() ccache can handle a much wider ranger of compiler options
|
||||
it() ccache avoids a double call to cpp on a cache miss
|
||||
)
|
||||
|
||||
manpagesection(CREDITS)
|
||||
|
||||
Thanks to the following people for their contributions to ccache
|
||||
itemization(
|
||||
it() Erik Thiele for the original compilercache script
|
||||
it() Luciano Rocha for the idea of compiling the pre-processor output
|
||||
to avoid a 2nd cpp pass
|
||||
it() Paul Russell for many suggestions and the debian packaging
|
||||
)
|
||||
|
||||
manpageauthor()
|
||||
|
||||
ccache was written by Andrew Tridgell
|
||||
url(http://samba.org/~tridge/)(http://samba.org/~tridge/).
|
||||
ccache was adapted to create ccache-swig for use with SWIG by William Fulton.
|
||||
|
||||
If you wish to report a problem or make a suggestion then please email
|
||||
the SWIG developers on the swig-devel mailing list, see
|
||||
url(http://www.swig.org/mail.html)(http://www.swig.org/mail.html)
|
||||
|
||||
ccache is released under the GNU General Public License version 2 or
|
||||
later. Please see the file COPYING for license details.
|
||||
|
||||
whenhtml(htmlcommand(
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
))
|
||||
|
|
@ -1 +0,0 @@
|
|||
#define SWIG_VERSION "@PACKAGE_VERSION@"
|
||||
193
CCache/cleanup.c
193
CCache/cleanup.c
|
|
@ -1,193 +0,0 @@
|
|||
/*
|
||||
Copyright (C) Andrew Tridgell 2002
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
functions to cleanup the cache directory when it gets too large
|
||||
*/
|
||||
|
||||
#include "ccache.h"
|
||||
|
||||
static struct files {
|
||||
char *fname;
|
||||
time_t mtime;
|
||||
size_t size;
|
||||
} **files;
|
||||
static unsigned allocated;
|
||||
static unsigned num_files;
|
||||
static size_t total_size;
|
||||
static size_t total_files;
|
||||
static size_t size_threshold;
|
||||
static size_t files_threshold;
|
||||
|
||||
/* file comparison function to try to delete the oldest files first */
|
||||
static int files_compare(struct files **f1, struct files **f2)
|
||||
{
|
||||
if ((*f2)->mtime == (*f1)->mtime) {
|
||||
return strcmp((*f2)->fname, (*f1)->fname);
|
||||
}
|
||||
if ((*f2)->mtime > (*f1)->mtime) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* this builds the list of files in the cache */
|
||||
static void traverse_fn(const char *fname, struct stat *st)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (!S_ISREG(st->st_mode)) return;
|
||||
|
||||
p = str_basename(fname);
|
||||
if (strcmp(p, "stats") == 0) {
|
||||
free(p);
|
||||
return;
|
||||
}
|
||||
free(p);
|
||||
|
||||
if (num_files == allocated) {
|
||||
allocated = 10000 + num_files*2;
|
||||
files = (struct files **)x_realloc(files,
|
||||
sizeof(struct files *)*allocated);
|
||||
}
|
||||
|
||||
files[num_files] = (struct files *)x_malloc(sizeof(struct files));
|
||||
files[num_files]->fname = x_strdup(fname);
|
||||
files[num_files]->mtime = st->st_mtime;
|
||||
files[num_files]->size = file_size(st) / 1024;
|
||||
total_size += files[num_files]->size;
|
||||
num_files++;
|
||||
}
|
||||
|
||||
/* sort the files we've found and delete the oldest ones until we are
|
||||
below the thresholds */
|
||||
static void sort_and_clean(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (num_files > 1) {
|
||||
/* sort in ascending data order */
|
||||
qsort(files, num_files, sizeof(struct files *),
|
||||
(COMPAR_FN_T)files_compare);
|
||||
}
|
||||
|
||||
/* delete enough files to bring us below the threshold */
|
||||
for (i=0;i<num_files; i++) {
|
||||
if ((size_threshold==0 || total_size < size_threshold) &&
|
||||
(files_threshold==0 || (num_files-i) < files_threshold)) break;
|
||||
|
||||
if (unlink(files[i]->fname) != 0 && errno != ENOENT) {
|
||||
fprintf(stderr, "unlink %s - %s\n",
|
||||
files[i]->fname, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
total_size -= files[i]->size;
|
||||
}
|
||||
|
||||
total_files = num_files - i;
|
||||
}
|
||||
|
||||
/* cleanup in one cache subdir */
|
||||
void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
size_threshold = maxsize * LIMIT_MULTIPLE;
|
||||
files_threshold = maxfiles * LIMIT_MULTIPLE;
|
||||
|
||||
num_files = 0;
|
||||
total_size = 0;
|
||||
|
||||
/* build a list of files */
|
||||
traverse(dir, traverse_fn);
|
||||
|
||||
/* clean the cache */
|
||||
sort_and_clean();
|
||||
|
||||
stats_set_sizes(dir, total_files, total_size);
|
||||
|
||||
/* free it up */
|
||||
for (i=0;i<num_files;i++) {
|
||||
free(files[i]->fname);
|
||||
free(files[i]);
|
||||
files[i] = NULL;
|
||||
}
|
||||
if (files) free(files);
|
||||
allocated = 0;
|
||||
files = NULL;
|
||||
|
||||
num_files = 0;
|
||||
total_size = 0;
|
||||
}
|
||||
|
||||
/* cleanup in all cache subdirs */
|
||||
void cleanup_all(const char *dir)
|
||||
{
|
||||
unsigned counters[STATS_END];
|
||||
char *dname, *sfile;
|
||||
int i;
|
||||
|
||||
for (i=0;i<=0xF;i++) {
|
||||
x_asprintf(&dname, "%s/%1x", dir, i);
|
||||
x_asprintf(&sfile, "%s/%1x/stats", dir, i);
|
||||
|
||||
memset(counters, 0, sizeof(counters));
|
||||
stats_read(sfile, counters);
|
||||
|
||||
cleanup_dir(dname,
|
||||
counters[STATS_MAXFILES],
|
||||
counters[STATS_MAXSIZE]);
|
||||
free(dname);
|
||||
free(sfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* traverse function for wiping files */
|
||||
static void wipe_fn(const char *fname, struct stat *st)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (!S_ISREG(st->st_mode)) return;
|
||||
|
||||
p = str_basename(fname);
|
||||
if (strcmp(p, "stats") == 0) {
|
||||
free(p);
|
||||
return;
|
||||
}
|
||||
free(p);
|
||||
|
||||
unlink(fname);
|
||||
}
|
||||
|
||||
|
||||
/* wipe all cached files in all subdirs */
|
||||
void wipe_all(const char *dir)
|
||||
{
|
||||
char *dname;
|
||||
int i;
|
||||
|
||||
for (i=0;i<=0xF;i++) {
|
||||
x_asprintf(&dname, "%s/%1x", dir, i);
|
||||
traverse(dir, wipe_fn);
|
||||
free(dname);
|
||||
}
|
||||
|
||||
/* and fix the counters */
|
||||
cleanup_all(dir);
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
dnl Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_INIT([ccache-swig], [0.0]) # Get version from SWIG in ccache_swig_config.h.in
|
||||
AC_PREREQ(2.52)
|
||||
AC_CONFIG_SRCDIR([ccache.h])
|
||||
|
||||
AC_MSG_NOTICE([Configuring ccache])
|
||||
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
dnl Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
AC_ARG_PROGRAM # for program_transform_name
|
||||
|
||||
AC_DEFINE([_GNU_SOURCE], 1,
|
||||
[Define _GNU_SOURCE so that we get all necessary prototypes])
|
||||
|
||||
# If GCC, turn on warnings.
|
||||
if test "x$GCC" = "xyes"
|
||||
then
|
||||
CFLAGS="$CFLAGS -Wall -W"
|
||||
else
|
||||
CFLAGS="$CFLAGS -O"
|
||||
fi
|
||||
|
||||
AC_HEADER_DIRENT
|
||||
AC_HEADER_TIME
|
||||
AC_HEADER_SYS_WAIT
|
||||
|
||||
AC_CHECK_HEADERS(ctype.h strings.h stdlib.h string.h pwd.h sys/time.h)
|
||||
|
||||
AC_CHECK_FUNCS(realpath snprintf vsnprintf vasprintf asprintf mkstemp)
|
||||
AC_CHECK_FUNCS(gethostname getpwuid)
|
||||
AC_CHECK_FUNCS(utimes)
|
||||
|
||||
AC_CACHE_CHECK([for compar_fn_t in stdlib.h],ccache_cv_COMPAR_FN_T, [
|
||||
AC_TRY_COMPILE(
|
||||
[#include <stdlib.h>],
|
||||
[
|
||||
void test_fn(void) { qsort(NULL, 0, 0, (__compar_fn_t)NULL); }
|
||||
],
|
||||
ccache_cv_COMPAR_FN_T=yes,ccache_cv_COMPAR_FN_T=no)])
|
||||
if test x"$ccache_cv_COMPAR_FN_T" = x"yes"; then
|
||||
AC_DEFINE(HAVE_COMPAR_FN_T, 1, [ ])
|
||||
fi
|
||||
|
||||
dnl Note: This could be replaced by AC_FUNC_SNPRINTF() in the autoconf macro archive
|
||||
AC_CACHE_CHECK([for C99 vsnprintf],ccache_cv_HAVE_C99_VSNPRINTF,[
|
||||
AC_TRY_RUN([
|
||||
#include <sys/types.h>
|
||||
#include <stdarg.h>
|
||||
void foo(const char *format, ...) {
|
||||
va_list ap;
|
||||
int len;
|
||||
char buf[5];
|
||||
|
||||
va_start(ap, format);
|
||||
len = vsnprintf(0, 0, format, ap);
|
||||
va_end(ap);
|
||||
if (len != 5) exit(1);
|
||||
|
||||
if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
main() { foo("hello"); }
|
||||
],
|
||||
ccache_cv_HAVE_C99_VSNPRINTF=yes,ccache_cv_HAVE_C99_VSNPRINTF=no,ccache_cv_HAVE_C99_VSNPRINTF=cross)])
|
||||
if test x"$ccache_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
|
||||
AC_DEFINE(HAVE_C99_VSNPRINTF, 1, [ ])
|
||||
fi
|
||||
|
||||
dnl Check for zlib.
|
||||
dnl Note: This could be replaced by CHECK_ZLIB() in the autoconf macro archive
|
||||
AC_ARG_ENABLE([zlib],
|
||||
AS_HELP_STRING([--enable-zlib], [enable zlib support for ccache compression]),,
|
||||
[enable_zlib=yes])
|
||||
|
||||
if test x"$enable_zlib" = x"yes"; then
|
||||
AC_CHECK_HEADER(zlib.h, AC_CHECK_LIB(z, gzdopen, [LIBS="-lz $LIBS"
|
||||
AC_DEFINE([ENABLE_ZLIB], 1, [Define to 1 if you would like to have zlib compression for ccache.]) ] ))
|
||||
fi
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
ccache (2.4-8) unstable; urgency=high
|
||||
|
||||
zlib compression is now enabled by default in order to increase the amount
|
||||
of object files that can fit in the cache.
|
||||
|
||||
The impact on performance is supposed to be almost negligible
|
||||
(see http://www.gustaebel.de/lars/ccache/). If you do want to disable
|
||||
it however, simply export the CCACHE_NOCOMPRESS environment variable.
|
||||
|
||||
Note that a zlib-enabled ccache will still read your existing
|
||||
uncompressed cache. If you want to compress/uncompress your cache,
|
||||
see the manage-cache.sh script under /usr/share/doc/ccache/examples/.
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sun, 20 May 2007 19:45:07 +1200
|
||||
|
||||
ccache (2.4-1) unstable; urgency=low
|
||||
|
||||
* This release changes the hash input slighly, so you will probably find
|
||||
that you will not get any hits against your existing cache when you
|
||||
upgrade.
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sat, 11 Jun 2005 13:54:33 -0400
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
Installing ccache
|
||||
-----------------
|
||||
|
||||
The recommended way to use this with Debian is to either create "cc"
|
||||
and "gcc" symlinks to /usr/bin/ccache in your private bin directory
|
||||
(which must be before the real cc and gcc in your path), or use
|
||||
CC="ccache gcc" on the make command line.
|
||||
|
||||
Another option is to just prepend /usr/lib/ccache in your PATH
|
||||
environment variable, like
|
||||
|
||||
export PATH="/usr/lib/ccache:$PATH"
|
||||
|
||||
Note that ccache works with both native and cross compilers.
|
||||
|
||||
Ignoring whitespace
|
||||
-------------------
|
||||
|
||||
If you wish to set up ccache so that it ignores blank lines, have a
|
||||
look at the CCACHE_UNIFY option. However, please note that this
|
||||
option is off by default since the reported line numbers may not
|
||||
match the source files anymore.
|
||||
|
||||
|
||||
NFS Issues
|
||||
----------
|
||||
|
||||
(from John Coiner <john.coiner@amd.com> on the ccache mailing list)
|
||||
|
||||
When CCache creates a hardlinked output file, it calls utime() to update
|
||||
the timestamp on the object, so that Make realizes that the object has
|
||||
changed.
|
||||
|
||||
On NFS, utime() has no coherency guarantee, AFAIK. When utime() runs on
|
||||
host A, and our parallel implementation of Make is running on host B,
|
||||
sometimes Make doesn't see the new timestamp soon enough -- and neglects
|
||||
to relink the final binary. That's a one-way ticket to Silent Mysterious
|
||||
Failure Town.
|
||||
|
||||
Instead of relying on the object file timestamp, we create a dummy file
|
||||
with a reliable timestamp:
|
||||
|
||||
objs/foo.o objs/foo.o.built :
|
||||
if ( ccache gcc -o foo.o -c foo.c ) ; \
|
||||
then touch objs/foo.o.built ; \
|
||||
else exit 1; \
|
||||
fi
|
||||
|
||||
binary : objs/foo.o.built
|
||||
gcc -o binary objs/foo.o
|
||||
|
||||
NFS does make a coherency guarantee, that if a file is written and
|
||||
close()d on host A, and subsequently open()ed on host B, that the second
|
||||
open() will reflect all modifications and attributes from the close().
|
||||
Since Make does open() when checking timestamps, and the dummy file is
|
||||
close()d when it's created, the binary will always relink after the
|
||||
object is recompiled.
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sun, 20 May 2007 17:35:36 +1200
|
||||
|
|
@ -1,221 +0,0 @@
|
|||
ccache (2.4-15) unstable; urgency=low
|
||||
|
||||
* Add a new patch which improve the consistency of timestamps on cached
|
||||
objects to make sure clean-up is based on least recently used objects.
|
||||
* Patch the set_limit call so that non-writable cache directories return
|
||||
an error when attempting to size the max(files|size) (closes: #332527)
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sun, 13 Apr 2008 15:07:05 +1200
|
||||
|
||||
ccache (2.4-14) unstable; urgency=low
|
||||
|
||||
* Mention the long options everywhere in the manpage
|
||||
* Merge Gentoo patches:
|
||||
- respect user's LDFLAGS
|
||||
- use utimes() for timestamp if possible
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sun, 23 Mar 2008 16:30:11 +1300
|
||||
|
||||
ccache (2.4-13) unstable; urgency=low
|
||||
|
||||
* Update CACHEDIR.TAG patch to avoid creating the tag file when the
|
||||
CCACHE_READONLY environment variable is set. (closes: #464356)
|
||||
* Mention the GNU-style long options in the manpage
|
||||
|
||||
-- Francois Marier <francois@debian.org> Thu, 07 Feb 2008 10:50:42 +1300
|
||||
|
||||
ccache (2.4-12) unstable; urgency=low
|
||||
|
||||
* Add symlink for gcc 4.3 (closes: #463590)
|
||||
* Add support for the CACHEDIR.TAG spec, thanks to Karl Chen.
|
||||
(see http://www.brynosaurus.com/cachedir/)
|
||||
* Fix hyphens in manpage (lintian notice)
|
||||
* Bump Standards-Version up to 3.7.3 (no changes)
|
||||
* Bump debhelper compatibility to 6
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sat, 02 Feb 2008 10:37:22 +1300
|
||||
|
||||
ccache (2.4-11) unstable; urgency=low
|
||||
|
||||
* Add the collab-maint repo to debian/control
|
||||
|
||||
-- Francois Marier <francois@debian.org> Tue, 20 Nov 2007 15:26:37 +1300
|
||||
|
||||
ccache (2.4-10) unstable; urgency=low
|
||||
|
||||
* Document where the patches are from in debian/patches/CREDITS
|
||||
* debian/rules:
|
||||
- Fixed "make distclean" lintian warning
|
||||
- Removed commented-out entries
|
||||
* Set debhelper compatibility to 5
|
||||
* Add homepage field in debian/control
|
||||
* Add symlinks for MinGW (closes: #445782)
|
||||
* Bump the version to 5 in the debhelper dependency
|
||||
|
||||
-- Francois Marier <francois@debian.org> Fri, 19 Oct 2007 16:04:37 +1300
|
||||
|
||||
ccache (2.4-9) unstable; urgency=low
|
||||
|
||||
* Add a symlink for gcc 4.2 (closes: #431007)
|
||||
* Fix dependencies when using -o (closes: #217713)
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sat, 30 Jun 2007 17:58:44 +1200
|
||||
|
||||
ccache (2.4-8) unstable; urgency=low
|
||||
|
||||
* Enable zlib compression of the cache by default (closes: #409848).
|
||||
Thanks to Sami Liedes for suggesting this.
|
||||
* Disable ccache when profiling (closes: #215849).
|
||||
Thanks to Ted Percival for the Patch.
|
||||
* Fix NFS renaming issues and add instructions to the README.
|
||||
Thanks to John Coiner and instructions.
|
||||
* Put all patches in debian/patches and apply them at build time.
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sun, 20 May 2007 19:42:34 +1200
|
||||
|
||||
ccache (2.4-7) unstable; urgency=low
|
||||
|
||||
* Use the real compiler when HOME is not set (closes: #396350)
|
||||
* Include user script under doc/examples (closes: #392435)
|
||||
Thanks to Behan Webster!
|
||||
* Add support for GNU --long options (closes: #297126)
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sat, 18 Nov 2006 00:50:59 -0500
|
||||
|
||||
ccache (2.4-6) unstable; urgency=low
|
||||
|
||||
* Include symlinks for gcc 4.1 (closes: #372838)
|
||||
* Update watch file
|
||||
|
||||
-- Francois Marier <francois@debian.org> Tue, 13 Jun 2006 22:17:37 -0400
|
||||
|
||||
ccache (2.4-5) unstable; urgency=low
|
||||
|
||||
* Document the fact that cross-compiling is supported (closes: #349221)
|
||||
* Bump Standards-Version up to 3.7.2 (no changes)
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sun, 4 Jun 2006 01:20:07 -0400
|
||||
|
||||
ccache (2.4-4) unstable; urgency=low
|
||||
|
||||
* Mention another way to use ccache in README.Debian (thanks to Benjamin
|
||||
Drieu for the suggestion) (closes: #267632)
|
||||
* Update FSF address
|
||||
* Fix watch file
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sat, 26 Nov 2005 00:15:13 -0500
|
||||
|
||||
ccache (2.4-3) unstable; urgency=low
|
||||
|
||||
* Actually use the configuration flags in debian/rules
|
||||
* Bump Standards-Version up to 3.6.2 (no changes)
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sun, 26 Jun 2005 13:33:19 -0400
|
||||
|
||||
ccache (2.4-2) unstable; urgency=low
|
||||
|
||||
* Add gcc and g++ symlinks to /usr/lib/ccache (closes: #313490)
|
||||
* Remove invalid entry from Depends
|
||||
|
||||
-- Francois Marier <francois@debian.org> Wed, 15 Jun 2005 20:51:03 -0400
|
||||
|
||||
ccache (2.4-1) unstable; urgency=low
|
||||
|
||||
* New maintainer (closes: #312867)
|
||||
* New upstream version: (closes: #273753, #239640)
|
||||
- New CCACHE_READONLY and CCACHE_TEMPDIR options
|
||||
- Fixed handling of hard-linked compilers on AIX
|
||||
- Fixed handling of HOME environment variable (closes: #299880)
|
||||
- Show cache directory in stats output
|
||||
* Fix copyright file
|
||||
* Add 'distcc' to Suggests (closes: #269158)
|
||||
* Add a note about whitespace in README.Debian (closes: #229116)
|
||||
* Update rules to add symmlinks for gcc 3.4 & 4.0 (closes: #261177)
|
||||
* Acknowledge NMUs (closes: #200185, #177129, #174417)
|
||||
|
||||
-- Francois Marier <francois@debian.org> Sun, 12 Jun 2005 12:05:34 -0400
|
||||
|
||||
ccache (2.3-1.1) unstable; urgency=low
|
||||
|
||||
* Non-maintainer upload during BSP
|
||||
* Re-apply patch for
|
||||
#200185 ccache: Incorrect symlinks in /usr/lib/ccache
|
||||
(Closes: #200185)
|
||||
|
||||
-- Frank Lichtenheld <djpig@debian.org> Fri, 19 Mar 2004 11:14:50 +0100
|
||||
|
||||
ccache (2.3-1) unstable; urgency=low
|
||||
|
||||
* New upstream release: obsoletes existing caches.
|
||||
* Tweak package description in arbitrary way (closes: #181721)
|
||||
|
||||
-- Paul Russell <prussell@debian.org> Mon, 29 Sep 2003 02:53:20 +0200
|
||||
|
||||
ccache (2.2-2) unstable; urgency=low
|
||||
|
||||
* Insert more symlinks in ccache dir (closes: #197468)
|
||||
|
||||
-- Paul Russell <prussell@debian.org> Mon, 16 Jun 2003 10:52:50 +0100
|
||||
|
||||
ccache (2.2-1) unstable; urgency=low
|
||||
|
||||
* New upstream release (closes: #150755)
|
||||
* Insert more symlinks in ccache dir (closes: #144462)
|
||||
|
||||
-- Paul Russell <prussell@debian.org> Mon, 17 Feb 2003 07:19:36 +0100
|
||||
|
||||
ccache (2.1.1-2) unstable; urgency=low
|
||||
|
||||
* Restored /usr/lib/ccache symlinks (closes: #179393)
|
||||
* Fixed manpage typo (closes: #179564)
|
||||
* With thanks to Andreas Rottmann.
|
||||
|
||||
-- Paul Russell <prussell@debian.org> Wed, 5 Feb 2003 10:01:10 +0100
|
||||
|
||||
ccache (2.1.1-1) unstable; urgency=low
|
||||
|
||||
* NMU (with maintainer consent).
|
||||
* New upstream release (closes: #174417, #177129).
|
||||
* debian/control:
|
||||
+ Build-Depend on and use dephelper 4 (DH_COMPAT = 4).
|
||||
+ Bumped Standards-Version to 3.5.8.
|
||||
+ No full stop on short package description (fixes linda warning).
|
||||
* debian/copright:
|
||||
+ Make lintian feel comfortable; fixes warnings:
|
||||
- copyright-should-refer-to-common-license-file-for-gpl
|
||||
- copyright-lists-upstream-authors-with-dh_make-boilerplate
|
||||
* Built with g++ 3.2 :-).
|
||||
|
||||
-- Andreas Rottmann <rotty@debian.org> Thu, 16 Jan 2003 11:42:38 +0100
|
||||
|
||||
ccache (1.9-1) unstable; urgency=low
|
||||
|
||||
* New upstream release (closes: #144920)
|
||||
|
||||
-- Paul Russell <prussell@debian.org> Mon, 13 May 2002 10:01:09 +0200
|
||||
|
||||
ccache (1.8-1) unstable; urgency=low
|
||||
|
||||
* New upstream release (closes: #145401)
|
||||
|
||||
-- Paul Russell <prussell@debian.org> Fri, 3 May 2002 02:26:32 +0200
|
||||
|
||||
ccache (1.7-1) unstable; urgency=low
|
||||
|
||||
* New upstream release
|
||||
* Install symlinks in /usr/lib/ccache (closes: #141337)
|
||||
|
||||
-- Paul Russell <prussell@debian.org> Wed, 10 Apr 2002 17:51:21 +0200
|
||||
|
||||
ccache (1.4-1) unstable; urgency=low
|
||||
|
||||
* New upstream release
|
||||
|
||||
-- Paul Russell <prussell@debian.org> Wed, 3 Apr 2002 03:41:46 +0200
|
||||
|
||||
ccache (1.2-1) unstable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
-- Paul Russell <prussell@debian.org> Sun, 31 Mar 2002 14:08:57 +0200
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
6
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
Source: ccache
|
||||
Section: devel
|
||||
Priority: optional
|
||||
Maintainer: Francois Marier <francois@debian.org>
|
||||
Build-Depends: debhelper (>> 6), autotools-dev, zlib1g-dev
|
||||
Standards-Version: 3.7.3
|
||||
Homepage: http://ccache.samba.org
|
||||
Vcs-Svn: svn://svn.debian.org/svn/collab-maint/deb-maint/ccache/
|
||||
Vcs-Browser: http://svn.debian.org/wsvn/collab-maint/deb-maint/ccache/
|
||||
|
||||
Package: ccache
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}
|
||||
Suggests: distcc
|
||||
Description: Compiler results cacher, for fast recompiles
|
||||
ccache is a compiler cache. It speeds up re-compilation of C/C++ code
|
||||
by caching previous compiles and detecting when the same compile is
|
||||
being done again.
|
||||
.
|
||||
This is similar to, but faster than, the compilercache package.
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
This package was debianized by Paul Russell <prussell@debian.org> on
|
||||
Sun, 31 Mar 2002 14:08:57 +0200.
|
||||
|
||||
It was downloaded from http://ccache.samba.org/ftp/ccache/
|
||||
|
||||
The ccache-zlib patch was downloaded from http://www.gustaebel.de/lars/ccache/
|
||||
|
||||
Upstream Author: Andrew Tridgell <tridge@samba.org>
|
||||
|
||||
Copyright: 2002-2005 Andrew Tridgell <tridge@samba.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301, USA
|
||||
|
||||
You are free to distribute this software under the terms of the GNU General
|
||||
Public License. On Debian systems, the complete text of the GNU General
|
||||
Public License can be found in /usr/share/common-licenses/GPL file.
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
usr/bin
|
||||
usr/lib/ccache
|
||||
usr/share/man/man1
|
||||
|
|
@ -1 +0,0 @@
|
|||
README
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
debian/update-ccache
|
||||
manage-cache.sh
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
--- ccache.c
|
||||
+++ ccache.c
|
||||
@@ -836,6 +836,13 @@
|
||||
{
|
||||
/* find the real compiler */
|
||||
find_compiler(argc, argv);
|
||||
+
|
||||
+ /* use the real compiler if HOME is not set */
|
||||
+ if (!cache_dir) {
|
||||
+ cc_log("Unable to determine home directory\n");
|
||||
+ cc_log("ccache is disabled\n");
|
||||
+ failed();
|
||||
+ }
|
||||
|
||||
/* we might be disabled */
|
||||
if (getenv("CCACHE_DISABLE")) {
|
||||
@@ -895,6 +902,13 @@
|
||||
printf("-V print version number\n");
|
||||
}
|
||||
|
||||
+static void check_cache_dir(void)
|
||||
+{
|
||||
+ if (!cache_dir) {
|
||||
+ fatal("Unable to determine home directory");
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
/* the main program when not doing a compile */
|
||||
static int ccache_main(int argc, char *argv[])
|
||||
{
|
||||
@@ -914,31 +928,37 @@
|
||||
exit(0);
|
||||
|
||||
case 's':
|
||||
+ check_cache_dir();
|
||||
stats_summary();
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
+ check_cache_dir();
|
||||
cleanup_all(cache_dir);
|
||||
printf("Cleaned cache\n");
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
+ check_cache_dir();
|
||||
wipe_all(cache_dir);
|
||||
printf("Cleared cache\n");
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
+ check_cache_dir();
|
||||
stats_zero();
|
||||
printf("Statistics cleared\n");
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
+ check_cache_dir();
|
||||
v = atoi(optarg);
|
||||
stats_set_limits(v, -1);
|
||||
printf("Set cache file limit to %u\n", (unsigned)v);
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
+ check_cache_dir();
|
||||
v = value_units(optarg);
|
||||
stats_set_limits(-1, v);
|
||||
printf("Set cache size limit to %uk\n", (unsigned)v);
|
||||
@@ -983,7 +1003,10 @@
|
||||
|
||||
cache_dir = getenv("CCACHE_DIR");
|
||||
if (!cache_dir) {
|
||||
- x_asprintf(&cache_dir, "%s/.ccache", get_home_directory());
|
||||
+ const char *home_directory = get_home_directory();
|
||||
+ if (home_directory) {
|
||||
+ x_asprintf(&cache_dir, "%s/.ccache", home_directory);
|
||||
+ }
|
||||
}
|
||||
|
||||
temp_dir = getenv("CCACHE_TEMPDIR");
|
||||
@@ -1023,7 +1046,7 @@
|
||||
}
|
||||
|
||||
/* make sure the cache dir exists */
|
||||
- if (create_dir(cache_dir) != 0) {
|
||||
+ if (cache_dir && (create_dir(cache_dir) != 0)) {
|
||||
fprintf(stderr,"ccache: failed to create %s (%s)\n",
|
||||
cache_dir, strerror(errno));
|
||||
exit(1);
|
||||
--- util.c
|
||||
+++ util.c
|
||||
@@ -448,7 +448,7 @@
|
||||
}
|
||||
}
|
||||
#endif
|
||||
- fatal("Unable to determine home directory");
|
||||
+ cc_log("Unable to determine home directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,133 +0,0 @@
|
|||
Index: ccache.c
|
||||
===================================================================
|
||||
--- ccache.c (révision 7695)
|
||||
+++ ccache.c (copie de travail)
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
#include "ccache.h"
|
||||
+#include <getopt.h>
|
||||
|
||||
/* the base cache directory */
|
||||
char *cache_dir = NULL;
|
||||
@@ -885,14 +886,14 @@
|
||||
printf("\tcompiler [compile options] (via symbolic link)\n");
|
||||
printf("\nOptions:\n");
|
||||
|
||||
- printf("-s show statistics summary\n");
|
||||
- printf("-z zero statistics\n");
|
||||
- printf("-c run a cache cleanup\n");
|
||||
- printf("-C clear the cache completely\n");
|
||||
- printf("-F <maxfiles> set maximum files in cache\n");
|
||||
- printf("-M <maxsize> set maximum size of cache (use G, M or K)\n");
|
||||
- printf("-h this help page\n");
|
||||
- printf("-V print version number\n");
|
||||
+ printf("-s, --show-stats show statistics summary\n");
|
||||
+ printf("-z, --zero-stats zero statistics\n");
|
||||
+ printf("-c, --cleanup run a cache cleanup\n");
|
||||
+ printf("-C, --clear clear the cache completely\n");
|
||||
+ printf("-F <n>, --max-files=<n> set maximum files in cache\n");
|
||||
+ printf("-M <n>, --max-size=<n> set maximum size of cache (use G, M or K)\n");
|
||||
+ printf("-h, --help this help page\n");
|
||||
+ printf("-V, --version print version number\n");
|
||||
}
|
||||
|
||||
/* the main program when not doing a compile */
|
||||
@@ -901,7 +902,21 @@
|
||||
int c;
|
||||
size_t v;
|
||||
|
||||
- while ((c = getopt(argc, argv, "hszcCF:M:V")) != -1) {
|
||||
+ static struct option long_options[] =
|
||||
+ {
|
||||
+ {"show-stats", no_argument, 0, 's'},
|
||||
+ {"zero-stats", no_argument, 0, 'z'},
|
||||
+ {"cleanup", no_argument, 0, 'c'},
|
||||
+ {"clear", no_argument, 0, 'C'},
|
||||
+ {"max-files", required_argument, 0, 'F'},
|
||||
+ {"max-size", required_argument, 0, 'M'},
|
||||
+ {"help", no_argument, 0, 'h'},
|
||||
+ {"version", no_argument, 0, 'V'},
|
||||
+ {0, 0, 0, 0}
|
||||
+ };
|
||||
+ int option_index = 0;
|
||||
+
|
||||
+ while ((c = getopt_long(argc, argv, "hszcCF:M:V", long_options, &option_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'V':
|
||||
printf("ccache version %s\n", CCACHE_VERSION);
|
||||
Index: ccache.1
|
||||
===================================================================
|
||||
--- ccache.1 (révision 7695)
|
||||
+++ ccache.1 (copie de travail)
|
||||
@@ -23,14 +23,14 @@
|
||||
.nf
|
||||
|
||||
|
||||
--s show statistics summary
|
||||
--z zero statistics
|
||||
--c run a cache cleanup
|
||||
--C clear the cache completely
|
||||
--F <maxfiles> set maximum files in cache
|
||||
--M <maxsize> set maximum size of cache (use G, M or K)
|
||||
--h this help page
|
||||
--V print version number
|
||||
+\-s, \-\-show-stats show statistics summary
|
||||
+\-z, \-\-zero-stats zero statistics
|
||||
+\-c, \-\-cleanup run a cache cleanup
|
||||
+\-C, \-\-clear clear the cache completely
|
||||
+\-F <n>, \-\-max-files=<n> set maximum files in cache
|
||||
+\-M <n>, \-\-max-size=<n> set maximum size of cache (use G, M or K)
|
||||
+\-h, \-\-help this help page
|
||||
+\-V, \-\-version print version number
|
||||
|
||||
.fi
|
||||
|
||||
@@ -43,22 +43,22 @@
|
||||
normal compiler options apply and you should refer to your compilers
|
||||
documentation\&.
|
||||
.PP
|
||||
-.IP "\fB-h\fP"
|
||||
+.IP "\fB-h, --help\fP"
|
||||
Print a options summary page
|
||||
.IP
|
||||
-.IP "\fB-s\fP"
|
||||
+.IP "\fB-s, --show-stats\fP"
|
||||
Print the current statistics summary for the cache\&. The
|
||||
statistics are stored spread across the subdirectories of the
|
||||
cache\&. Using "ccache -s" adds up the statistics across all
|
||||
subdirectories and prints the totals\&.
|
||||
.IP
|
||||
-.IP "\fB-z\fP"
|
||||
+.IP "\fB-z, --zero-stats\fP"
|
||||
Zero the cache statistics\&.
|
||||
.IP
|
||||
-.IP "\fB-V\fP"
|
||||
+.IP "\fB-V, --version\fP"
|
||||
Print the ccache version number
|
||||
.IP
|
||||
-.IP "\fB-c\fP"
|
||||
+.IP "\fB-c, --cleanup\fP"
|
||||
Clean the cache and re-calculate the cache file count and
|
||||
size totals\&. Normally the -c option should not be necessary as ccache
|
||||
keeps the cache below the specified limits at runtime and keeps
|
||||
@@ -66,16 +66,16 @@
|
||||
if you manually modify the cache contents or believe that the cache
|
||||
size statistics may be inaccurate\&.
|
||||
.IP
|
||||
-.IP "\fB-C\fP"
|
||||
+.IP "\fB-C, --clear\fP"
|
||||
Clear the entire cache, removing all cached files\&.
|
||||
.IP
|
||||
-.IP "\fB-F maxfiles\fP"
|
||||
+.IP "\fB-F <maxfiles>, --max-files=<maxfiles>\fP"
|
||||
This sets the maximum number of files allowed in
|
||||
the cache\&. The value is stored inside the cache directory and applies
|
||||
to all future compiles\&. Due to the way the value is stored the actual
|
||||
value used is always rounded down to the nearest multiple of 16\&.
|
||||
.IP
|
||||
-.IP "\fB-M maxsize\fP"
|
||||
+.IP "\fB-M <maxsize>, --max-size=<maxsize>\fP"
|
||||
This sets the maximum cache size\&. You can specify
|
||||
a value in gigabytes, megabytes or kilobytes by appending a G, M or K
|
||||
to the value\&. The default is gigabytes\&. The actual value stored is
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
diff -ru ccache-2.4/ccache.c ccache-2.4-tp/ccache.c
|
||||
--- ccache.c 2007-05-20 03:14:19.000000000 +1000
|
||||
+++ ccache.c 2007-05-20 03:17:54.000000000 +1000
|
||||
@@ -641,6 +641,9 @@
|
||||
|
||||
/* these are too hard */
|
||||
if (strcmp(argv[i], "-fbranch-probabilities")==0 ||
|
||||
+ strcmp(argv[i], "-fprofile-arcs") == 0 ||
|
||||
+ strcmp(argv[i], "-ftest-coverage") == 0 ||
|
||||
+ strcmp(argv[i], "--coverage") == 0 ||
|
||||
strcmp(argv[i], "-M") == 0 ||
|
||||
strcmp(argv[i], "-MM") == 0 ||
|
||||
strcmp(argv[i], "-x") == 0) {
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
--- ccache.1.orig 2007-05-20 17:30:57.000000000 +1200
|
||||
+++ ccache.1 2007-05-20 17:31:27.000000000 +1200
|
||||
@@ -367,12 +367,6 @@
|
||||
.IP o
|
||||
ccache avoids a double call to cpp on a cache miss
|
||||
.PP
|
||||
-.SH "BUGS"
|
||||
-.PP
|
||||
-When the cache is stored on an NFS filesystem, the filesystem must be
|
||||
-exported with the \fBno_subtree_check\fP option to make renames between
|
||||
-directories reliable\&.
|
||||
-.PP
|
||||
.SH "CREDITS"
|
||||
.PP
|
||||
Thanks to the following people for their contributions to ccache
|
||||
--- util.c.patched 2007-05-20 18:19:11.000000000 +1200
|
||||
+++ util.c 2007-05-20 18:20:55.000000000 +1200
|
||||
@@ -58,9 +58,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
+static int safe_rename(const char* oldpath, const char* newpath)
|
||||
+{
|
||||
+ /* safe_rename is for creating entries in the cache.
|
||||
+
|
||||
+ Works like rename(), but it never overwrites an existing
|
||||
+ cache entry. This avoids corruption on NFS. */
|
||||
+ int status = link( oldpath, newpath );
|
||||
+ if( status == 0 || errno == EEXIST )
|
||||
+ {
|
||||
+ return unlink( oldpath );
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ return -1;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
/* move a file using rename */
|
||||
int move_file(const char *src, const char *dest) {
|
||||
- return rename(src, dest);
|
||||
+ return safe_rename(src, dest);
|
||||
}
|
||||
|
||||
/* copy a file - used when hard links don't work
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
--- ccache.c Mon Sep 13 11:38:30 2004
|
||||
+++ ccache.c Thu Jun 21 22:17:32 2007
|
||||
@@ -627,6 +627,13 @@ static void process_args(int argc, char
|
||||
int found_S_opt = 0;
|
||||
struct stat st;
|
||||
char *e;
|
||||
+ /* is gcc being asked to output dependencies? */
|
||||
+ int generating_dependencies = 0;
|
||||
+ /* is the dependency makefile name overridden with -MF? */
|
||||
+ int dependency_filename_specified = 0;
|
||||
+ /* is the dependency makefile target name specified with -MQ or -MF? */
|
||||
+ int dependency_target_specified = 0;
|
||||
+
|
||||
|
||||
stripped_args = args_init(0, NULL);
|
||||
|
||||
@@ -702,6 +709,18 @@ static void process_args(int argc, char
|
||||
continue;
|
||||
}
|
||||
|
||||
+ /* These options require special handling, because they
|
||||
+ behave differently with gcc -E, when the output
|
||||
+ file is not specified. */
|
||||
+
|
||||
+ if (strcmp(argv[i], "-MD") == 0 || strcmp(argv[i], "-MMD") == 0) {
|
||||
+ generating_dependencies = 1;
|
||||
+ } else if (strcmp(argv[i], "-MF") == 0) {
|
||||
+ dependency_filename_specified = 1;
|
||||
+ } else if (strcmp(argv[i], "-MQ") == 0 || strcmp(argv[i], "-MT") == 0) {
|
||||
+ dependency_target_specified = 1;
|
||||
+ }
|
||||
+
|
||||
/* options that take an argument */
|
||||
{
|
||||
const char *opts[] = {"-I", "-include", "-imacros", "-iprefix",
|
||||
@@ -812,6 +831,41 @@ static void process_args(int argc, char
|
||||
}
|
||||
p[1] = found_S_opt ? 's' : 'o';
|
||||
p[2] = 0;
|
||||
+ }
|
||||
+
|
||||
+ /* If dependencies are generated, configure the preprocessor */
|
||||
+
|
||||
+ if (generating_dependencies && output_file) {
|
||||
+ if (!dependency_filename_specified) {
|
||||
+ char *default_depfile_name = x_strdup(output_file);
|
||||
+ char *p = strrchr(default_depfile_name, '.');
|
||||
+
|
||||
+ if (p) {
|
||||
+ if (strlen(p) < 2) {
|
||||
+ stats_update(STATS_ARGS);
|
||||
+ failed();
|
||||
+ return;
|
||||
+ }
|
||||
+ *p = 0;
|
||||
+ }
|
||||
+ else {
|
||||
+ int len = p - default_depfile_name;
|
||||
+
|
||||
+ p = x_malloc(len + 3);
|
||||
+ strncpy(default_depfile_name, p, len - 1);
|
||||
+ free(default_depfile_name);
|
||||
+ default_depfile_name = p;
|
||||
+ }
|
||||
+
|
||||
+ strcat(default_depfile_name, ".d");
|
||||
+ args_add(stripped_args, "-MF");
|
||||
+ args_add(stripped_args, default_depfile_name);
|
||||
+ }
|
||||
+
|
||||
+ if (!dependency_target_specified) {
|
||||
+ args_add(stripped_args, "-MT");
|
||||
+ args_add(stripped_args, output_file);
|
||||
+ }
|
||||
}
|
||||
|
||||
/* cope with -o /dev/null */
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
Index: ccache.c
|
||||
===================================================================
|
||||
--- ccache.c (révision 7695)
|
||||
+++ ccache.c (copie de travail)
|
||||
@@ -1029,6 +1029,14 @@
|
||||
exit(1);
|
||||
}
|
||||
|
||||
+ if (!getenv("CCACHE_READONLY")) {
|
||||
+ if (create_cachedirtag(cache_dir) != 0) {
|
||||
+ fprintf(stderr,"ccache: failed to create %s/CACHEDIR.TAG (%s)\n",
|
||||
+ cache_dir, strerror(errno));
|
||||
+ exit(1);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
ccache(argc, argv);
|
||||
return 1;
|
||||
}
|
||||
Index: ccache.h
|
||||
===================================================================
|
||||
--- ccache.h (révision 7695)
|
||||
+++ ccache.h (copie de travail)
|
||||
@@ -81,6 +81,7 @@
|
||||
int copy_file(const char *src, const char *dest);
|
||||
|
||||
int create_dir(const char *dir);
|
||||
+int create_cachedirtag(const char *dir);
|
||||
void x_asprintf(char **ptr, const char *format, ...);
|
||||
char *x_strdup(const char *s);
|
||||
void *x_realloc(void *ptr, size_t size);
|
||||
Index: util.c
|
||||
===================================================================
|
||||
--- util.c (révision 7695)
|
||||
+++ util.c (copie de travail)
|
||||
@@ -138,6 +138,39 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
+char const CACHEDIR_TAG[] =
|
||||
+ "Signature: 8a477f597d28d172789f06886806bc55\n"
|
||||
+ "# This file is a cache directory tag created by ccache.\n"
|
||||
+ "# For information about cache directory tags, see:\n"
|
||||
+ "# http://www.brynosaurus.com/cachedir/\n";
|
||||
+
|
||||
+int create_cachedirtag(const char *dir)
|
||||
+{
|
||||
+ char *filename;
|
||||
+ struct stat st;
|
||||
+ FILE *f;
|
||||
+ x_asprintf(&filename, "%s/CACHEDIR.TAG", dir);
|
||||
+ if (stat(filename, &st) == 0) {
|
||||
+ if (S_ISREG(st.st_mode)) {
|
||||
+ goto success;
|
||||
+ }
|
||||
+ errno = EEXIST;
|
||||
+ goto error;
|
||||
+ }
|
||||
+ f = fopen(filename, "w");
|
||||
+ if (!f) goto error;
|
||||
+ if (fwrite(CACHEDIR_TAG, sizeof(CACHEDIR_TAG)-1, 1, f) != 1) {
|
||||
+ goto error;
|
||||
+ }
|
||||
+ if (fclose(f)) goto error;
|
||||
+success:
|
||||
+ free(filename);
|
||||
+ return 0;
|
||||
+error:
|
||||
+ free(filename);
|
||||
+ return 1;
|
||||
+}
|
||||
+
|
||||
/*
|
||||
this is like asprintf() but dies if the malloc fails
|
||||
note that we use vsnprintf in a rather poor way to make this more portable
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
Index: ccache.1
|
||||
===================================================================
|
||||
--- ccache.1 (révision 7695)
|
||||
+++ ccache.1 (copie de travail)
|
||||
@@ -49,7 +49,7 @@
|
||||
.IP "\fB-s\fP"
|
||||
Print the current statistics summary for the cache\&. The
|
||||
statistics are stored spread across the subdirectories of the
|
||||
-cache\&. Using "ccache -s" adds up the statistics across all
|
||||
+cache\&. Using "ccache \-s" adds up the statistics across all
|
||||
subdirectories and prints the totals\&.
|
||||
.IP
|
||||
.IP "\fB-z\fP"
|
||||
@@ -60,7 +60,7 @@
|
||||
.IP
|
||||
.IP "\fB-c\fP"
|
||||
Clean the cache and re-calculate the cache file count and
|
||||
-size totals\&. Normally the -c option should not be necessary as ccache
|
||||
+size totals\&. Normally the \-c option should not be necessary as ccache
|
||||
keeps the cache below the specified limits at runtime and keeps
|
||||
statistics up to date on each compile\&. This option is mostly useful
|
||||
if you manually modify the cache contents or believe that the cache
|
||||
@@ -100,9 +100,9 @@
|
||||
|
||||
|
||||
cp ccache /usr/local/bin/
|
||||
- ln -s /usr/local/bin/ccache /usr/local/bin/gcc
|
||||
- ln -s /usr/local/bin/ccache /usr/local/bin/g++
|
||||
- ln -s /usr/local/bin/ccache /usr/local/bin/cc
|
||||
+ ln \-s /usr/local/bin/ccache /usr/local/bin/gcc
|
||||
+ ln \-s /usr/local/bin/ccache /usr/local/bin/g++
|
||||
+ ln \-s /usr/local/bin/ccache /usr/local/bin/cc
|
||||
|
||||
.fi
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
.PP
|
||||
When run as a compiler front end ccache usually just takes the same
|
||||
command line options as the compiler you are using\&. The only exception
|
||||
-to this is the option \&'--ccache-skip\&'\&. That option can be used to tell
|
||||
+to this is the option \&'\-\-ccache-skip\&'\&. That option can be used to tell
|
||||
ccache that the next option is definitely not a input filename, and
|
||||
should be passed along to the compiler as-is\&.
|
||||
.PP
|
||||
@@ -128,7 +128,7 @@
|
||||
of the resulting object file (among other things)\&. The heuristic
|
||||
ccache uses in this parse is that any string on the command line that
|
||||
exists as a file is treated as an input file name (usually a C
|
||||
-file)\&. By using --ccache-skip you can force an option to not be
|
||||
+file)\&. By using \-\-ccache-skip you can force an option to not be
|
||||
treated as an input file name and instead be passed along to the
|
||||
compiler as a command line option\&.
|
||||
.PP
|
||||
@@ -238,7 +238,7 @@
|
||||
.IP "\fBCCACHE_UNIFY\fP"
|
||||
If you set the environment variable CCACHE_UNIFY
|
||||
then ccache will use the C/C++ unifier when hashing the pre-processor
|
||||
-output if -g is not used in the compile\&. The unifier is slower than a
|
||||
+output if \-g is not used in the compile\&. The unifier is slower than a
|
||||
normal hash, so setting this environment variable loses a little bit
|
||||
of speed, but it means that ccache can take advantage of not
|
||||
recompiling when the changes to the source code consist of
|
||||
@@ -262,7 +262,7 @@
|
||||
.PP
|
||||
By default ccache has a one gigabyte limit on the cache size and no
|
||||
maximum number of files\&. You can set a different limit using the
|
||||
-"ccache -M" and "ccache -F" options, which set the size and number of
|
||||
+"ccache \-M" and "ccache \-F" options, which set the size and number of
|
||||
files limits\&.
|
||||
.PP
|
||||
When these limits are reached ccache will reduce the cache to 20%
|
||||
@@ -276,7 +276,7 @@
|
||||
that it is the same code by forming a hash of:
|
||||
.PP
|
||||
.IP o
|
||||
-the pre-processor output from running the compiler with -E
|
||||
+the pre-processor output from running the compiler with \-E
|
||||
.IP o
|
||||
the command line options
|
||||
.IP o
|
||||
@@ -331,7 +331,7 @@
|
||||
.IP o
|
||||
Make sure that the setgid bit is set on all directories in the
|
||||
cache\&. This tells the filesystem to inherit group ownership for new
|
||||
-directories\&. The command "chmod g+s `find $CCACHE_DIR -type d`" might
|
||||
+directories\&. The command "chmod g+s `find $CCACHE_DIR \-type d`" might
|
||||
be useful for this\&.
|
||||
.PP
|
||||
.SH "HISTORY"
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
--- Makefile.in.orig 2008-03-23 17:01:19.000000000 +1300
|
||||
+++ Makefile.in 2008-03-23 17:03:03.000000000 +1300
|
||||
@@ -21,7 +21,7 @@
|
||||
docs: ccache.1 web/ccache-man.html
|
||||
|
||||
ccache$(EXEEXT): $(OBJS) $(HEADERS)
|
||||
- $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||
|
||||
ccache.1: ccache.yo
|
||||
-yodl2man -o ccache.1 ccache.yo
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
--- ccache.c (révision 8804)
|
||||
+++ ccache.c (copie de travail)
|
||||
@@ -481,6 +481,9 @@
|
||||
return;
|
||||
}
|
||||
|
||||
+ /* update timestamps for LRU cleanup
|
||||
+ also gives output_file a sensible mtime when hard-linking (for make) */
|
||||
+ utime(hashname, NULL);
|
||||
utime(stderr_file, NULL);
|
||||
|
||||
if (strcmp(output_file, "/dev/null") == 0) {
|
||||
@@ -513,10 +516,6 @@
|
||||
failed();
|
||||
}
|
||||
}
|
||||
- if (ret == 0) {
|
||||
- /* update the mtime on the file so that make doesn't get confused */
|
||||
- utime(output_file, NULL);
|
||||
- }
|
||||
|
||||
/* get rid of the intermediate preprocessor file */
|
||||
if (i_tmpfile) {
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
--- ccache.c 2004-09-13 03:38:30.000000000 -0700
|
||||
+++ ccache.c 2006-06-09 16:29:16.695117780 -0700
|
||||
@@ -481,8 +481,13 @@
|
||||
|
||||
/* update timestamps for LRU cleanup
|
||||
also gives output_file a sensible mtime when hard-linking (for make) */
|
||||
+#ifdef HAVE_UTIMES
|
||||
+ utimes(hashname, NULL);
|
||||
+ utimes(stderr_file, NULL);
|
||||
+#else
|
||||
utime(hashname, NULL);
|
||||
utime(stderr_file, NULL);
|
||||
+#endif
|
||||
|
||||
if (strcmp(output_file, "/dev/null") == 0) {
|
||||
ret = 0;
|
||||
--- ccache.h 2004-09-13 03:38:30.000000000 -0700
|
||||
+++ ccache.h 2006-06-09 16:28:16.601658626 -0700
|
||||
@@ -22,6 +22,9 @@
|
||||
#ifdef HAVE_PWD_H
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
+#ifdef HAVE_SYS_TIME_H
|
||||
+#include <sys/time.h>
|
||||
+#endif
|
||||
|
||||
#define STATUS_NOTFOUND 3
|
||||
#define STATUS_FATAL 4
|
||||
--- config.h.in 2003-09-27 21:48:17.000000000 -0700
|
||||
+++ config.h.in 2006-06-09 16:25:43.000000000 -0700
|
||||
@@ -19,6 +19,9 @@
|
||||
/* Define to 1 if you have the `gethostname' function. */
|
||||
#undef HAVE_GETHOSTNAME
|
||||
|
||||
+/* Define to 1 if you have the `getpwuid' function. */
|
||||
+#undef HAVE_GETPWUID
|
||||
+
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
@@ -31,6 +34,9 @@
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
#undef HAVE_NDIR_H
|
||||
|
||||
+/* Define to 1 if you have the <pwd.h> header file. */
|
||||
+#undef HAVE_PWD_H
|
||||
+
|
||||
/* Define to 1 if you have the `realpath' function. */
|
||||
#undef HAVE_REALPATH
|
||||
|
||||
@@ -60,6 +66,9 @@
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
+/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
+#undef HAVE_SYS_TIME_H
|
||||
+
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
@@ -69,6 +78,9 @@
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
+/* Define to 1 if you have the `utimes' function. */
|
||||
+#undef HAVE_UTIMES
|
||||
+
|
||||
/* Define to 1 if you have the `vasprintf' function. */
|
||||
#undef HAVE_VASPRINTF
|
||||
|
||||
--- configure.in 2004-09-13 03:38:30.000000000 -0700
|
||||
+++ configure.in 2006-06-09 16:25:15.541288184 -0700
|
||||
@@ -27,10 +27,11 @@
|
||||
AC_HEADER_TIME
|
||||
AC_HEADER_SYS_WAIT
|
||||
|
||||
-AC_CHECK_HEADERS(ctype.h strings.h stdlib.h string.h pwd.h)
|
||||
+AC_CHECK_HEADERS(ctype.h strings.h stdlib.h string.h pwd.h sys/time.h)
|
||||
|
||||
AC_CHECK_FUNCS(realpath snprintf vsnprintf vasprintf asprintf mkstemp)
|
||||
AC_CHECK_FUNCS(gethostname getpwuid)
|
||||
+AC_CHECK_FUNCS(utimes)
|
||||
|
||||
AC_CACHE_CHECK([for compar_fn_t in stdlib.h],ccache_cv_COMPAR_FN_T, [
|
||||
AC_TRY_COMPILE(
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
--- stats.c (révision 8804)
|
||||
+++ stats.c (copie de travail)
|
||||
@@ -286,7 +286,7 @@
|
||||
|
||||
|
||||
/* set the per directory limits */
|
||||
-void stats_set_limits(long maxfiles, long maxsize)
|
||||
+int stats_set_limits(long maxfiles, long maxsize)
|
||||
{
|
||||
int dir;
|
||||
unsigned counters[STATS_END];
|
||||
@@ -298,7 +298,9 @@
|
||||
maxsize /= 16;
|
||||
}
|
||||
|
||||
- create_dir(cache_dir);
|
||||
+ if (create_dir(cache_dir) != 0) {
|
||||
+ return 1;
|
||||
+ }
|
||||
|
||||
/* set the limits in each directory */
|
||||
for (dir=0;dir<=0xF;dir++) {
|
||||
@@ -306,7 +308,9 @@
|
||||
int fd;
|
||||
|
||||
x_asprintf(&cdir, "%s/%1x", cache_dir, dir);
|
||||
- create_dir(cdir);
|
||||
+ if (create_dir(cdir) != 0) {
|
||||
+ return 1;
|
||||
+ }
|
||||
x_asprintf(&fname, "%s/stats", cdir);
|
||||
free(cdir);
|
||||
|
||||
@@ -326,6 +330,8 @@
|
||||
}
|
||||
free(fname);
|
||||
}
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
/* set the per directory sizes */
|
||||
--- ccache.c (révision 8804)
|
||||
+++ ccache.c (copie de travail)
|
||||
@@ -935,15 +934,23 @@
|
||||
case 'F':
|
||||
check_cache_dir();
|
||||
v = atoi(optarg);
|
||||
- stats_set_limits(v, -1);
|
||||
- printf("Set cache file limit to %u\n", (unsigned)v);
|
||||
+ if (stats_set_limits(v, -1) == 0) {
|
||||
+ printf("Set cache file limit to %u\n", (unsigned)v);
|
||||
+ } else {
|
||||
+ printf("Could not set cache file limit.\n");
|
||||
+ exit(1);
|
||||
+ }
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
check_cache_dir();
|
||||
v = value_units(optarg);
|
||||
- stats_set_limits(-1, v);
|
||||
- printf("Set cache size limit to %uk\n", (unsigned)v);
|
||||
+ if (stats_set_limits(-1, v) == 0) {
|
||||
+ printf("Set cache size limit to %uk\n", (unsigned)v);
|
||||
+ } else {
|
||||
+ printf("Could not set cache size limit.\n");
|
||||
+ exit(1);
|
||||
+ }
|
||||
break;
|
||||
|
||||
default:
|
||||
--- ccache.h (révision 8804)
|
||||
+++ ccache.h (copie de travail)
|
||||
@@ -101,7 +101,7 @@
|
||||
void stats_summary(void);
|
||||
void stats_tocache(size_t size);
|
||||
void stats_read(const char *stats_file, unsigned counters[STATS_END]);
|
||||
-void stats_set_limits(long maxfiles, long maxsize);
|
||||
+int stats_set_limits(long maxfiles, long maxsize);
|
||||
size_t value_units(const char *s);
|
||||
void display_size(unsigned v);
|
||||
void stats_set_sizes(const char *dir, size_t num_files, size_t total_size);
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
--- web/index.html~ 2004-09-13 13:38:30.000000000 +0300
|
||||
+++ web/index.html 2004-09-26 01:04:38.458008118 +0300
|
||||
@@ -29,10 +29,10 @@
|
||||
<li>fixed handling of HOME environment variable
|
||||
</ul>
|
||||
|
||||
-See the <a href="/ccache/ccache-man.html">manual page</a> for details
|
||||
+See the <a href="ccache-man.html">manual page</a> for details
|
||||
on the new options.<p>
|
||||
|
||||
-You can get this release from the <a href="/ftp/ccache/">download directory</a>
|
||||
+You can get this release from the <a href="http://ccache.samba.org/ftp/ccache/">download directory</a>
|
||||
|
||||
<p>NOTE! This release changes the hash input slighly, so you will
|
||||
probably find that you will not get any hits against your existing
|
||||
@@ -87,7 +87,7 @@
|
||||
|
||||
<h2>Documentation</h2>
|
||||
|
||||
-See the <a href="/ccache/ccache-man.html">manual page</a>
|
||||
+See the <a href="ccache-man.html">manual page</a>
|
||||
|
||||
|
||||
<h2>Performance</h2>
|
||||
@@ -116,7 +116,7 @@
|
||||
<h2>Download</h2>
|
||||
|
||||
You can download the latest release from the <a
|
||||
-href="/ftp/ccache/">download directory</a>.<p>
|
||||
+href="http://ccache.samba.org/ftp/ccache/">download directory</a>.<p>
|
||||
|
||||
For the bleeding edge, you can fetch ccache via CVS or
|
||||
rsync. To fetch via cvs use the following command:
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
Index: ccache.1
|
||||
===================================================================
|
||||
RCS file: /cvsroot/ccache/ccache.1,v
|
||||
retrieving revision 1.26
|
||||
diff -u -r1.26 ccache.1
|
||||
--- ccache.1 24 Nov 2005 21:10:08 -0000 1.26
|
||||
+++ ccache.1 21 Jul 2007 21:03:32 -0000
|
||||
@@ -330,7 +330,7 @@
|
||||
.IP o
|
||||
Use the same \fBCCACHE_DIR\fP environment variable setting
|
||||
.IP o
|
||||
-Set the \fBCCACHE_NOLINK\fP environment variable
|
||||
+Unset the \fBCCACHE_HARDLINK\fP environment variable
|
||||
.IP o
|
||||
Make sure everyone sets the CCACHE_UMASK environment variable
|
||||
to 002, this ensures that cached files are accessible to everyone in
|
||||
Index: ccache.yo
|
||||
===================================================================
|
||||
RCS file: /cvsroot/ccache/ccache.yo,v
|
||||
retrieving revision 1.27
|
||||
diff -u -r1.27 ccache.yo
|
||||
--- ccache.yo 24 Nov 2005 21:54:09 -0000 1.27
|
||||
+++ ccache.yo 21 Jul 2007 21:03:32 -0000
|
||||
@@ -289,7 +289,7 @@
|
||||
|
||||
itemize(
|
||||
it() Use the same bf(CCACHE_DIR) environment variable setting
|
||||
- it() Set the bf(CCACHE_NOLINK) environment variable
|
||||
+ it() Unset the bf(CCACHE_HARDLINK) environment variable
|
||||
it() Make sure everyone sets the CCACHE_UMASK environment variable
|
||||
to 002, this ensures that cached files are accessible to everyone in
|
||||
the group.
|
||||
Index: web/ccache-man.html
|
||||
===================================================================
|
||||
RCS file: /cvsroot/ccache/web/ccache-man.html,v
|
||||
retrieving revision 1.25
|
||||
diff -u -r1.25 ccache-man.html
|
||||
--- web/ccache-man.html 13 Sep 2004 10:38:17 -0000 1.25
|
||||
+++ web/ccache-man.html 21 Jul 2007 21:03:32 -0000
|
||||
@@ -256,7 +256,7 @@
|
||||
following conditions need to be met:
|
||||
<p><ul>
|
||||
<li > Use the same <strong>CCACHE_DIR</strong> environment variable setting
|
||||
- <li > Set the <strong>CCACHE_NOLINK</strong> environment variable
|
||||
+ <li > Unset the <strong>CCACHE_HARDLINK</strong> environment variable
|
||||
<li > Make sure everyone sets the CCACHE_UMASK environment variable
|
||||
to 002, this ensures that cached files are accessible to everyone in
|
||||
the group.
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
01_no_home.diff:
|
||||
Francois Marier <francois@debian.org>
|
||||
Made especially for the Debian package.
|
||||
|
||||
02_ccache_compressed.diff:
|
||||
Lars Gustäbel <lars@gustaebel.de>
|
||||
http://www.gustaebel.de/lars/ccache/ (downloaded on 2007-05-20)
|
||||
|
||||
03_long_options.diff:
|
||||
Francois Marier <francois@debian.org>
|
||||
Made especially for the Debian package.
|
||||
|
||||
04_ignore_profile.diff:
|
||||
Ted Percival <ted@midg3t.net>
|
||||
http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=20;filename=ccache-profile.patch;att=1;bug=215849
|
||||
|
||||
05_nfs_fix.diff:
|
||||
John Coiner <john.coiner@amd.com>
|
||||
http://lists.samba.org/archive/ccache/2007q1/000265.html
|
||||
|
||||
06_md.diff:
|
||||
Andrea Bittau <a.bittau@cs.ucl.ac.uk>
|
||||
http://darkircop.org/ccache/ccache-2.4-md.patch (downloaded on 2007-06-30)
|
||||
|
||||
07_cachedirtag.diff:
|
||||
Karl Chen <quarl@cs.berkeley.edu>
|
||||
http://lists.samba.org/archive/ccache/2008q1/000316.html (downloaded on 2008-02-02)
|
||||
|
||||
08_manpage_hyphens.diff:
|
||||
Francois Marier <francois@debian.org>
|
||||
Made especially for the Debian package.
|
||||
|
||||
09_respect_ldflags.diff:
|
||||
Lisa Seelye <lisa@gentoo.org>
|
||||
http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-util/ccache/files/ccache-2.4-respectflags.patch?rev=1.1&view=markup
|
||||
|
||||
10_lru_cleanup.diff:
|
||||
RW <fbsd06@mlists.homeunix.com>
|
||||
http://lists.samba.org/archive/ccache/2008q2/000339.html (downloaded on 2008-04-11)
|
||||
|
||||
11_utimes.diff:
|
||||
Robin H. Johnson <robbat2@gentoo.org>
|
||||
http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-util/ccache/files/ccache-2.4-utimes.patch?rev=1.1&view=markup
|
||||
|
||||
12_cachesize_permissions.diff:
|
||||
Francois Marier <francois@debian.org>
|
||||
Made especially for the Debian package to fix http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=332527
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
#!/usr/bin/make -f
|
||||
# Sample debian/rules that uses debhelper.
|
||||
# GNU copyright 1997 to 1999 by Joey Hess.
|
||||
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
|
||||
# These are used for cross-compiling and for saving the configure script
|
||||
# from having to guess our platform (since we know it already)
|
||||
export DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
|
||||
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
|
||||
|
||||
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
|
||||
confflags += --build $(DEB_HOST_GNU_TYPE)
|
||||
else
|
||||
confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
|
||||
CFLAGS += -g
|
||||
endif
|
||||
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
|
||||
INSTALL_PROGRAM += -s
|
||||
endif
|
||||
|
||||
config.status: configure
|
||||
dh_testdir
|
||||
|
||||
# Apply Debian specific patches
|
||||
cp $(CURDIR)/ccache.c $(CURDIR)/ccache.c.unpatched
|
||||
cp $(CURDIR)/util.c $(CURDIR)/util.c.unpatched
|
||||
cp $(CURDIR)/ccache.1 $(CURDIR)/ccache.1.unpatched
|
||||
cp $(CURDIR)/ccache.h $(CURDIR)/ccache.h.unpatched
|
||||
cp $(CURDIR)/ccache.yo $(CURDIR)/ccache.yo.unpatched
|
||||
cp $(CURDIR)/config.h.in $(CURDIR)/config.h.in.unpatched
|
||||
cp $(CURDIR)/configure $(CURDIR)/configure.unpatched
|
||||
cp $(CURDIR)/configure.in $(CURDIR)/configure.in.unpatched
|
||||
cp $(CURDIR)/Makefile.in $(CURDIR)/Makefile.in.unpatched
|
||||
if test ! -f patch-stamp; then \
|
||||
for patch in $(CURDIR)/debian/patches/*.diff ;\
|
||||
do \
|
||||
echo APPLYING PATCH\: $${patch##*/};\
|
||||
patch -p0 < $$patch ;\
|
||||
done ;\
|
||||
touch patch-stamp ;\
|
||||
fi
|
||||
chmod +x $(CURDIR)/manage-cache.sh
|
||||
|
||||
./configure $(confflags) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info
|
||||
|
||||
build: build-stamp
|
||||
|
||||
build-stamp: config.status
|
||||
dh_testdir
|
||||
|
||||
$(MAKE)
|
||||
|
||||
touch build-stamp
|
||||
|
||||
clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
rm -f build-stamp
|
||||
|
||||
# Unapply patches
|
||||
-test -r $(CURDIR)/ccache.c.unpatched && mv $(CURDIR)/ccache.c.unpatched $(CURDIR)/ccache.c
|
||||
-test -r $(CURDIR)/util.c.unpatched && mv $(CURDIR)/util.c.unpatched $(CURDIR)/util.c
|
||||
-test -r $(CURDIR)/ccache.1.unpatched && mv $(CURDIR)/ccache.1.unpatched $(CURDIR)/ccache.1
|
||||
-test -r $(CURDIR)/ccache.h.unpatched && mv $(CURDIR)/ccache.h.unpatched $(CURDIR)/ccache.h
|
||||
-test -r $(CURDIR)/ccache.yo.unpatched && mv $(CURDIR)/ccache.yo.unpatched $(CURDIR)/ccache.yo
|
||||
-test -r $(CURDIR)/config.h.in.unpatched && mv $(CURDIR)/config.h.in.unpatched $(CURDIR)/config.h.in
|
||||
-test -r $(CURDIR)/configure.unpatched && mv $(CURDIR)/configure.unpatched $(CURDIR)/configure
|
||||
-test -r $(CURDIR)/configure.in.unpatched && mv $(CURDIR)/configure.in.unpatched $(CURDIR)/configure.in
|
||||
-test -r $(CURDIR)/Makefile.in.unpatched && mv $(CURDIR)/Makefile.in.unpatched $(CURDIR)/Makefile.in
|
||||
-rm -f $(CURDIR)/manage-cache.sh
|
||||
-rm -f patch-stamp
|
||||
|
||||
[ ! -f Makefile ] || $(MAKE) distclean
|
||||
|
||||
dh_clean
|
||||
|
||||
# Update config.sub and config.guess
|
||||
-test -r /usr/share/misc/config.sub && \
|
||||
cp -f /usr/share/misc/config.sub config.sub
|
||||
-test -r /usr/share/misc/config.guess && \
|
||||
cp -f /usr/share/misc/config.guess config.guess
|
||||
|
||||
|
||||
install: build
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_clean -k
|
||||
dh_installdirs
|
||||
|
||||
# Add here commands to install the package into debian/ccache.
|
||||
$(MAKE) install prefix=$(CURDIR)/debian/ccache/usr
|
||||
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/$(DEB_BUILD_GNU_TYPE)-gcc
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/$(DEB_BUILD_GNU_TYPE)-g++
|
||||
set -e; for ver in 2.95 3.0 3.2 3.3 3.4 4.0 4.1 4.2 4.3; do \
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/$(DEB_BUILD_GNU_TYPE)-gcc-$$ver; \
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/gcc-$$ver; \
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/$(DEB_BUILD_GNU_TYPE)-g++-$$ver; \
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/g++-$$ver; \
|
||||
done
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/cc
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/c++
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/gcc
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/g++
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/i586-mingw32msvc-c++
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/i586-mingw32msvc-cc
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/i586-mingw32msvc-g++
|
||||
ln -s ../../bin/ccache $(CURDIR)/debian/ccache/usr/lib/ccache/i586-mingw32msvc-gcc
|
||||
|
||||
# Build architecture-independent files here.
|
||||
binary-indep: build install
|
||||
# We have nothing to do by default.
|
||||
|
||||
# Build architecture-dependent files here.
|
||||
binary-arch: build install
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installdocs
|
||||
dh_installexamples
|
||||
dh_installmenu
|
||||
dh_installcron
|
||||
dh_installman
|
||||
dh_installinfo
|
||||
dh_installchangelogs
|
||||
dh_link
|
||||
dh_strip
|
||||
dh_compress
|
||||
dh_fixperms
|
||||
dh_installdeb
|
||||
dh_shlibdeps
|
||||
dh_gencontrol
|
||||
dh_md5sums
|
||||
dh_builddeb
|
||||
|
||||
binary: binary-indep binary-arch
|
||||
.PHONY: build clean binary-indep binary-arch binary install
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Update compiler links to ccache (in /usr/local/bin)
|
||||
#
|
||||
# The idea is that /usr/local/bin is ahead of /usr/bin in your PATH, so adding
|
||||
# the link /usr/local/bin/cc -> /usr/bin/ccache means that it is run instead of
|
||||
# /usr/bin/cc
|
||||
#
|
||||
# Written by: Behan Webster <behanw@websterwood.com>
|
||||
#
|
||||
|
||||
DIRECTORY=/usr/local/bin
|
||||
CCACHE=/usr/bin/ccache
|
||||
CCDIR=/usr/lib/ccache
|
||||
|
||||
usage() {
|
||||
echo "Usage: `basename $0` [--directory <dir>] [--remove]"
|
||||
exit 0
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ] ; do
|
||||
case "$1" in
|
||||
-d*|--d*|--directory) DIRECTORY=$2; shift; shift;;
|
||||
-h*|--h*|--help) usage;;
|
||||
-r*|--r*|--remove) REMOVE=1; shift;;
|
||||
-t*|--t*|--test) TEST=echo; shift;;
|
||||
esac
|
||||
done
|
||||
|
||||
for FILE in `cd $CCDIR; ls` ; do
|
||||
LINK=$DIRECTORY/$FILE
|
||||
if [ -z "$REMOVE" ] ; then
|
||||
# Add link
|
||||
$TEST ln -fs $CCACHE $LINK
|
||||
else
|
||||
# Remove link
|
||||
if [ -L "$LINK" ] ; then
|
||||
$TEST rm -f $LINK
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# vim: sw=4 ts=4
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
version=2
|
||||
http://samba.org/ftp/ccache/ccache-(.*)\.tar\.gz
|
||||
286
CCache/execute.c
286
CCache/execute.c
|
|
@ -1,286 +0,0 @@
|
|||
/*
|
||||
Copyright (C) Andrew Tridgell 2002
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "ccache.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
char *argvtos(char **argv)
|
||||
{
|
||||
int i, len;
|
||||
char *ptr, *str;
|
||||
|
||||
for (i = 0, len = 0; argv[i]; i++) {
|
||||
len += strlen(argv[i]) + 3;
|
||||
}
|
||||
|
||||
str = ptr = (char *)malloc(len + 1);
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; argv[i]; i++) {
|
||||
len = strlen(argv[i]);
|
||||
*ptr++ = '"';
|
||||
memcpy(ptr, argv[i], len);
|
||||
ptr += len;
|
||||
*ptr++ = '"';
|
||||
*ptr++ = ' ';
|
||||
}
|
||||
*ptr = 0;
|
||||
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
execute a compiler backend, capturing all output to the given paths
|
||||
the full path to the compiler to run is in argv[0]
|
||||
*/
|
||||
int execute(char **argv,
|
||||
const char *path_stdout,
|
||||
const char *path_stderr)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
#if 1
|
||||
PROCESS_INFORMATION pinfo;
|
||||
STARTUPINFO sinfo;
|
||||
BOOL ret;
|
||||
DWORD exitcode;
|
||||
char *args;
|
||||
HANDLE fd_out, fd_err;
|
||||
SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
|
||||
|
||||
/* TODO: needs moving after possible exit() below, but before stdout is redirected */
|
||||
if (ccache_verbose) {
|
||||
display_execute_args(argv);
|
||||
}
|
||||
|
||||
fd_out = CreateFile(path_stdout, GENERIC_WRITE, 0, &sa, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (fd_out == INVALID_HANDLE_VALUE) {
|
||||
return STATUS_NOCACHE;
|
||||
}
|
||||
|
||||
fd_err = CreateFile(path_stderr, GENERIC_WRITE, 0, &sa, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (fd_err == INVALID_HANDLE_VALUE) {
|
||||
return STATUS_NOCACHE;
|
||||
}
|
||||
|
||||
ZeroMemory(&pinfo, sizeof(PROCESS_INFORMATION));
|
||||
ZeroMemory(&sinfo, sizeof(STARTUPINFO));
|
||||
|
||||
sinfo.cb = sizeof(STARTUPINFO);
|
||||
sinfo.hStdError = fd_err;
|
||||
sinfo.hStdOutput = fd_out;
|
||||
sinfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
sinfo.dwFlags |= STARTF_USESTDHANDLES;
|
||||
|
||||
args = argvtos(argv);
|
||||
|
||||
ret = CreateProcessA(argv[0], args, NULL, NULL, TRUE, 0, NULL, NULL,
|
||||
&sinfo, &pinfo);
|
||||
|
||||
free(args);
|
||||
CloseHandle(fd_out);
|
||||
CloseHandle(fd_err);
|
||||
|
||||
if (ret == 0)
|
||||
return -1;
|
||||
|
||||
WaitForSingleObject(pinfo.hProcess, INFINITE);
|
||||
GetExitCodeProcess(pinfo.hProcess, &exitcode);
|
||||
CloseHandle(pinfo.hProcess);
|
||||
CloseHandle(pinfo.hThread);
|
||||
|
||||
return exitcode;
|
||||
#else /* possibly slightly faster */
|
||||
/* needs fixing to quote commandline options to handle spaces in CCACHE_DIR etc */
|
||||
int status = -2;
|
||||
int fd, std_od = -1, std_ed = -1;
|
||||
|
||||
/* TODO: needs moving after possible exit() below, but before stdout is redirected */
|
||||
if (ccache_verbose) {
|
||||
display_execute_args(argv);
|
||||
}
|
||||
|
||||
unlink(path_stdout);
|
||||
std_od = _dup(1);
|
||||
fd = _open(path_stdout, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
|
||||
if (fd == -1) {
|
||||
exit(STATUS_NOCACHE);
|
||||
}
|
||||
_dup2(fd, 1);
|
||||
_close(fd);
|
||||
|
||||
unlink(path_stderr);
|
||||
fd = _open(path_stderr, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
|
||||
std_ed = _dup(2);
|
||||
if (fd == -1) {
|
||||
exit(STATUS_NOCACHE);
|
||||
}
|
||||
_dup2(fd, 2);
|
||||
_close(fd);
|
||||
|
||||
/* Spawn process (_exec* familly doesn't return) */
|
||||
status = _spawnv(_P_WAIT, argv[0], (const char **)argv);
|
||||
|
||||
/* Restore descriptors */
|
||||
if (std_od != -1) _dup2(std_od, 1);
|
||||
if (std_ed != -1) _dup2(std_ed, 2);
|
||||
_flushall();
|
||||
|
||||
return (status>0);
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
pid_t pid;
|
||||
int status;
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1) fatal("Failed to fork");
|
||||
|
||||
if (pid == 0) {
|
||||
int fd;
|
||||
|
||||
/* TODO: needs moving after possible exit() below, but before stdout is redirected */
|
||||
if (ccache_verbose) {
|
||||
display_execute_args(argv);
|
||||
}
|
||||
|
||||
unlink(path_stdout);
|
||||
fd = open(path_stdout, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
|
||||
if (fd == -1) {
|
||||
exit(STATUS_NOCACHE);
|
||||
}
|
||||
dup2(fd, 1);
|
||||
close(fd);
|
||||
|
||||
unlink(path_stderr);
|
||||
fd = open(path_stderr, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
|
||||
if (fd == -1) {
|
||||
exit(STATUS_NOCACHE);
|
||||
}
|
||||
dup2(fd, 2);
|
||||
close(fd);
|
||||
|
||||
exit(execv(argv[0], argv));
|
||||
}
|
||||
|
||||
if (waitpid(pid, &status, 0) != pid) {
|
||||
fatal("waitpid failed");
|
||||
}
|
||||
|
||||
if (WEXITSTATUS(status) == 0 && WIFSIGNALED(status)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
find an executable by name in $PATH. Exclude any that are links to exclude_name
|
||||
*/
|
||||
char *find_executable(const char *name, const char *exclude_name)
|
||||
{
|
||||
#if _WIN32
|
||||
(void)exclude_name;
|
||||
DWORD ret;
|
||||
char namebuf[MAX_PATH];
|
||||
|
||||
ret = SearchPathA(getenv("CCACHE_PATH"), name, ".exe",
|
||||
sizeof(namebuf), namebuf, NULL);
|
||||
if (ret != 0) {
|
||||
return x_strdup(namebuf);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
#else
|
||||
char *path;
|
||||
char *tok;
|
||||
struct stat st1, st2;
|
||||
|
||||
if (*name == '/') {
|
||||
return x_strdup(name);
|
||||
}
|
||||
|
||||
path = getenv("CCACHE_PATH");
|
||||
if (!path) {
|
||||
path = getenv("PATH");
|
||||
}
|
||||
if (!path) {
|
||||
cc_log("no PATH variable!?\n");
|
||||
stats_update(STATS_ENVIRONMMENT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path = x_strdup(path);
|
||||
|
||||
/* search the path looking for the first compiler of the right name
|
||||
that isn't us */
|
||||
for (tok=strtok(path,":"); tok; tok = strtok(NULL, ":")) {
|
||||
char *fname;
|
||||
x_asprintf(&fname, "%s/%s", tok, name);
|
||||
/* look for a normal executable file */
|
||||
if (access(fname, X_OK) == 0 &&
|
||||
lstat(fname, &st1) == 0 &&
|
||||
stat(fname, &st2) == 0 &&
|
||||
S_ISREG(st2.st_mode)) {
|
||||
/* if its a symlink then ensure it doesn't
|
||||
point at something called exclude_name */
|
||||
if (S_ISLNK(st1.st_mode)) {
|
||||
char *buf = x_realpath(fname);
|
||||
if (buf) {
|
||||
char *p = str_basename(buf);
|
||||
if (strcmp(p, exclude_name) == 0) {
|
||||
/* its a link to "ccache" ! */
|
||||
free(p);
|
||||
free(buf);
|
||||
continue;
|
||||
}
|
||||
free(buf);
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* found it! */
|
||||
free(path);
|
||||
return fname;
|
||||
}
|
||||
free(fname);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void display_execute_args(char **argv)
|
||||
{
|
||||
if (argv) {
|
||||
printf("ccache executing: ");
|
||||
while (*argv) {
|
||||
printf("%s ", *argv);
|
||||
++argv;
|
||||
}
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
Copyright (C) Andrew Tridgell 2002
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
simple front-end functions to mdfour code
|
||||
*/
|
||||
|
||||
#include "ccache.h"
|
||||
|
||||
static struct mdfour md;
|
||||
|
||||
void hash_buffer(const char *s, int len)
|
||||
{
|
||||
mdfour_update(&md, (unsigned char *)s, len);
|
||||
}
|
||||
|
||||
void hash_start(void)
|
||||
{
|
||||
mdfour_begin(&md);
|
||||
}
|
||||
|
||||
void hash_string(const char *s)
|
||||
{
|
||||
hash_buffer(s, strlen(s));
|
||||
}
|
||||
|
||||
void hash_int(int x)
|
||||
{
|
||||
hash_buffer((char *)&x, sizeof(x));
|
||||
}
|
||||
|
||||
/* add contents of a file to the hash */
|
||||
void hash_file(const char *fname)
|
||||
{
|
||||
char buf[1024];
|
||||
int fd, n;
|
||||
|
||||
fd = open(fname, O_RDONLY|O_BINARY);
|
||||
if (fd == -1) {
|
||||
cc_log("Failed to open %s\n", fname);
|
||||
fatal("hash_file");
|
||||
}
|
||||
|
||||
while ((n = read(fd, buf, sizeof(buf))) > 0) {
|
||||
hash_buffer(buf, n);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* return the hash result as a static string */
|
||||
char *hash_result(void)
|
||||
{
|
||||
unsigned char sum[16];
|
||||
static char ret[53];
|
||||
int i;
|
||||
|
||||
hash_buffer(NULL, 0);
|
||||
mdfour_result(&md, sum);
|
||||
|
||||
for (i=0;i<16;i++) {
|
||||
sprintf(&ret[i*2], "%02x", (unsigned)sum[i]);
|
||||
}
|
||||
sprintf(&ret[i*2], "-%u", (unsigned)md.totalN);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
#! /bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch.
|
||||
#
|
||||
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit="${DOITPROG-}"
|
||||
|
||||
|
||||
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||
|
||||
mvprog="${MVPROG-mv}"
|
||||
cpprog="${CPPROG-cp}"
|
||||
chmodprog="${CHMODPROG-chmod}"
|
||||
chownprog="${CHOWNPROG-chown}"
|
||||
chgrpprog="${CHGRPPROG-chgrp}"
|
||||
stripprog="${STRIPPROG-strip}"
|
||||
rmprog="${RMPROG-rm}"
|
||||
mkdirprog="${MKDIRPROG-mkdir}"
|
||||
|
||||
transformbasename=""
|
||||
transform_arg=""
|
||||
instcmd="$mvprog"
|
||||
chmodcmd="$chmodprog 0755"
|
||||
chowncmd=""
|
||||
chgrpcmd=""
|
||||
stripcmd=""
|
||||
rmcmd="$rmprog -f"
|
||||
mvcmd="$mvprog"
|
||||
src=""
|
||||
dst=""
|
||||
dir_arg=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd="$cpprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd="$stripprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "install: no input file specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -d $dst ]; then
|
||||
instcmd=:
|
||||
else
|
||||
instcmd=mkdir
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
|
||||
if [ -f $src -o -d $src ]
|
||||
then
|
||||
true
|
||||
else
|
||||
echo "install: $src does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "install: no destination specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d $dst ]
|
||||
then
|
||||
dst="$dst"/`basename $src`
|
||||
else
|
||||
true
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
'
|
||||
IFS="${IFS-${defaultIFS}}"
|
||||
|
||||
oIFS="${IFS}"
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS="${oIFS}"
|
||||
|
||||
pathcomp=''
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp="${pathcomp}${1}"
|
||||
shift
|
||||
|
||||
if [ ! -d "${pathcomp}" ] ;
|
||||
then
|
||||
$mkdirprog "${pathcomp}"
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
pathcomp="${pathcomp}/"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd $dst &&
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
|
||||
else
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
dstfile=`basename $dst $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
fi
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# Make a temp file name in the proper directory.
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
|
||||
$doit $instcmd $src $dsttmp &&
|
||||
|
||||
trap "rm -f ${dsttmp}" 0 &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
|
||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||
|
||||
fi &&
|
||||
|
||||
|
||||
exit 0
|
||||
284
CCache/mdfour.c
284
CCache/mdfour.c
|
|
@ -1,284 +0,0 @@
|
|||
/*
|
||||
a implementation of MD4 designed for use in the SMB authentication protocol
|
||||
Copyright (C) Andrew Tridgell 1997-1998.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "ccache.h"
|
||||
|
||||
/* NOTE: This code makes no attempt to be fast!
|
||||
|
||||
It assumes that a int is at least 32 bits long
|
||||
*/
|
||||
|
||||
static struct mdfour *m;
|
||||
|
||||
#define MASK32 (0xffffffff)
|
||||
|
||||
#define F(X,Y,Z) ((((X)&(Y)) | ((~(X))&(Z))))
|
||||
#define G(X,Y,Z) ((((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z))))
|
||||
#define H(X,Y,Z) (((X)^(Y)^(Z)))
|
||||
#define lshift(x,s) (((((x)<<(s))&MASK32) | (((x)>>(32-(s)))&MASK32)))
|
||||
|
||||
#define ROUND1(a,b,c,d,k,s) a = lshift((a + F(b,c,d) + M[k])&MASK32, s)
|
||||
#define ROUND2(a,b,c,d,k,s) a = lshift((a + G(b,c,d) + M[k] + 0x5A827999)&MASK32,s)
|
||||
#define ROUND3(a,b,c,d,k,s) a = lshift((a + H(b,c,d) + M[k] + 0x6ED9EBA1)&MASK32,s)
|
||||
|
||||
/* this applies md4 to 64 byte chunks */
|
||||
static void mdfour64(uint32 *M)
|
||||
{
|
||||
uint32 AA, BB, CC, DD;
|
||||
uint32 A,B,C,D;
|
||||
|
||||
A = m->A; B = m->B; C = m->C; D = m->D;
|
||||
AA = A; BB = B; CC = C; DD = D;
|
||||
|
||||
ROUND1(A,B,C,D, 0, 3); ROUND1(D,A,B,C, 1, 7);
|
||||
ROUND1(C,D,A,B, 2, 11); ROUND1(B,C,D,A, 3, 19);
|
||||
ROUND1(A,B,C,D, 4, 3); ROUND1(D,A,B,C, 5, 7);
|
||||
ROUND1(C,D,A,B, 6, 11); ROUND1(B,C,D,A, 7, 19);
|
||||
ROUND1(A,B,C,D, 8, 3); ROUND1(D,A,B,C, 9, 7);
|
||||
ROUND1(C,D,A,B, 10, 11); ROUND1(B,C,D,A, 11, 19);
|
||||
ROUND1(A,B,C,D, 12, 3); ROUND1(D,A,B,C, 13, 7);
|
||||
ROUND1(C,D,A,B, 14, 11); ROUND1(B,C,D,A, 15, 19);
|
||||
|
||||
|
||||
ROUND2(A,B,C,D, 0, 3); ROUND2(D,A,B,C, 4, 5);
|
||||
ROUND2(C,D,A,B, 8, 9); ROUND2(B,C,D,A, 12, 13);
|
||||
ROUND2(A,B,C,D, 1, 3); ROUND2(D,A,B,C, 5, 5);
|
||||
ROUND2(C,D,A,B, 9, 9); ROUND2(B,C,D,A, 13, 13);
|
||||
ROUND2(A,B,C,D, 2, 3); ROUND2(D,A,B,C, 6, 5);
|
||||
ROUND2(C,D,A,B, 10, 9); ROUND2(B,C,D,A, 14, 13);
|
||||
ROUND2(A,B,C,D, 3, 3); ROUND2(D,A,B,C, 7, 5);
|
||||
ROUND2(C,D,A,B, 11, 9); ROUND2(B,C,D,A, 15, 13);
|
||||
|
||||
ROUND3(A,B,C,D, 0, 3); ROUND3(D,A,B,C, 8, 9);
|
||||
ROUND3(C,D,A,B, 4, 11); ROUND3(B,C,D,A, 12, 15);
|
||||
ROUND3(A,B,C,D, 2, 3); ROUND3(D,A,B,C, 10, 9);
|
||||
ROUND3(C,D,A,B, 6, 11); ROUND3(B,C,D,A, 14, 15);
|
||||
ROUND3(A,B,C,D, 1, 3); ROUND3(D,A,B,C, 9, 9);
|
||||
ROUND3(C,D,A,B, 5, 11); ROUND3(B,C,D,A, 13, 15);
|
||||
ROUND3(A,B,C,D, 3, 3); ROUND3(D,A,B,C, 11, 9);
|
||||
ROUND3(C,D,A,B, 7, 11); ROUND3(B,C,D,A, 15, 15);
|
||||
|
||||
A += AA; B += BB;
|
||||
C += CC; D += DD;
|
||||
|
||||
A &= MASK32; B &= MASK32;
|
||||
C &= MASK32; D &= MASK32;
|
||||
|
||||
m->A = A; m->B = B; m->C = C; m->D = D;
|
||||
}
|
||||
|
||||
static void copy64(uint32 *M, const unsigned char *in)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0;i<16;i++)
|
||||
M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
|
||||
(in[i*4+1]<<8) | (in[i*4+0]<<0);
|
||||
}
|
||||
|
||||
static void copy4(unsigned char *out,uint32 x)
|
||||
{
|
||||
out[0] = x&0xFF;
|
||||
out[1] = (x>>8)&0xFF;
|
||||
out[2] = (x>>16)&0xFF;
|
||||
out[3] = (x>>24)&0xFF;
|
||||
}
|
||||
|
||||
void mdfour_begin(struct mdfour *md)
|
||||
{
|
||||
md->A = 0x67452301;
|
||||
md->B = 0xefcdab89;
|
||||
md->C = 0x98badcfe;
|
||||
md->D = 0x10325476;
|
||||
md->totalN = 0;
|
||||
md->tail_len = 0;
|
||||
}
|
||||
|
||||
|
||||
static void mdfour_tail(const unsigned char *in, int n)
|
||||
{
|
||||
unsigned char buf[128];
|
||||
uint32 M[16];
|
||||
uint32 b;
|
||||
|
||||
m->totalN += n;
|
||||
|
||||
b = m->totalN * 8;
|
||||
|
||||
memset(buf, 0, 128);
|
||||
if (n) memcpy(buf, in, n);
|
||||
buf[n] = 0x80;
|
||||
|
||||
if (n <= 55) {
|
||||
copy4(buf+56, b);
|
||||
copy64(M, buf);
|
||||
mdfour64(M);
|
||||
} else {
|
||||
copy4(buf+120, b);
|
||||
copy64(M, buf);
|
||||
mdfour64(M);
|
||||
copy64(M, buf+64);
|
||||
mdfour64(M);
|
||||
}
|
||||
}
|
||||
|
||||
void mdfour_update(struct mdfour *md, const unsigned char *in, int n)
|
||||
{
|
||||
uint32 M[16];
|
||||
|
||||
m = md;
|
||||
|
||||
if (in == NULL) {
|
||||
mdfour_tail(md->tail, md->tail_len);
|
||||
return;
|
||||
}
|
||||
|
||||
if (md->tail_len) {
|
||||
int len = 64 - md->tail_len;
|
||||
if (len > n) len = n;
|
||||
memcpy(md->tail+md->tail_len, in, len);
|
||||
md->tail_len += len;
|
||||
n -= len;
|
||||
in += len;
|
||||
if (md->tail_len == 64) {
|
||||
copy64(M, md->tail);
|
||||
mdfour64(M);
|
||||
m->totalN += 64;
|
||||
md->tail_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
while (n >= 64) {
|
||||
copy64(M, in);
|
||||
mdfour64(M);
|
||||
in += 64;
|
||||
n -= 64;
|
||||
m->totalN += 64;
|
||||
}
|
||||
|
||||
if (n) {
|
||||
memcpy(md->tail, in, n);
|
||||
md->tail_len = n;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mdfour_result(struct mdfour *md, unsigned char *out)
|
||||
{
|
||||
m = md;
|
||||
|
||||
copy4(out, m->A);
|
||||
copy4(out+4, m->B);
|
||||
copy4(out+8, m->C);
|
||||
copy4(out+12, m->D);
|
||||
}
|
||||
|
||||
|
||||
void mdfour(unsigned char *out, const unsigned char *in, int n)
|
||||
{
|
||||
struct mdfour md;
|
||||
mdfour_begin(&md);
|
||||
mdfour_update(&md, in, n);
|
||||
mdfour_update(&md, NULL, 0);
|
||||
mdfour_result(&md, out);
|
||||
}
|
||||
|
||||
#ifdef TEST_MDFOUR
|
||||
static void file_checksum1(char *fname)
|
||||
{
|
||||
int fd, i;
|
||||
struct mdfour md;
|
||||
unsigned char buf[1024], sum[16];
|
||||
unsigned chunk;
|
||||
|
||||
fd = open(fname,O_RDONLY|O_BINARY);
|
||||
if (fd == -1) {
|
||||
perror("fname");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
chunk = 1 + random() % (sizeof(buf) - 1);
|
||||
|
||||
mdfour_begin(&md);
|
||||
|
||||
while (1) {
|
||||
int n = read(fd, buf, chunk);
|
||||
if (n >= 0) {
|
||||
mdfour_update(&md, buf, n);
|
||||
}
|
||||
if (n < chunk) break;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
mdfour_update(&md, NULL, 0);
|
||||
|
||||
mdfour_result(&md, sum);
|
||||
|
||||
for (i=0;i<16;i++)
|
||||
printf("%02x", sum[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
#if 0
|
||||
#include "../md4.h"
|
||||
|
||||
static void file_checksum2(char *fname)
|
||||
{
|
||||
int fd, i;
|
||||
MDstruct md;
|
||||
unsigned char buf[64], sum[16];
|
||||
|
||||
fd = open(fname,O_RDONLY|O_BINARY);
|
||||
if (fd == -1) {
|
||||
perror("fname");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
MDbegin(&md);
|
||||
|
||||
while (1) {
|
||||
int n = read(fd, buf, sizeof(buf));
|
||||
if (n <= 0) break;
|
||||
MDupdate(&md, buf, n*8);
|
||||
}
|
||||
|
||||
if (!md.done) {
|
||||
MDupdate(&md, buf, 0);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
memcpy(sum, md.buffer, 16);
|
||||
|
||||
for (i=0;i<16;i++)
|
||||
printf("%02x", sum[i]);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
file_checksum1(argv[1]);
|
||||
#if 0
|
||||
file_checksum2(argv[1]);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
Unix SMB/Netbios implementation.
|
||||
Version 1.9.
|
||||
a implementation of MD4 designed for use in the SMB authentication protocol
|
||||
Copyright (C) Andrew Tridgell 1997-1998.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
struct mdfour {
|
||||
uint32 A, B, C, D;
|
||||
uint32 totalN;
|
||||
unsigned char tail[64];
|
||||
unsigned tail_len;
|
||||
};
|
||||
|
||||
void mdfour_begin(struct mdfour *md);
|
||||
void mdfour_update(struct mdfour *md, const unsigned char *in, int n);
|
||||
void mdfour_result(struct mdfour *md, unsigned char *out);
|
||||
void mdfour(unsigned char *out, const unsigned char *in, int n);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
These packaging files are contributd by users of ccache. I do not
|
||||
maintain them, and they may well need updating before you use them.
|
||||
|
||||
I don't distribute binary packages of ccache myself, but if you wish
|
||||
to add ccache to a distribution then that's OK
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
Summary: Compiler Cache
|
||||
Name: ccache
|
||||
Version: 2.3
|
||||
Release: 1
|
||||
Group: Development/Languages
|
||||
License: GPL
|
||||
URL: http://ccache.samba.org/
|
||||
Source: ccache-%{version}.tar.gz
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-root
|
||||
|
||||
%description
|
||||
ccache caches gcc output files
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%build
|
||||
%configure
|
||||
make
|
||||
|
||||
install -d -m 0755 $RPM_BUILD_ROOT%{_bindir}
|
||||
install -m 0755 ccache $RPM_BUILD_ROOT%{_bindir}
|
||||
install -d -m 0755 $RPM_BUILD_ROOT%{_mandir}/man1
|
||||
install -m 0644 ccache.1 $RPM_BUILD_ROOT%{_mandir}/man1
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
%doc README
|
||||
%{_mandir}/man1/ccache.1*
|
||||
%{_bindir}/ccache
|
||||
|
||||
%clean
|
||||
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%changelog
|
||||
* Mon Apr 01 2002 Peter Jones <pjones@redhat.com>
|
||||
- Created the package
|
||||
|
|
@ -1,962 +0,0 @@
|
|||
/*
|
||||
* Copyright Patrick Powell 1995
|
||||
* This code is based on code written by Patrick Powell (papowell@astart.com)
|
||||
* It may be used for any purpose as long as this notice remains intact
|
||||
* on all source code distributions
|
||||
*/
|
||||
|
||||
/**************************************************************
|
||||
* Original:
|
||||
* Patrick Powell Tue Apr 11 09:48:21 PDT 1995
|
||||
* A bombproof version of doprnt (dopr) included.
|
||||
* Sigh. This sort of thing is always nasty do deal with. Note that
|
||||
* the version here does not include floating point...
|
||||
*
|
||||
* snprintf() is used instead of sprintf() as it does limit checks
|
||||
* for string length. This covers a nasty loophole.
|
||||
*
|
||||
* The other functions are there to prevent NULL pointers from
|
||||
* causing nast effects.
|
||||
*
|
||||
* More Recently:
|
||||
* Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43
|
||||
* This was ugly. It is still ugly. I opted out of floating point
|
||||
* numbers, but the formatter understands just about everything
|
||||
* from the normal C string format, at least as far as I can tell from
|
||||
* the Solaris 2.5 printf(3S) man page.
|
||||
*
|
||||
* Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1
|
||||
* Ok, added some minimal floating point support, which means this
|
||||
* probably requires libm on most operating systems. Don't yet
|
||||
* support the exponent (e,E) and sigfig (g,G). Also, fmtint()
|
||||
* was pretty badly broken, it just wasn't being exercised in ways
|
||||
* which showed it, so that's been fixed. Also, formated the code
|
||||
* to mutt conventions, and removed dead code left over from the
|
||||
* original. Also, there is now a builtin-test, just compile with:
|
||||
* gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
|
||||
* and run snprintf for results.
|
||||
*
|
||||
* Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i
|
||||
* The PGP code was using unsigned hexadecimal formats.
|
||||
* Unfortunately, unsigned formats simply didn't work.
|
||||
*
|
||||
* Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8
|
||||
* The original code assumed that both snprintf() and vsnprintf() were
|
||||
* missing. Some systems only have snprintf() but not vsnprintf(), so
|
||||
* the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
|
||||
*
|
||||
* Andrew Tridgell (tridge@samba.org) Oct 1998
|
||||
* fixed handling of %.0f
|
||||
* added test for HAVE_LONG_DOUBLE
|
||||
*
|
||||
* tridge@samba.org, idra@samba.org, April 2001
|
||||
* got rid of fcvt code (twas buggy and made testing harder)
|
||||
* added C99 semantics
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
#ifndef NO_CONFIG_H /* for some tests */
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#ifdef HAVE_CTYPE_H
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <stdarg.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) && defined(HAVE_C99_VSNPRINTF)
|
||||
/* only include stdio.h if we are not re-defining snprintf or vsnprintf */
|
||||
#include <stdio.h>
|
||||
/* make the compiler happy with an empty file */
|
||||
void dummy_snprintf(void) {}
|
||||
#else
|
||||
|
||||
#ifdef HAVE_LONG_DOUBLE
|
||||
#define LDOUBLE long double
|
||||
#else
|
||||
#define LDOUBLE double
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
#define LLONG long long
|
||||
#else
|
||||
#define LLONG long
|
||||
#endif
|
||||
|
||||
static size_t dopr(char *buffer, size_t maxlen, const char *format,
|
||||
va_list args);
|
||||
static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
|
||||
char *value, int flags, int min, int max);
|
||||
static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
|
||||
long value, int base, int min, int max, int flags);
|
||||
static void fmtfp(char *buffer, size_t *currlen, size_t maxlen,
|
||||
LDOUBLE fvalue, int min, int max, int flags);
|
||||
static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
|
||||
|
||||
/*
|
||||
* dopr(): poor man's version of doprintf
|
||||
*/
|
||||
|
||||
/* format read states */
|
||||
#define DP_S_DEFAULT 0
|
||||
#define DP_S_FLAGS 1
|
||||
#define DP_S_MIN 2
|
||||
#define DP_S_DOT 3
|
||||
#define DP_S_MAX 4
|
||||
#define DP_S_MOD 5
|
||||
#define DP_S_CONV 6
|
||||
#define DP_S_DONE 7
|
||||
|
||||
/* format flags - Bits */
|
||||
#define DP_F_MINUS (1 << 0)
|
||||
#define DP_F_PLUS (1 << 1)
|
||||
#define DP_F_SPACE (1 << 2)
|
||||
#define DP_F_NUM (1 << 3)
|
||||
#define DP_F_ZERO (1 << 4)
|
||||
#define DP_F_UP (1 << 5)
|
||||
#define DP_F_UNSIGNED (1 << 6)
|
||||
|
||||
/* Conversion Flags */
|
||||
#define DP_C_SHORT 1
|
||||
#define DP_C_LONG 2
|
||||
#define DP_C_LDOUBLE 3
|
||||
#define DP_C_LLONG 4
|
||||
|
||||
#define char_to_int(p) ((p)- '0')
|
||||
#ifndef MAX
|
||||
#define MAX(p,q) (((p) >= (q)) ? (p) : (q))
|
||||
#endif
|
||||
|
||||
static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args)
|
||||
{
|
||||
char ch;
|
||||
LLONG value;
|
||||
LDOUBLE fvalue;
|
||||
char *strvalue;
|
||||
int min;
|
||||
int max;
|
||||
int state;
|
||||
int flags;
|
||||
int cflags;
|
||||
size_t currlen;
|
||||
|
||||
state = DP_S_DEFAULT;
|
||||
currlen = flags = cflags = min = 0;
|
||||
max = -1;
|
||||
ch = *format++;
|
||||
|
||||
while (state != DP_S_DONE) {
|
||||
if (ch == '\0')
|
||||
state = DP_S_DONE;
|
||||
|
||||
switch(state) {
|
||||
case DP_S_DEFAULT:
|
||||
if (ch == '%')
|
||||
state = DP_S_FLAGS;
|
||||
else
|
||||
dopr_outch (buffer, &currlen, maxlen, ch);
|
||||
ch = *format++;
|
||||
break;
|
||||
case DP_S_FLAGS:
|
||||
switch (ch) {
|
||||
case '-':
|
||||
flags |= DP_F_MINUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '+':
|
||||
flags |= DP_F_PLUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case ' ':
|
||||
flags |= DP_F_SPACE;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '#':
|
||||
flags |= DP_F_NUM;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '0':
|
||||
flags |= DP_F_ZERO;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
state = DP_S_MIN;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case DP_S_MIN:
|
||||
if (isdigit((unsigned char)ch)) {
|
||||
min = 10*min + char_to_int (ch);
|
||||
ch = *format++;
|
||||
} else if (ch == '*') {
|
||||
min = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_DOT;
|
||||
} else {
|
||||
state = DP_S_DOT;
|
||||
}
|
||||
break;
|
||||
case DP_S_DOT:
|
||||
if (ch == '.') {
|
||||
state = DP_S_MAX;
|
||||
ch = *format++;
|
||||
} else {
|
||||
state = DP_S_MOD;
|
||||
}
|
||||
break;
|
||||
case DP_S_MAX:
|
||||
if (isdigit((unsigned char)ch)) {
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
max = 10*max + char_to_int (ch);
|
||||
ch = *format++;
|
||||
} else if (ch == '*') {
|
||||
max = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_MOD;
|
||||
} else {
|
||||
state = DP_S_MOD;
|
||||
}
|
||||
break;
|
||||
case DP_S_MOD:
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
cflags = DP_C_SHORT;
|
||||
ch = *format++;
|
||||
break;
|
||||
case 'l':
|
||||
cflags = DP_C_LONG;
|
||||
ch = *format++;
|
||||
if (ch == 'l') { /* It's a long long */
|
||||
cflags = DP_C_LLONG;
|
||||
ch = *format++;
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
cflags = DP_C_LDOUBLE;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
state = DP_S_CONV;
|
||||
break;
|
||||
case DP_S_CONV:
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, long int);
|
||||
else if (cflags == DP_C_LLONG)
|
||||
value = va_arg (args, LLONG);
|
||||
else
|
||||
value = va_arg (args, int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'o':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = (long)va_arg (args, unsigned long int);
|
||||
else if (cflags == DP_C_LLONG)
|
||||
value = (long)va_arg (args, unsigned LLONG);
|
||||
else
|
||||
value = (long)va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
|
||||
break;
|
||||
case 'u':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = (long)va_arg (args, unsigned long int);
|
||||
else if (cflags == DP_C_LLONG)
|
||||
value = (LLONG)va_arg (args, unsigned LLONG);
|
||||
else
|
||||
value = (long)va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'X':
|
||||
flags |= DP_F_UP;
|
||||
case 'x':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = (long)va_arg (args, unsigned long int);
|
||||
else if (cflags == DP_C_LLONG)
|
||||
value = (LLONG)va_arg (args, unsigned LLONG);
|
||||
else
|
||||
value = (long)va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
|
||||
break;
|
||||
case 'f':
|
||||
if (cflags == DP_C_LDOUBLE)
|
||||
fvalue = va_arg (args, LDOUBLE);
|
||||
else
|
||||
fvalue = va_arg (args, double);
|
||||
/* um, floating point? */
|
||||
fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
|
||||
break;
|
||||
case 'E':
|
||||
flags |= DP_F_UP;
|
||||
case 'e':
|
||||
if (cflags == DP_C_LDOUBLE)
|
||||
fvalue = va_arg (args, LDOUBLE);
|
||||
else
|
||||
fvalue = va_arg (args, double);
|
||||
break;
|
||||
case 'G':
|
||||
flags |= DP_F_UP;
|
||||
case 'g':
|
||||
if (cflags == DP_C_LDOUBLE)
|
||||
fvalue = va_arg (args, LDOUBLE);
|
||||
else
|
||||
fvalue = va_arg (args, double);
|
||||
break;
|
||||
case 'c':
|
||||
dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
|
||||
break;
|
||||
case 's':
|
||||
strvalue = va_arg (args, char *);
|
||||
if (!strvalue) strvalue = "(NULL)";
|
||||
if (max == -1) {
|
||||
max = strlen(strvalue);
|
||||
}
|
||||
if (min > 0 && max >= 0 && min > max) max = min;
|
||||
fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
|
||||
break;
|
||||
case 'p':
|
||||
strvalue = (char *)va_arg(args, void *);
|
||||
fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
|
||||
break;
|
||||
case 'n':
|
||||
if (cflags == DP_C_SHORT) {
|
||||
short int *num;
|
||||
num = va_arg (args, short int *);
|
||||
*num = currlen;
|
||||
} else if (cflags == DP_C_LONG) {
|
||||
long int *num;
|
||||
num = va_arg (args, long int *);
|
||||
*num = (long int)currlen;
|
||||
} else if (cflags == DP_C_LLONG) {
|
||||
LLONG *num;
|
||||
num = va_arg (args, LLONG *);
|
||||
*num = (LLONG)currlen;
|
||||
} else {
|
||||
int *num;
|
||||
num = va_arg (args, int *);
|
||||
*num = currlen;
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
dopr_outch (buffer, &currlen, maxlen, ch);
|
||||
break;
|
||||
case 'w':
|
||||
/* not supported yet, treat as next char */
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
/* Unknown, skip */
|
||||
break;
|
||||
}
|
||||
ch = *format++;
|
||||
state = DP_S_DEFAULT;
|
||||
flags = cflags = min = 0;
|
||||
max = -1;
|
||||
break;
|
||||
case DP_S_DONE:
|
||||
break;
|
||||
default:
|
||||
/* hmm? */
|
||||
break; /* some picky compilers need this */
|
||||
}
|
||||
}
|
||||
if (maxlen != 0) {
|
||||
if (currlen < maxlen - 1)
|
||||
buffer[currlen] = '\0';
|
||||
else if (maxlen > 0)
|
||||
buffer[maxlen - 1] = '\0';
|
||||
}
|
||||
|
||||
return currlen;
|
||||
}
|
||||
|
||||
static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
|
||||
char *value, int flags, int min, int max)
|
||||
{
|
||||
int padlen, strln; /* amount to pad */
|
||||
int cnt = 0;
|
||||
|
||||
#ifdef DEBUG_SNPRINTF
|
||||
printf("fmtstr min=%d max=%d s=[%s]\n", min, max, value);
|
||||
#endif
|
||||
if (value == 0) {
|
||||
value = "<NULL>";
|
||||
}
|
||||
|
||||
for (strln = 0; value[strln]; ++strln); /* strlen */
|
||||
padlen = min - strln;
|
||||
if (padlen < 0)
|
||||
padlen = 0;
|
||||
if (flags & DP_F_MINUS)
|
||||
padlen = -padlen; /* Left Justify */
|
||||
|
||||
while ((padlen > 0) && (cnt < max)) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--padlen;
|
||||
++cnt;
|
||||
}
|
||||
while (*value && (cnt < max)) {
|
||||
dopr_outch (buffer, currlen, maxlen, *value++);
|
||||
++cnt;
|
||||
}
|
||||
while ((padlen < 0) && (cnt < max)) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++padlen;
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
|
||||
|
||||
static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
|
||||
long value, int base, int min, int max, int flags)
|
||||
{
|
||||
int signvalue = 0;
|
||||
unsigned long uvalue;
|
||||
char convert[20];
|
||||
int place = 0;
|
||||
int spadlen = 0; /* amount to space pad */
|
||||
int zpadlen = 0; /* amount to zero pad */
|
||||
int caps = 0;
|
||||
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
|
||||
uvalue = value;
|
||||
|
||||
if(!(flags & DP_F_UNSIGNED)) {
|
||||
if( value < 0 ) {
|
||||
signvalue = '-';
|
||||
uvalue = -value;
|
||||
} else {
|
||||
if (flags & DP_F_PLUS) /* Do a sign (+/i) */
|
||||
signvalue = '+';
|
||||
else if (flags & DP_F_SPACE)
|
||||
signvalue = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
|
||||
|
||||
do {
|
||||
convert[place++] =
|
||||
(caps? "0123456789ABCDEF":"0123456789abcdef")
|
||||
[uvalue % (unsigned)base ];
|
||||
uvalue = (uvalue / (unsigned)base );
|
||||
} while(uvalue && (place < 20));
|
||||
if (place == 20) place--;
|
||||
convert[place] = 0;
|
||||
|
||||
zpadlen = max - place;
|
||||
spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
|
||||
if (zpadlen < 0) zpadlen = 0;
|
||||
if (spadlen < 0) spadlen = 0;
|
||||
if (flags & DP_F_ZERO) {
|
||||
zpadlen = MAX(zpadlen, spadlen);
|
||||
spadlen = 0;
|
||||
}
|
||||
if (flags & DP_F_MINUS)
|
||||
spadlen = -spadlen; /* Left Justifty */
|
||||
|
||||
#ifdef DEBUG_SNPRINTF
|
||||
printf("zpad: %d, spad: %d, min: %d, max: %d, place: %d\n",
|
||||
zpadlen, spadlen, min, max, place);
|
||||
#endif
|
||||
|
||||
/* Spaces */
|
||||
while (spadlen > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--spadlen;
|
||||
}
|
||||
|
||||
/* Sign */
|
||||
if (signvalue)
|
||||
dopr_outch (buffer, currlen, maxlen, signvalue);
|
||||
|
||||
/* Zeros */
|
||||
if (zpadlen > 0) {
|
||||
while (zpadlen > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, '0');
|
||||
--zpadlen;
|
||||
}
|
||||
}
|
||||
|
||||
/* Digits */
|
||||
while (place > 0)
|
||||
dopr_outch (buffer, currlen, maxlen, convert[--place]);
|
||||
|
||||
/* Left Justified spaces */
|
||||
while (spadlen < 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++spadlen;
|
||||
}
|
||||
}
|
||||
|
||||
static LDOUBLE abs_val(LDOUBLE value)
|
||||
{
|
||||
LDOUBLE result = value;
|
||||
|
||||
if (value < 0)
|
||||
result = -value;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static LDOUBLE POW10(int exp)
|
||||
{
|
||||
LDOUBLE result = 1;
|
||||
|
||||
while (exp) {
|
||||
result *= 10;
|
||||
exp--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static LLONG ROUND(LDOUBLE value)
|
||||
{
|
||||
LLONG intpart;
|
||||
|
||||
intpart = (LLONG)value;
|
||||
value = value - intpart;
|
||||
if (value >= 0.5) intpart++;
|
||||
|
||||
return intpart;
|
||||
}
|
||||
|
||||
/* a replacement for modf that doesn't need the math library. Should
|
||||
be portable, but slow */
|
||||
static double my_modf(double x0, double *iptr)
|
||||
{
|
||||
int i;
|
||||
long l;
|
||||
double x = x0;
|
||||
double f = 1.0;
|
||||
|
||||
for (i=0;i<100;i++) {
|
||||
l = (long)x;
|
||||
if (l <= (x+1) && l >= (x-1)) break;
|
||||
x *= 0.1;
|
||||
f *= 10.0;
|
||||
}
|
||||
|
||||
if (i == 100) {
|
||||
/* yikes! the number is beyond what we can handle. What do we do? */
|
||||
(*iptr) = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (i != 0) {
|
||||
double i2;
|
||||
double ret;
|
||||
|
||||
ret = my_modf(x0-l*f, &i2);
|
||||
(*iptr) = l*f + i2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
(*iptr) = l;
|
||||
return x - (*iptr);
|
||||
}
|
||||
|
||||
|
||||
static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
|
||||
LDOUBLE fvalue, int min, int max, int flags)
|
||||
{
|
||||
int signvalue = 0;
|
||||
double ufvalue;
|
||||
char iconvert[311];
|
||||
char fconvert[311];
|
||||
int iplace = 0;
|
||||
int fplace = 0;
|
||||
int padlen = 0; /* amount to pad */
|
||||
int zpadlen = 0;
|
||||
int caps = 0;
|
||||
int index;
|
||||
double intpart;
|
||||
double fracpart;
|
||||
double temp;
|
||||
|
||||
/*
|
||||
* AIX manpage says the default is 0, but Solaris says the default
|
||||
* is 6, and sprintf on AIX defaults to 6
|
||||
*/
|
||||
if (max < 0)
|
||||
max = 6;
|
||||
|
||||
ufvalue = abs_val (fvalue);
|
||||
|
||||
if (fvalue < 0) {
|
||||
signvalue = '-';
|
||||
} else {
|
||||
if (flags & DP_F_PLUS) { /* Do a sign (+/i) */
|
||||
signvalue = '+';
|
||||
} else {
|
||||
if (flags & DP_F_SPACE)
|
||||
signvalue = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
if (max == 0) ufvalue += 0.5; /* if max = 0 we must round */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Sorry, we only support 16 digits past the decimal because of our
|
||||
* conversion method
|
||||
*/
|
||||
if (max > 16)
|
||||
max = 16;
|
||||
|
||||
/* We "cheat" by converting the fractional part to integer by
|
||||
* multiplying by a factor of 10
|
||||
*/
|
||||
|
||||
temp = ufvalue;
|
||||
my_modf(temp, &intpart);
|
||||
|
||||
fracpart = ROUND((POW10(max)) * (ufvalue - intpart));
|
||||
|
||||
if (fracpart >= POW10(max)) {
|
||||
intpart++;
|
||||
fracpart -= POW10(max);
|
||||
}
|
||||
|
||||
|
||||
/* Convert integer part */
|
||||
do {
|
||||
temp = intpart;
|
||||
my_modf(intpart*0.1, &intpart);
|
||||
temp = temp*0.1;
|
||||
index = (int) ((temp -intpart +0.05)* 10.0);
|
||||
/* index = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */
|
||||
/* printf ("%llf, %f, %x\n", temp, intpart, index); */
|
||||
iconvert[iplace++] =
|
||||
(caps? "0123456789ABCDEF":"0123456789abcdef")[index];
|
||||
} while (intpart && (iplace < 311));
|
||||
if (iplace == 311) iplace--;
|
||||
iconvert[iplace] = 0;
|
||||
|
||||
/* Convert fractional part */
|
||||
if (fracpart)
|
||||
{
|
||||
do {
|
||||
temp = fracpart;
|
||||
my_modf(fracpart*0.1, &fracpart);
|
||||
temp = temp*0.1;
|
||||
index = (int) ((temp -fracpart +0.05)* 10.0);
|
||||
/* index = (int) ((((temp/10) -fracpart) +0.05) *10); */
|
||||
/* printf ("%lf, %lf, %ld\n", temp, fracpart, index); */
|
||||
fconvert[fplace++] =
|
||||
(caps? "0123456789ABCDEF":"0123456789abcdef")[index];
|
||||
} while(fracpart && (fplace < 311));
|
||||
if (fplace == 311) fplace--;
|
||||
}
|
||||
fconvert[fplace] = 0;
|
||||
|
||||
/* -1 for decimal point, another -1 if we are printing a sign */
|
||||
padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
|
||||
zpadlen = max - fplace;
|
||||
if (zpadlen < 0) zpadlen = 0;
|
||||
if (padlen < 0)
|
||||
padlen = 0;
|
||||
if (flags & DP_F_MINUS)
|
||||
padlen = -padlen; /* Left Justifty */
|
||||
|
||||
if ((flags & DP_F_ZERO) && (padlen > 0)) {
|
||||
if (signvalue) {
|
||||
dopr_outch (buffer, currlen, maxlen, signvalue);
|
||||
--padlen;
|
||||
signvalue = 0;
|
||||
}
|
||||
while (padlen > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, '0');
|
||||
--padlen;
|
||||
}
|
||||
}
|
||||
while (padlen > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--padlen;
|
||||
}
|
||||
if (signvalue)
|
||||
dopr_outch (buffer, currlen, maxlen, signvalue);
|
||||
|
||||
while (iplace > 0)
|
||||
dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]);
|
||||
|
||||
#ifdef DEBUG_SNPRINTF
|
||||
printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Decimal point. This should probably use locale to find the correct
|
||||
* char to print out.
|
||||
*/
|
||||
if (max > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, '.');
|
||||
|
||||
while (fplace > 0)
|
||||
dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]);
|
||||
}
|
||||
|
||||
while (zpadlen > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, '0');
|
||||
--zpadlen;
|
||||
}
|
||||
|
||||
while (padlen < 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++padlen;
|
||||
}
|
||||
}
|
||||
|
||||
static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
|
||||
{
|
||||
if (*currlen < maxlen) {
|
||||
buffer[(*currlen)] = c;
|
||||
}
|
||||
(*currlen)++;
|
||||
}
|
||||
|
||||
/* yes this really must be a ||. Don't muck with this (tridge) */
|
||||
#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
|
||||
int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
|
||||
{
|
||||
return dopr(str, count, fmt, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* yes this really must be a ||. Don't muck wiith this (tridge)
|
||||
*
|
||||
* The logic for these two is that we need our own definition if the
|
||||
* OS *either* has no definition of *sprintf, or if it does have one
|
||||
* that doesn't work properly according to the autoconf test. Perhaps
|
||||
* these should really be smb_snprintf to avoid conflicts with buggy
|
||||
* linkers? -- mbp
|
||||
*/
|
||||
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_SNPRINTF)
|
||||
int snprintf(char *str,size_t count,const char *fmt,...)
|
||||
{
|
||||
size_t ret;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = vsnprintf(str, count, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VASPRINTF
|
||||
int vasprintf(char **ptr, const char *format, va_list ap)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = vsnprintf(0, 0, format, ap);
|
||||
if (ret <= 0) return ret;
|
||||
|
||||
(*ptr) = (char *)malloc(ret+1);
|
||||
if (!*ptr) return -1;
|
||||
ret = vsnprintf(*ptr, ret+1, format, ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HAVE_ASPRINTF
|
||||
int asprintf(char **ptr, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
*ptr = 0;
|
||||
va_start(ap, format);
|
||||
ret = vasprintf(ptr, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSYSLOG
|
||||
#ifdef HAVE_SYSLOG
|
||||
void vsyslog (int facility_priority, char *format, va_list arglist)
|
||||
{
|
||||
char *msg = 0;
|
||||
vasprintf(&msg, format, arglist);
|
||||
if (!msg)
|
||||
return;
|
||||
syslog(facility_priority, "%s", msg);
|
||||
free(msg);
|
||||
}
|
||||
#endif /* HAVE_SYSLOG */
|
||||
#endif /* HAVE_VSYSLOG */
|
||||
|
||||
#ifdef TEST_SNPRINTF
|
||||
|
||||
int sprintf(char *str,const char *fmt,...);
|
||||
|
||||
int main (void)
|
||||
{
|
||||
char buf1[1024];
|
||||
char buf2[1024];
|
||||
char *fp_fmt[] = {
|
||||
"%1.1f",
|
||||
"%-1.5f",
|
||||
"%1.5f",
|
||||
"%123.9f",
|
||||
"%10.5f",
|
||||
"% 10.5f",
|
||||
"%+22.9f",
|
||||
"%+4.9f",
|
||||
"%01.3f",
|
||||
"%4f",
|
||||
"%3.1f",
|
||||
"%3.2f",
|
||||
"%.0f",
|
||||
"%f",
|
||||
"-16.16f",
|
||||
0
|
||||
};
|
||||
double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
|
||||
0.9996, 1.996, 4.136, 0};
|
||||
char *int_fmt[] = {
|
||||
"%-1.5d",
|
||||
"%1.5d",
|
||||
"%123.9d",
|
||||
"%5.5d",
|
||||
"%10.5d",
|
||||
"% 10.5d",
|
||||
"%+22.33d",
|
||||
"%01.3d",
|
||||
"%4d",
|
||||
"%d",
|
||||
0
|
||||
};
|
||||
long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
|
||||
char *str_fmt[] = {
|
||||
"10.5s",
|
||||
"5.10s",
|
||||
"10.1s",
|
||||
"0.10s",
|
||||
"10.0s",
|
||||
"1.10s",
|
||||
"%s",
|
||||
"%.1s",
|
||||
"%.10s",
|
||||
"%10s",
|
||||
0
|
||||
};
|
||||
char *str_vals[] = {"hello", "a", "", "a longer string", 0};
|
||||
int x, y;
|
||||
int fail = 0;
|
||||
int num = 0;
|
||||
|
||||
printf ("Testing snprintf format codes against system sprintf...\n");
|
||||
|
||||
for (x = 0; fp_fmt[x] ; x++) {
|
||||
for (y = 0; fp_nums[y] != 0 ; y++) {
|
||||
int l1 = snprintf(0, 0, fp_fmt[x], fp_nums[y]);
|
||||
int l2 = snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]);
|
||||
sprintf (buf2, fp_fmt[x], fp_nums[y]);
|
||||
if (strcmp (buf1, buf2)) {
|
||||
printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n",
|
||||
fp_fmt[x], buf1, buf2);
|
||||
fail++;
|
||||
}
|
||||
if (l1 != l2) {
|
||||
printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, fp_fmt[x]);
|
||||
fail++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
for (x = 0; int_fmt[x] ; x++) {
|
||||
for (y = 0; int_nums[y] != 0 ; y++) {
|
||||
int l1 = snprintf(0, 0, int_fmt[x], int_nums[y]);
|
||||
int l2 = snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]);
|
||||
sprintf (buf2, int_fmt[x], int_nums[y]);
|
||||
if (strcmp (buf1, buf2)) {
|
||||
printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n",
|
||||
int_fmt[x], buf1, buf2);
|
||||
fail++;
|
||||
}
|
||||
if (l1 != l2) {
|
||||
printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, int_fmt[x]);
|
||||
fail++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
for (x = 0; str_fmt[x] ; x++) {
|
||||
for (y = 0; str_vals[y] != 0 ; y++) {
|
||||
int l1 = snprintf(0, 0, str_fmt[x], str_vals[y]);
|
||||
int l2 = snprintf(buf1, sizeof(buf1), str_fmt[x], str_vals[y]);
|
||||
sprintf (buf2, str_fmt[x], str_vals[y]);
|
||||
if (strcmp (buf1, buf2)) {
|
||||
printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n",
|
||||
str_fmt[x], buf1, buf2);
|
||||
fail++;
|
||||
}
|
||||
if (l1 != l2) {
|
||||
printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, str_fmt[x]);
|
||||
fail++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
printf ("%d tests failed out of %d.\n", fail, num);
|
||||
|
||||
printf("seeing how many digits we support\n");
|
||||
{
|
||||
double v0 = 0.12345678901234567890123456789012345678901;
|
||||
for (x=0; x<100; x++) {
|
||||
snprintf(buf1, sizeof(buf1), "%1.1f", v0*pow(10, x));
|
||||
sprintf(buf2, "%1.1f", v0*pow(10, x));
|
||||
if (strcmp(buf1, buf2)) {
|
||||
printf("we seem to support %d digits\n", x-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* SNPRINTF_TEST */
|
||||
361
CCache/stats.c
361
CCache/stats.c
|
|
@ -1,361 +0,0 @@
|
|||
/*
|
||||
Copyright (C) Andrew Tridgell 2002
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
routines to handle the stats files
|
||||
|
||||
the stats file is stored one per cache subdirectory to make this more
|
||||
scalable
|
||||
*/
|
||||
|
||||
#include "ccache.h"
|
||||
|
||||
extern char *stats_file;
|
||||
extern char *cache_dir;
|
||||
|
||||
#define STATS_VERSION 1
|
||||
|
||||
#define FLAG_NOZERO 1 /* don't zero with the -z option */
|
||||
#define FLAG_ALWAYS 2 /* always show, even if zero */
|
||||
|
||||
static struct {
|
||||
enum stats stat;
|
||||
char *message;
|
||||
void (*fn)(unsigned );
|
||||
unsigned flags;
|
||||
} stats_info[] = {
|
||||
{ STATS_CACHED, "cache hit ", NULL, FLAG_ALWAYS },
|
||||
{ STATS_TOCACHE, "cache miss ", NULL, FLAG_ALWAYS },
|
||||
{ STATS_LINK, "called for link ", NULL, 0 },
|
||||
{ STATS_MULTIPLE, "multiple source files ", NULL, 0 },
|
||||
{ STATS_STDOUT, "compiler produced stdout ", NULL, 0 },
|
||||
{ STATS_STATUS, "compile failed ", NULL, 0 },
|
||||
{ STATS_ERROR, "ccache internal error ", NULL, 0 },
|
||||
{ STATS_PREPROCESSOR, "preprocessor error ", NULL, 0 },
|
||||
{ STATS_COMPILER, "couldn't find the compiler ", NULL, 0 },
|
||||
{ STATS_MISSING, "cache file missing ", NULL, 0 },
|
||||
{ STATS_ARGS, "bad compiler arguments ", NULL, 0 },
|
||||
{ STATS_NOTC, "not a C/C++ file ", NULL, 0 },
|
||||
{ STATS_CONFTEST, "autoconf compile/link ", NULL, 0 },
|
||||
{ STATS_UNSUPPORTED, "unsupported compiler option ", NULL, 0 },
|
||||
{ STATS_OUTSTDOUT, "output to stdout ", NULL, 0 },
|
||||
{ STATS_DEVICE, "output to a non-regular file ", NULL, 0 },
|
||||
{ STATS_NOINPUT, "no input file ", NULL, 0 },
|
||||
{ STATS_ENVIRONMMENT, "error due to bad env variable ", NULL, 0 },
|
||||
{ STATS_NUMFILES, "files in cache ", NULL, FLAG_NOZERO|FLAG_ALWAYS },
|
||||
{ STATS_TOTALSIZE, "cache size ", display_size , FLAG_NOZERO|FLAG_ALWAYS },
|
||||
{ STATS_MAXFILES, "max files ", NULL, FLAG_NOZERO },
|
||||
{ STATS_MAXSIZE, "max cache size ", display_size, FLAG_NOZERO },
|
||||
{ STATS_NONE, NULL, NULL, 0 }
|
||||
};
|
||||
|
||||
/* parse a stats file from a buffer - adding to the counters */
|
||||
static void parse_stats(unsigned counters[STATS_END], char *buf)
|
||||
{
|
||||
int i;
|
||||
char *p, *p2;
|
||||
|
||||
p = buf;
|
||||
for (i=0;i<STATS_END;i++) {
|
||||
counters[i] += strtol(p, &p2, 10);
|
||||
if (!p2 || p2 == p) break;
|
||||
p = p2;
|
||||
}
|
||||
}
|
||||
|
||||
/* write out a stats file */
|
||||
static void write_stats(int fd, unsigned counters[STATS_END])
|
||||
{
|
||||
int i;
|
||||
int len = 0;
|
||||
char buf[1024];
|
||||
|
||||
for (i=0;i<STATS_END;i++) {
|
||||
len += snprintf(buf+len, sizeof(buf)-(len+1), "%u ", counters[i]);
|
||||
if (len >= (int)sizeof(buf)-1) fatal("stats too long?!");
|
||||
}
|
||||
len += snprintf(buf+len, sizeof(buf)-(len+1), "\n");
|
||||
if (len >= (int)sizeof(buf)-1) fatal("stats too long?!");
|
||||
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
if (write(fd, buf, len) == -1) fatal("could not write stats");
|
||||
}
|
||||
|
||||
|
||||
/* fill in some default stats values */
|
||||
static void stats_default(unsigned counters[STATS_END])
|
||||
{
|
||||
counters[STATS_MAXSIZE] += DEFAULT_MAXSIZE / 16;
|
||||
}
|
||||
|
||||
/* read in the stats from one dir and add to the counters */
|
||||
static void stats_read_fd(int fd, unsigned counters[STATS_END])
|
||||
{
|
||||
char buf[1024];
|
||||
int len;
|
||||
len = read(fd, buf, sizeof(buf)-1);
|
||||
if (len <= 0) {
|
||||
stats_default(counters);
|
||||
return;
|
||||
}
|
||||
buf[len] = 0;
|
||||
parse_stats(counters, buf);
|
||||
}
|
||||
|
||||
/* update the stats counter for this compile */
|
||||
static void stats_update_size(enum stats stat, size_t size, size_t numfiles)
|
||||
{
|
||||
int fd;
|
||||
unsigned counters[STATS_END];
|
||||
int need_cleanup = 0;
|
||||
|
||||
if (getenv("CCACHE_NOSTATS")) return;
|
||||
|
||||
if (!stats_file) {
|
||||
if (!cache_dir) return;
|
||||
x_asprintf(&stats_file, "%s/stats", cache_dir);
|
||||
}
|
||||
|
||||
/* open safely to try to prevent symlink races */
|
||||
fd = safe_open(stats_file);
|
||||
|
||||
/* still can't get it? don't bother ... */
|
||||
if (fd == -1) return;
|
||||
|
||||
memset(counters, 0, sizeof(counters));
|
||||
|
||||
if (lock_fd(fd) != 0) return;
|
||||
|
||||
/* read in the old stats */
|
||||
stats_read_fd(fd, counters);
|
||||
|
||||
/* update them */
|
||||
counters[stat]++;
|
||||
|
||||
/* on a cache miss we up the file count and size */
|
||||
if (stat == STATS_TOCACHE) {
|
||||
counters[STATS_NUMFILES] += numfiles;
|
||||
counters[STATS_TOTALSIZE] += size;
|
||||
}
|
||||
|
||||
/* and write them out */
|
||||
write_stats(fd, counters);
|
||||
close(fd);
|
||||
|
||||
/* we might need to cleanup if the cache has now got too big */
|
||||
if (counters[STATS_MAXFILES] != 0 &&
|
||||
counters[STATS_NUMFILES] > counters[STATS_MAXFILES]) {
|
||||
need_cleanup = 1;
|
||||
}
|
||||
if (counters[STATS_MAXSIZE] != 0 &&
|
||||
counters[STATS_TOTALSIZE] > counters[STATS_MAXSIZE]) {
|
||||
need_cleanup = 1;
|
||||
}
|
||||
|
||||
if (need_cleanup) {
|
||||
char *p = dirname(stats_file);
|
||||
cleanup_dir(p, counters[STATS_MAXFILES], counters[STATS_MAXSIZE]);
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* record a cache miss */
|
||||
void stats_tocache(size_t size, size_t numfiles)
|
||||
{
|
||||
/* convert size to kilobytes */
|
||||
size = size / 1024;
|
||||
|
||||
stats_update_size(STATS_TOCACHE, size, numfiles);
|
||||
}
|
||||
|
||||
/* update a normal stat */
|
||||
void stats_update(enum stats stat)
|
||||
{
|
||||
stats_update_size(stat, 0, 0);
|
||||
}
|
||||
|
||||
/* read in the stats from one dir and add to the counters */
|
||||
void stats_read(const char *stats_file, unsigned counters[STATS_END])
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(stats_file, O_RDONLY|O_BINARY);
|
||||
if (fd == -1) {
|
||||
stats_default(counters);
|
||||
return;
|
||||
}
|
||||
lock_fd(fd);
|
||||
stats_read_fd(fd, counters);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* sum and display the total stats for all cache dirs */
|
||||
void stats_summary(void)
|
||||
{
|
||||
int dir, i;
|
||||
unsigned counters[STATS_END];
|
||||
|
||||
memset(counters, 0, sizeof(counters));
|
||||
|
||||
/* add up the stats in each directory */
|
||||
for (dir=-1;dir<=0xF;dir++) {
|
||||
char *fname;
|
||||
|
||||
if (dir == -1) {
|
||||
x_asprintf(&fname, "%s/stats", cache_dir);
|
||||
} else {
|
||||
x_asprintf(&fname, "%s/%1x/stats", cache_dir, dir);
|
||||
}
|
||||
|
||||
stats_read(fname, counters);
|
||||
free(fname);
|
||||
|
||||
/* oh what a nasty hack ... */
|
||||
if (dir == -1) {
|
||||
counters[STATS_MAXSIZE] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf("cache directory %s\n", cache_dir);
|
||||
|
||||
/* and display them */
|
||||
for (i=0;stats_info[i].message;i++) {
|
||||
enum stats stat = stats_info[i].stat;
|
||||
|
||||
if (counters[stat] == 0 &&
|
||||
!(stats_info[i].flags & FLAG_ALWAYS)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s ", stats_info[i].message);
|
||||
if (stats_info[i].fn) {
|
||||
stats_info[i].fn(counters[stat]);
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("%8u\n", counters[stat]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* zero all the stats structures */
|
||||
void stats_zero(void)
|
||||
{
|
||||
int dir, fd;
|
||||
unsigned i;
|
||||
char *fname;
|
||||
unsigned counters[STATS_END];
|
||||
|
||||
x_asprintf(&fname, "%s/stats", cache_dir);
|
||||
unlink(fname);
|
||||
free(fname);
|
||||
|
||||
for (dir=0;dir<=0xF;dir++) {
|
||||
x_asprintf(&fname, "%s/%1x/stats", cache_dir, dir);
|
||||
fd = safe_open(fname);
|
||||
if (fd == -1) {
|
||||
free(fname);
|
||||
continue;
|
||||
}
|
||||
memset(counters, 0, sizeof(counters));
|
||||
lock_fd(fd);
|
||||
stats_read_fd(fd, counters);
|
||||
for (i=0;stats_info[i].message;i++) {
|
||||
if (!(stats_info[i].flags & FLAG_NOZERO)) {
|
||||
counters[stats_info[i].stat] = 0;
|
||||
}
|
||||
}
|
||||
write_stats(fd, counters);
|
||||
close(fd);
|
||||
free(fname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* set the per directory limits */
|
||||
int stats_set_limits(long maxfiles, long maxsize)
|
||||
{
|
||||
int dir;
|
||||
unsigned counters[STATS_END];
|
||||
|
||||
if (maxfiles != -1) {
|
||||
maxfiles /= 16;
|
||||
}
|
||||
if (maxsize != -1) {
|
||||
maxsize /= 16;
|
||||
}
|
||||
|
||||
if (create_dir(cache_dir) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* set the limits in each directory */
|
||||
for (dir=0;dir<=0xF;dir++) {
|
||||
char *fname, *cdir;
|
||||
int fd;
|
||||
|
||||
x_asprintf(&cdir, "%s/%1x", cache_dir, dir);
|
||||
if (create_dir(cdir) != 0) {
|
||||
return 1;
|
||||
}
|
||||
x_asprintf(&fname, "%s/stats", cdir);
|
||||
free(cdir);
|
||||
|
||||
memset(counters, 0, sizeof(counters));
|
||||
fd = safe_open(fname);
|
||||
if (fd != -1) {
|
||||
lock_fd(fd);
|
||||
stats_read_fd(fd, counters);
|
||||
if (maxfiles != -1) {
|
||||
counters[STATS_MAXFILES] = maxfiles;
|
||||
}
|
||||
if (maxsize != -1) {
|
||||
counters[STATS_MAXSIZE] = maxsize;
|
||||
}
|
||||
write_stats(fd, counters);
|
||||
close(fd);
|
||||
}
|
||||
free(fname);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set the per directory sizes */
|
||||
void stats_set_sizes(const char *dir, size_t num_files, size_t total_size)
|
||||
{
|
||||
int fd;
|
||||
unsigned counters[STATS_END];
|
||||
char *stats_file;
|
||||
|
||||
create_dir(dir);
|
||||
x_asprintf(&stats_file, "%s/stats", dir);
|
||||
|
||||
memset(counters, 0, sizeof(counters));
|
||||
|
||||
fd = safe_open(stats_file);
|
||||
if (fd != -1) {
|
||||
lock_fd(fd);
|
||||
stats_read_fd(fd, counters);
|
||||
counters[STATS_NUMFILES] = num_files;
|
||||
counters[STATS_TOTALSIZE] = total_size;
|
||||
write_stats(fd, counters);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
free(stats_file);
|
||||
}
|
||||
452
CCache/test.sh
452
CCache/test.sh
|
|
@ -1,452 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# a simple test suite for ccache
|
||||
# tridge@samba.org
|
||||
|
||||
if test -n "$CC"; then
|
||||
COMPILER="$CC"
|
||||
else
|
||||
COMPILER=cc
|
||||
fi
|
||||
|
||||
if test -n "$SWIG"; then
|
||||
SWIG="$SWIG"
|
||||
else
|
||||
SWIG=swig
|
||||
fi
|
||||
|
||||
CCACHE=../ccache-swig
|
||||
TESTDIR=test.$$
|
||||
|
||||
test_failed() {
|
||||
reason="$1"
|
||||
echo $1
|
||||
$CCACHE -s
|
||||
cd ..
|
||||
rm -rf $TESTDIR
|
||||
echo TEST FAILED
|
||||
exit 1
|
||||
}
|
||||
|
||||
randcode() {
|
||||
outfile="$1"
|
||||
nlines=$2
|
||||
i=0;
|
||||
(
|
||||
while [ $i -lt $nlines ]; do
|
||||
echo "int foo$nlines$i(int x) { return x; }"
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
) >> "$outfile"
|
||||
}
|
||||
|
||||
genswigcode() {
|
||||
outfile="$1"
|
||||
nlines=$2
|
||||
i=0;
|
||||
(
|
||||
echo "%module swigtest$2;"
|
||||
while [ $i -lt $nlines ]; do
|
||||
echo "int foo$nlines$i(int x);"
|
||||
echo "struct Bar$nlines$i { int y; };"
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
) >> "$outfile"
|
||||
}
|
||||
|
||||
|
||||
getstat() {
|
||||
stat="$1"
|
||||
value=`$CCACHE -s | grep "$stat" | cut -c34-40`
|
||||
echo $value
|
||||
}
|
||||
|
||||
checkstat() {
|
||||
stat="$1"
|
||||
expected_value="$2"
|
||||
value=`getstat "$stat"`
|
||||
# echo "exp: $expected_value got: $value $testname"
|
||||
if [ "$expected_value" != "$value" ]; then
|
||||
test_failed "SUITE: $testsuite TEST: $testname - Expected $stat to be $expected_value got $value"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
basetests() {
|
||||
echo "starting testsuite $testsuite"
|
||||
rm -rf "$CCACHE_DIR"
|
||||
checkstat 'cache hit' 0
|
||||
checkstat 'cache miss' 0
|
||||
|
||||
j=1
|
||||
rm -f *.c
|
||||
while [ $j -lt 32 ]; do
|
||||
randcode test$j.c $j
|
||||
j=`expr $j + 1`
|
||||
done
|
||||
|
||||
testname="BASIC"
|
||||
$CCACHE_COMPILE -c test1.c
|
||||
checkstat 'cache hit' 0
|
||||
checkstat 'cache miss' 1
|
||||
|
||||
testname="BASIC2"
|
||||
$CCACHE_COMPILE -c test1.c
|
||||
checkstat 'cache hit' 1
|
||||
checkstat 'cache miss' 1
|
||||
|
||||
testname="debug"
|
||||
$CCACHE_COMPILE -c test1.c -g
|
||||
checkstat 'cache hit' 1
|
||||
checkstat 'cache miss' 2
|
||||
|
||||
testname="debug2"
|
||||
$CCACHE_COMPILE -c test1.c -g
|
||||
checkstat 'cache hit' 2
|
||||
checkstat 'cache miss' 2
|
||||
|
||||
testname="output"
|
||||
$CCACHE_COMPILE -c test1.c -o foo.o
|
||||
checkstat 'cache hit' 3
|
||||
checkstat 'cache miss' 2
|
||||
|
||||
testname="link"
|
||||
$CCACHE_COMPILE test1.c -o test 2> /dev/null
|
||||
checkstat 'called for link' 1
|
||||
|
||||
testname="multiple"
|
||||
$CCACHE_COMPILE -c test1.c test2.c
|
||||
checkstat 'multiple source files' 1
|
||||
|
||||
testname="find"
|
||||
$CCACHE blahblah -c test1.c 2> /dev/null
|
||||
checkstat "couldn't find the compiler" 1
|
||||
|
||||
testname="bad"
|
||||
$CCACHE_COMPILE -c test1.c -I 2> /dev/null
|
||||
checkstat 'bad compiler arguments' 1
|
||||
|
||||
testname="c/c++"
|
||||
ln -f test1.c test1.ccc
|
||||
$CCACHE_COMPILE -c test1.ccc 2> /dev/null
|
||||
checkstat 'not a C/C++ file' 1
|
||||
|
||||
testname="unsupported"
|
||||
$CCACHE_COMPILE -M foo -c test1.c > /dev/null 2>&1
|
||||
checkstat 'unsupported compiler option' 1
|
||||
|
||||
testname="stdout"
|
||||
$CCACHE echo foo -c test1.c > /dev/null
|
||||
checkstat 'compiler produced stdout' 1
|
||||
|
||||
testname="non-regular"
|
||||
mkdir testd
|
||||
$CCACHE_COMPILE -o testd -c test1.c > /dev/null 2>&1
|
||||
rmdir testd
|
||||
checkstat 'output to a non-regular file' 1
|
||||
|
||||
testname="no-input"
|
||||
$CCACHE_COMPILE -c -O2 2> /dev/null
|
||||
checkstat 'no input file' 1
|
||||
|
||||
|
||||
testname="CCACHE_DISABLE"
|
||||
CCACHE_DISABLE=1 $CCACHE_COMPILE -c test1.c 2> /dev/null
|
||||
checkstat 'cache hit' 3
|
||||
$CCACHE_COMPILE -c test1.c
|
||||
checkstat 'cache hit' 4
|
||||
|
||||
testname="CCACHE_CPP2"
|
||||
CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -O
|
||||
checkstat 'cache hit' 4
|
||||
checkstat 'cache miss' 3
|
||||
|
||||
CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -O
|
||||
checkstat 'cache hit' 5
|
||||
checkstat 'cache miss' 3
|
||||
|
||||
testname="CCACHE_NOSTATS"
|
||||
CCACHE_NOSTATS=1 $CCACHE_COMPILE -c test1.c -O -O
|
||||
checkstat 'cache hit' 5
|
||||
checkstat 'cache miss' 3
|
||||
|
||||
testname="CCACHE_RECACHE"
|
||||
CCACHE_RECACHE=1 $CCACHE_COMPILE -c test1.c -O -O
|
||||
checkstat 'cache hit' 5
|
||||
checkstat 'cache miss' 4
|
||||
|
||||
# strictly speaking should be 6 - RECACHE causes a double counting!
|
||||
checkstat 'files in cache' 8
|
||||
$CCACHE -c > /dev/null
|
||||
checkstat 'files in cache' 6
|
||||
|
||||
|
||||
testname="CCACHE_HASHDIR"
|
||||
CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O
|
||||
checkstat 'cache hit' 5
|
||||
checkstat 'cache miss' 5
|
||||
|
||||
CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O
|
||||
checkstat 'cache hit' 6
|
||||
checkstat 'cache miss' 5
|
||||
|
||||
checkstat 'files in cache' 8
|
||||
|
||||
testname="comments"
|
||||
echo '/* a silly comment */' > test1-comment.c
|
||||
cat test1.c >> test1-comment.c
|
||||
$CCACHE_COMPILE -c test1-comment.c
|
||||
rm -f test1-comment*
|
||||
checkstat 'cache hit' 6
|
||||
checkstat 'cache miss' 6
|
||||
|
||||
testname="CCACHE_UNIFY"
|
||||
CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c
|
||||
checkstat 'cache hit' 6
|
||||
checkstat 'cache miss' 7
|
||||
mv test1.c test1-saved.c
|
||||
echo '/* another comment */' > test1.c
|
||||
cat test1-saved.c >> test1.c
|
||||
CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c
|
||||
mv test1-saved.c test1.c
|
||||
checkstat 'cache hit' 7
|
||||
checkstat 'cache miss' 7
|
||||
|
||||
testname="cache-size"
|
||||
for f in *.c; do
|
||||
$CCACHE_COMPILE -c $f
|
||||
done
|
||||
checkstat 'cache hit' 8
|
||||
checkstat 'cache miss' 37
|
||||
checkstat 'files in cache' 72
|
||||
$CCACHE -F 48 -c > /dev/null
|
||||
if [ `getstat 'files in cache'` -gt 48 ]; then
|
||||
test_failed '-F test failed'
|
||||
fi
|
||||
|
||||
testname="cpp call"
|
||||
$CCACHE_COMPILE -c test1.c -E > test1.i
|
||||
checkstat 'cache hit' 8
|
||||
checkstat 'cache miss' 37
|
||||
|
||||
testname="direct .i compile"
|
||||
$CCACHE_COMPILE -c test1.c
|
||||
checkstat 'cache hit' 8
|
||||
checkstat 'cache miss' 38
|
||||
|
||||
$CCACHE_COMPILE -c test1.i
|
||||
checkstat 'cache hit' 9
|
||||
checkstat 'cache miss' 38
|
||||
|
||||
$CCACHE_COMPILE -c test1.i
|
||||
checkstat 'cache hit' 10
|
||||
checkstat 'cache miss' 38
|
||||
|
||||
# removed these tests as some compilers (including newer versions of gcc)
|
||||
# determine which language to use based on .ii/.i extension, and C++ may
|
||||
# not be installed
|
||||
# testname="direct .ii file"
|
||||
# mv test1.i test1.ii
|
||||
# $CCACHE_COMPILE -c test1.ii
|
||||
# checkstat 'cache hit' 10
|
||||
# checkstat 'cache miss' 39
|
||||
|
||||
# $CCACHE_COMPILE -c test1.ii
|
||||
# checkstat 'cache hit' 11
|
||||
# checkstat 'cache miss' 39
|
||||
|
||||
testname="stripc" # This test might not be portable
|
||||
CCACHE_STRIPC=1 $CCACHE_COMPILE -c test1.c
|
||||
checkstat 'cache hit' 10
|
||||
checkstat 'cache miss' 39
|
||||
|
||||
CCACHE_STRIPC=1 $CCACHE_COMPILE -c test1.c
|
||||
checkstat 'cache hit' 11
|
||||
checkstat 'cache miss' 39
|
||||
|
||||
testname="zero-stats"
|
||||
$CCACHE -z > /dev/null
|
||||
checkstat 'cache hit' 0
|
||||
checkstat 'cache miss' 0
|
||||
|
||||
testname="clear"
|
||||
$CCACHE -C > /dev/null
|
||||
checkstat 'files in cache' 0
|
||||
|
||||
|
||||
rm -f test1.c
|
||||
}
|
||||
|
||||
swigtests() {
|
||||
echo "starting swig testsuite $testsuite"
|
||||
rm -rf "$CCACHE_DIR"
|
||||
checkstat 'cache hit' 0
|
||||
checkstat 'cache miss' 0
|
||||
|
||||
j=1
|
||||
rm -f *.i
|
||||
genswigcode testswig1.i 1
|
||||
|
||||
testname="BASIC"
|
||||
$CCACHE_COMPILE -java testswig1.i
|
||||
checkstat 'cache hit' 0
|
||||
checkstat 'cache miss' 1
|
||||
|
||||
checkstat 'files in cache' 6
|
||||
|
||||
testname="BASIC2"
|
||||
$CCACHE_COMPILE -java testswig1.i
|
||||
checkstat 'cache hit' 1
|
||||
checkstat 'cache miss' 1
|
||||
|
||||
testname="output"
|
||||
$CCACHE_COMPILE -java testswig1.i -o foo_wrap.c
|
||||
checkstat 'cache hit' 1
|
||||
checkstat 'cache miss' 2
|
||||
|
||||
testname="bad"
|
||||
$CCACHE_COMPILE -java testswig1.i -I 2> /dev/null
|
||||
checkstat 'bad compiler arguments' 1
|
||||
|
||||
testname="stdout"
|
||||
$CCACHE_COMPILE -v -java testswig1.i > /dev/null
|
||||
checkstat 'compiler produced stdout' 1
|
||||
|
||||
testname="non-regular"
|
||||
mkdir testd
|
||||
$CCACHE_COMPILE -o testd -java testswig1.i > /dev/null 2>&1
|
||||
rmdir testd
|
||||
checkstat 'output to a non-regular file' 1
|
||||
|
||||
testname="no-input"
|
||||
$CCACHE_COMPILE -java 2> /dev/null
|
||||
checkstat 'no input file' 1
|
||||
|
||||
|
||||
testname="CCACHE_DISABLE"
|
||||
CCACHE_DISABLE=1 $CCACHE_COMPILE -java testswig1.i 2> /dev/null
|
||||
checkstat 'cache hit' 1
|
||||
$CCACHE_COMPILE -java testswig1.i
|
||||
checkstat 'cache hit' 2
|
||||
|
||||
testname="CCACHE_CPP2"
|
||||
CCACHE_CPP2=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
||||
checkstat 'cache hit' 2
|
||||
checkstat 'cache miss' 3
|
||||
|
||||
CCACHE_CPP2=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
||||
checkstat 'cache hit' 3
|
||||
checkstat 'cache miss' 3
|
||||
|
||||
testname="CCACHE_NOSTATS"
|
||||
CCACHE_NOSTATS=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
||||
checkstat 'cache hit' 3
|
||||
checkstat 'cache miss' 3
|
||||
|
||||
testname="CCACHE_RECACHE"
|
||||
CCACHE_RECACHE=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
||||
checkstat 'cache hit' 3
|
||||
checkstat 'cache miss' 4
|
||||
|
||||
# strictly speaking should be 3x6=18 instead of 4x6=24 - RECACHE causes a double counting!
|
||||
checkstat 'files in cache' 24
|
||||
$CCACHE -c > /dev/null
|
||||
checkstat 'files in cache' 18
|
||||
|
||||
|
||||
testname="CCACHE_HASHDIR"
|
||||
CCACHE_HASHDIR=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
||||
checkstat 'cache hit' 3
|
||||
checkstat 'cache miss' 5
|
||||
|
||||
CCACHE_HASHDIR=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
||||
checkstat 'cache hit' 4
|
||||
checkstat 'cache miss' 5
|
||||
|
||||
checkstat 'files in cache' 24
|
||||
|
||||
testname="cpp call"
|
||||
$CCACHE_COMPILE -java -E testswig1.i > testswig1-preproc.i
|
||||
checkstat 'cache hit' 4
|
||||
checkstat 'cache miss' 5
|
||||
|
||||
testname="direct .i compile"
|
||||
$CCACHE_COMPILE -java testswig1.i
|
||||
checkstat 'cache hit' 5
|
||||
checkstat 'cache miss' 5
|
||||
|
||||
# No cache hit due to different input file name, -nopreprocess should not be given twice to SWIG
|
||||
$CCACHE_COMPILE -java -nopreprocess testswig1-preproc.i
|
||||
checkstat 'cache hit' 5
|
||||
checkstat 'cache miss' 6
|
||||
|
||||
$CCACHE_COMPILE -java -nopreprocess testswig1-preproc.i
|
||||
checkstat 'cache hit' 6
|
||||
checkstat 'cache miss' 6
|
||||
|
||||
testname="stripc"
|
||||
CCACHE_STRIPC=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
||||
checkstat 'cache hit' 7
|
||||
checkstat 'cache miss' 6
|
||||
|
||||
CCACHE_STRIPC=1 $CCACHE_COMPILE -java -O -O -O testswig1.i
|
||||
checkstat 'cache hit' 7
|
||||
checkstat 'cache miss' 7
|
||||
|
||||
rm -f testswig1-preproc.i
|
||||
rm -f testswig1.i
|
||||
}
|
||||
|
||||
######
|
||||
# main program
|
||||
rm -rf $TESTDIR
|
||||
mkdir $TESTDIR
|
||||
cd $TESTDIR || exit 1
|
||||
CCACHE_DIR="ccache dir" # with space in directory name (like Windows default)
|
||||
mkdir "$CCACHE_DIR"
|
||||
export CCACHE_DIR
|
||||
|
||||
testsuite="base"
|
||||
CCACHE_COMPILE="$CCACHE $COMPILER"
|
||||
basetests
|
||||
CCACHE_COMPILE="$CCACHE $SWIG"
|
||||
swigtests
|
||||
|
||||
if test -z "$NOSOFTLINKSTEST"; then
|
||||
testsuite="link"
|
||||
ln -s $CCACHE $COMPILER
|
||||
CCACHE_COMPILE="./$COMPILER"
|
||||
basetests
|
||||
rm "./$COMPILER"
|
||||
ln -s $CCACHE $SWIG
|
||||
CCACHE_COMPILE="./$SWIG"
|
||||
swigtests
|
||||
rm "./$SWIG"
|
||||
else
|
||||
echo "skipping testsuite link"
|
||||
fi
|
||||
|
||||
testsuite="hardlink"
|
||||
CCACHE_COMPILE="env CCACHE_NOCOMPRESS=1 CCACHE_HARDLINK=1 $CCACHE $COMPILER"
|
||||
basetests
|
||||
CCACHE_COMPILE="env CCACHE_NOCOMPRESS=1 CCACHE_HARDLINK=1 $CCACHE $SWIG"
|
||||
swigtests
|
||||
|
||||
testsuite="cpp2"
|
||||
CCACHE_COMPILE="env CCACHE_CPP2=1 $CCACHE $COMPILER"
|
||||
basetests
|
||||
CCACHE_COMPILE="env CCACHE_CPP2=1 $CCACHE $SWIG"
|
||||
swigtests
|
||||
|
||||
testsuite="nlevels4"
|
||||
CCACHE_COMPILE="env CCACHE_NLEVELS=4 $CCACHE $COMPILER"
|
||||
basetests
|
||||
|
||||
testsuite="nlevels1"
|
||||
CCACHE_COMPILE="env CCACHE_NLEVELS=1 $CCACHE $COMPILER"
|
||||
basetests
|
||||
|
||||
cd ..
|
||||
rm -rf $TESTDIR
|
||||
echo test done - OK
|
||||
exit 0
|
||||
307
CCache/unify.c
307
CCache/unify.c
|
|
@ -1,307 +0,0 @@
|
|||
/*
|
||||
Copyright (C) Andrew Tridgell 2002
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
C/C++ unifier
|
||||
|
||||
the idea is that changes that don't affect the resulting C code
|
||||
should not change the hash. This is achieved by folding white-space
|
||||
and other non-semantic fluff in the input into a single unified format.
|
||||
|
||||
This unifier was design to match the output of the unifier in
|
||||
compilercache, which is flex based. The major difference is that
|
||||
this unifier is much faster (about 2x) and more forgiving of
|
||||
syntactic errors. Continuing on syntactic errors is important to
|
||||
cope with C/C++ extensions in the local compiler (for example,
|
||||
inline assembly systems).
|
||||
*/
|
||||
|
||||
#include "ccache.h"
|
||||
|
||||
static char *s_tokens[] = {
|
||||
"...", ">>=", "<<=", "+=", "-=", "*=", "/=", "%=", "&=", "^=",
|
||||
"|=", ">>", "<<", "++", "--", "->", "&&", "||", "<=", ">=",
|
||||
"==", "!=", ";", "{", "<%", "}", "%>", ",", ":", "=",
|
||||
"(", ")", "[", "<:", "]", ":>", ".", "&", "!", "~",
|
||||
"-", "+", "*", "/", "%", "<", ">", "^", "|", "?",
|
||||
0
|
||||
};
|
||||
|
||||
#define C_ALPHA 1
|
||||
#define C_SPACE 2
|
||||
#define C_TOKEN 4
|
||||
#define C_QUOTE 8
|
||||
#define C_DIGIT 16
|
||||
#define C_HEX 32
|
||||
#define C_FLOAT 64
|
||||
#define C_SIGN 128
|
||||
|
||||
static struct {
|
||||
unsigned char type;
|
||||
unsigned char num_toks;
|
||||
char *toks[7];
|
||||
} tokens[256];
|
||||
|
||||
/* build up the table used by the unifier */
|
||||
static void build_table(void)
|
||||
{
|
||||
unsigned char c;
|
||||
int i;
|
||||
static int done;
|
||||
|
||||
if (done) return;
|
||||
done = 1;
|
||||
|
||||
memset(tokens, 0, sizeof(tokens));
|
||||
for (c=0;c<128;c++) {
|
||||
if (isalpha(c) || c == '_') tokens[c].type |= C_ALPHA;
|
||||
if (isdigit(c)) tokens[c].type |= C_DIGIT;
|
||||
if (isspace(c)) tokens[c].type |= C_SPACE;
|
||||
if (isxdigit(c)) tokens[c].type |= C_HEX;
|
||||
}
|
||||
tokens['\''].type |= C_QUOTE;
|
||||
tokens['"'].type |= C_QUOTE;
|
||||
tokens['l'].type |= C_FLOAT;
|
||||
tokens['L'].type |= C_FLOAT;
|
||||
tokens['f'].type |= C_FLOAT;
|
||||
tokens['F'].type |= C_FLOAT;
|
||||
tokens['U'].type |= C_FLOAT;
|
||||
tokens['u'].type |= C_FLOAT;
|
||||
|
||||
tokens['-'].type |= C_SIGN;
|
||||
tokens['+'].type |= C_SIGN;
|
||||
|
||||
for (i=0;s_tokens[i];i++) {
|
||||
c = s_tokens[i][0];
|
||||
tokens[c].type |= C_TOKEN;
|
||||
tokens[c].toks[tokens[c].num_toks] = s_tokens[i];
|
||||
tokens[c].num_toks++;
|
||||
}
|
||||
}
|
||||
|
||||
/* buffer up characters before hashing them */
|
||||
static void pushchar(unsigned char c)
|
||||
{
|
||||
static unsigned char buf[64];
|
||||
static int len;
|
||||
|
||||
if (c == 0) {
|
||||
if (len > 0) {
|
||||
hash_buffer((char *)buf, len);
|
||||
len = 0;
|
||||
}
|
||||
hash_buffer(NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
buf[len++] = c;
|
||||
if (len == 64) {
|
||||
hash_buffer((char *)buf, len);
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* hash some C/C++ code after unifying */
|
||||
static void unify(unsigned char *p, size_t size)
|
||||
{
|
||||
size_t ofs;
|
||||
unsigned char q;
|
||||
int i;
|
||||
|
||||
build_table();
|
||||
|
||||
for (ofs=0; ofs<size;) {
|
||||
if (p[ofs] == '#') {
|
||||
if ((size-ofs) > 2 && p[ofs+1] == ' ' && isdigit(p[ofs+2])) {
|
||||
do {
|
||||
ofs++;
|
||||
} while (ofs < size && p[ofs] != '\n');
|
||||
ofs++;
|
||||
} else {
|
||||
do {
|
||||
pushchar(p[ofs]);
|
||||
ofs++;
|
||||
} while (ofs < size && p[ofs] != '\n');
|
||||
pushchar('\n');
|
||||
ofs++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens[p[ofs]].type & C_ALPHA) {
|
||||
do {
|
||||
pushchar(p[ofs]);
|
||||
ofs++;
|
||||
} while (ofs < size &&
|
||||
(tokens[p[ofs]].type & (C_ALPHA|C_DIGIT)));
|
||||
pushchar('\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens[p[ofs]].type & C_DIGIT) {
|
||||
do {
|
||||
pushchar(p[ofs]);
|
||||
ofs++;
|
||||
} while (ofs < size &&
|
||||
((tokens[p[ofs]].type & C_DIGIT) || p[ofs] == '.'));
|
||||
if (ofs < size && (p[ofs] == 'x' || p[ofs] == 'X')) {
|
||||
do {
|
||||
pushchar(p[ofs]);
|
||||
ofs++;
|
||||
} while (ofs < size && (tokens[p[ofs]].type & C_HEX));
|
||||
}
|
||||
if (ofs < size && (p[ofs] == 'E' || p[ofs] == 'e')) {
|
||||
pushchar(p[ofs]);
|
||||
ofs++;
|
||||
while (ofs < size &&
|
||||
(tokens[p[ofs]].type & (C_DIGIT|C_SIGN))) {
|
||||
pushchar(p[ofs]);
|
||||
ofs++;
|
||||
}
|
||||
}
|
||||
while (ofs < size && (tokens[p[ofs]].type & C_FLOAT)) {
|
||||
pushchar(p[ofs]);
|
||||
ofs++;
|
||||
}
|
||||
pushchar('\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens[p[ofs]].type & C_SPACE) {
|
||||
do {
|
||||
ofs++;
|
||||
} while (ofs < size && (tokens[p[ofs]].type & C_SPACE));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens[p[ofs]].type & C_QUOTE) {
|
||||
q = p[ofs];
|
||||
pushchar(p[ofs]);
|
||||
do {
|
||||
ofs++;
|
||||
while (ofs < size-1 && p[ofs] == '\\') {
|
||||
pushchar(p[ofs]);
|
||||
pushchar(p[ofs+1]);
|
||||
ofs+=2;
|
||||
}
|
||||
pushchar(p[ofs]);
|
||||
} while (ofs < size && p[ofs] != q);
|
||||
pushchar('\n');
|
||||
ofs++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens[p[ofs]].type & C_TOKEN) {
|
||||
q = p[ofs];
|
||||
for (i=0;i<tokens[q].num_toks;i++) {
|
||||
unsigned char *s = (unsigned char *)tokens[q].toks[i];
|
||||
int len = strlen((char *)s);
|
||||
if (size >= ofs+len && memcmp(&p[ofs], s, len) == 0) {
|
||||
int j;
|
||||
for (j=0;s[j];j++) {
|
||||
pushchar(s[j]);
|
||||
ofs++;
|
||||
}
|
||||
pushchar('\n');
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < tokens[q].num_toks) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
pushchar(p[ofs]);
|
||||
pushchar('\n');
|
||||
ofs++;
|
||||
}
|
||||
pushchar(0);
|
||||
}
|
||||
|
||||
|
||||
/* hash a file that consists of preprocessor output, but remove any line
|
||||
number information from the hash
|
||||
*/
|
||||
int unify_hash(const char *fname)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HANDLE file;
|
||||
HANDLE section;
|
||||
DWORD filesize_low;
|
||||
char *map;
|
||||
int ret = -1;
|
||||
|
||||
file = CreateFileA(fname, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, 0, NULL);
|
||||
if (file != INVALID_HANDLE_VALUE) {
|
||||
filesize_low = GetFileSize(file, NULL);
|
||||
if (!(filesize_low == INVALID_FILE_SIZE && GetLastError() != NO_ERROR)) {
|
||||
section = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
CloseHandle(file);
|
||||
if (section != NULL) {
|
||||
map = MapViewOfFile(section, FILE_MAP_READ, 0, 0, 0);
|
||||
CloseHandle(section);
|
||||
if (map != NULL)
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == -1) {
|
||||
cc_log("Failed to open preprocessor output %s\n", fname);
|
||||
stats_update(STATS_PREPROCESSOR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* pass it through the unifier */
|
||||
unify((unsigned char *)map, filesize_low);
|
||||
|
||||
UnmapViewOfFile(map);
|
||||
|
||||
return 0;
|
||||
#else
|
||||
int fd;
|
||||
struct stat st;
|
||||
char *map;
|
||||
|
||||
fd = open(fname, O_RDONLY|O_BINARY);
|
||||
if (fd == -1 || fstat(fd, &st) != 0) {
|
||||
cc_log("Failed to open preprocessor output %s\n", fname);
|
||||
stats_update(STATS_PREPROCESSOR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* we use mmap() to make it easy to handle arbitrarily long
|
||||
lines in preprocessor output. I have seen lines of over
|
||||
100k in length, so this is well worth it */
|
||||
map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (map == (char *)-1) {
|
||||
cc_log("Failed to mmap %s\n", fname);
|
||||
stats_update(STATS_PREPROCESSOR);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
/* pass it through the unifier */
|
||||
unify((unsigned char *)map, st.st_size);
|
||||
|
||||
munmap(map, st.st_size);
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
884
CCache/util.c
884
CCache/util.c
|
|
@ -1,884 +0,0 @@
|
|||
/*
|
||||
Copyright (C) Andrew Tridgell 2002
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "ccache.h"
|
||||
|
||||
static FILE *logfile;
|
||||
|
||||
/* log a message to the CCACHE_LOGFILE location */
|
||||
void cc_log(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
extern char *cache_logfile;
|
||||
|
||||
if (!cache_logfile) return;
|
||||
|
||||
if (!logfile) logfile = fopen(cache_logfile, "a");
|
||||
if (!logfile) return;
|
||||
|
||||
va_start(ap, format);
|
||||
vfprintf(logfile, format, ap);
|
||||
va_end(ap);
|
||||
fflush(logfile);
|
||||
}
|
||||
|
||||
/* something went badly wrong! */
|
||||
void fatal(const char *msg)
|
||||
{
|
||||
cc_log("FATAL: %s\n", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int safe_rename(const char* oldpath, const char* newpath)
|
||||
{
|
||||
/* safe_rename is for creating entries in the cache.
|
||||
|
||||
Works like rename(), but it never overwrites an existing
|
||||
cache entry. This avoids corruption on NFS. */
|
||||
#ifndef _WIN32
|
||||
int status = link(oldpath, newpath);
|
||||
if( status == 0 || errno == EEXIST )
|
||||
#else
|
||||
int status = CreateHardLinkA(newpath, oldpath, NULL) ? 0 : -1;
|
||||
if( status == 0 || GetLastError() == ERROR_ALREADY_EXISTS )
|
||||
#endif
|
||||
{
|
||||
return unlink( oldpath );
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ZLIB
|
||||
/* copy all data from one file descriptor to another */
|
||||
void copy_fd(int fd_in, int fd_out)
|
||||
{
|
||||
char buf[10240];
|
||||
int n;
|
||||
|
||||
while ((n = read(fd_in, buf, sizeof(buf))) > 0) {
|
||||
if (write(fd_out, buf, n) != n) {
|
||||
fatal("Failed to copy fd");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef HAVE_MKSTEMP
|
||||
/* cheap and nasty mkstemp replacement */
|
||||
static int mkstemp(char *template)
|
||||
{
|
||||
mktemp(template);
|
||||
return open(template, O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* move a file using rename */
|
||||
int move_file(const char *src, const char *dest) {
|
||||
return safe_rename(src, dest);
|
||||
}
|
||||
|
||||
/* copy a file - used when hard links don't work
|
||||
the copy is done via a temporary file and atomic rename
|
||||
*/
|
||||
static int copy_file(const char *src, const char *dest)
|
||||
{
|
||||
int fd1, fd2;
|
||||
char buf[10240];
|
||||
int n;
|
||||
char *tmp_name;
|
||||
mode_t mask;
|
||||
|
||||
x_asprintf(&tmp_name, "%s.XXXXXX", dest);
|
||||
|
||||
fd1 = open(src, O_RDONLY|O_BINARY);
|
||||
if (fd1 == -1) {
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd2 = mkstemp(tmp_name);
|
||||
if (fd2 == -1) {
|
||||
close(fd1);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((n = read(fd1, buf, sizeof(buf))) > 0) {
|
||||
if (write(fd2, buf, n) != n) {
|
||||
close(fd2);
|
||||
close(fd1);
|
||||
unlink(tmp_name);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd1);
|
||||
|
||||
/* get perms right on the tmp file */
|
||||
#ifndef _WIN32
|
||||
mask = umask(0);
|
||||
fchmod(fd2, 0666 & ~mask);
|
||||
umask(mask);
|
||||
#else
|
||||
(void)mask;
|
||||
#endif
|
||||
|
||||
/* the close can fail on NFS if out of space */
|
||||
if (close(fd2) == -1) {
|
||||
unlink(tmp_name);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unlink(dest);
|
||||
|
||||
if (rename(tmp_name, dest) == -1) {
|
||||
unlink(tmp_name);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(tmp_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* copy a file to the cache */
|
||||
static int copy_file_to_cache(const char *src, const char *dest) {
|
||||
return copy_file(src, dest);
|
||||
}
|
||||
|
||||
/* copy a file from the cache */
|
||||
static int copy_file_from_cache(const char *src, const char *dest) {
|
||||
return copy_file(src, dest);
|
||||
}
|
||||
|
||||
#else /* ENABLE_ZLIB */
|
||||
|
||||
/* copy all data from one file descriptor to another
|
||||
possibly decompressing it
|
||||
*/
|
||||
void copy_fd(int fd_in, int fd_out) {
|
||||
char buf[10240];
|
||||
int n;
|
||||
gzFile gz_in;
|
||||
|
||||
gz_in = gzdopen(dup(fd_in), "rb");
|
||||
|
||||
if (!gz_in) {
|
||||
fatal("Failed to copy fd");
|
||||
}
|
||||
|
||||
while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
|
||||
if (write(fd_out, buf, n) != n) {
|
||||
fatal("Failed to copy fd");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int _copy_file(const char *src, const char *dest, int mode) {
|
||||
int fd_in, fd_out;
|
||||
gzFile gz_in, gz_out = NULL;
|
||||
char buf[10240];
|
||||
int n, ret;
|
||||
char *tmp_name;
|
||||
mode_t mask;
|
||||
struct stat st;
|
||||
|
||||
x_asprintf(&tmp_name, "%s.XXXXXX", dest);
|
||||
|
||||
if (getenv("CCACHE_NOCOMPRESS")) {
|
||||
mode = COPY_UNCOMPRESSED;
|
||||
}
|
||||
|
||||
/* open source file */
|
||||
fd_in = open(src, O_RDONLY);
|
||||
if (fd_in == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
gz_in = gzdopen(fd_in, "rb");
|
||||
if (!gz_in) {
|
||||
close(fd_in);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* open destination file */
|
||||
fd_out = mkstemp(tmp_name);
|
||||
if (fd_out == -1) {
|
||||
gzclose(gz_in);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mode == COPY_TO_CACHE) {
|
||||
/* The gzip file format occupies at least 20 bytes. So
|
||||
it will always occupy an entire filesystem block,
|
||||
even for empty files.
|
||||
Since most stderr files will be empty, we turn off
|
||||
compression in this case to save space.
|
||||
*/
|
||||
if (fstat(fd_in, &st) != 0) {
|
||||
gzclose(gz_in);
|
||||
close(fd_out);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
if (file_size(&st) == 0) {
|
||||
mode = COPY_UNCOMPRESSED;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == COPY_TO_CACHE) {
|
||||
gz_out = gzdopen(dup(fd_out), "wb");
|
||||
if (!gz_out) {
|
||||
gzclose(gz_in);
|
||||
close(fd_out);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
|
||||
if (mode == COPY_TO_CACHE) {
|
||||
ret = gzwrite(gz_out, buf, n);
|
||||
} else {
|
||||
ret = write(fd_out, buf, n);
|
||||
}
|
||||
if (ret != n) {
|
||||
gzclose(gz_in);
|
||||
if (gz_out) {
|
||||
gzclose(gz_out);
|
||||
}
|
||||
close(fd_out);
|
||||
unlink(tmp_name);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gzclose(gz_in);
|
||||
if (gz_out) {
|
||||
gzclose(gz_out);
|
||||
}
|
||||
|
||||
/* get perms right on the tmp file */
|
||||
mask = umask(0);
|
||||
fchmod(fd_out, 0666 & ~mask);
|
||||
umask(mask);
|
||||
|
||||
/* the close can fail on NFS if out of space */
|
||||
if (close(fd_out) == -1) {
|
||||
unlink(tmp_name);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unlink(dest);
|
||||
|
||||
if (rename(tmp_name, dest) == -1) {
|
||||
unlink(tmp_name);
|
||||
free(tmp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(tmp_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* move a file to the cache, compressing it */
|
||||
int move_file(const char *src, const char *dest) {
|
||||
int ret;
|
||||
|
||||
ret = _copy_file(src, dest, COPY_TO_CACHE);
|
||||
if (ret != -1) unlink(src);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* copy a file to the cache, compressing it */
|
||||
static int copy_file_to_cache(const char *src, const char *dest) {
|
||||
return _copy_file(src, dest, COPY_TO_CACHE);
|
||||
}
|
||||
|
||||
/* copy a file from the cache, decompressing it */
|
||||
static int copy_file_from_cache(const char *src, const char *dest) {
|
||||
return _copy_file(src, dest, COPY_FROM_CACHE);
|
||||
}
|
||||
#endif /* ENABLE_ZLIB */
|
||||
|
||||
/* test if a file is zlib compressed */
|
||||
int test_if_compressed(const char *filename) {
|
||||
FILE *f;
|
||||
|
||||
f = fopen(filename, "rb");
|
||||
if (!f) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* test if file starts with 1F8B, which is zlib's
|
||||
* magic number */
|
||||
if ((fgetc(f) != 0x1f) || (fgetc(f) != 0x8b)) {
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* copy file to the cache with error checking taking into account compression and hard linking if desired */
|
||||
int commit_to_cache(const char *src, const char *dest, int hardlink)
|
||||
{
|
||||
int ret = -1;
|
||||
struct stat st;
|
||||
if (stat(src, &st) == 0) {
|
||||
unlink(dest);
|
||||
if (hardlink) {
|
||||
#ifdef _WIN32
|
||||
ret = CreateHardLinkA(dest, src, NULL) ? 0 : -1;
|
||||
#else
|
||||
ret = link(src, dest);
|
||||
#endif
|
||||
}
|
||||
if (ret == -1) {
|
||||
ret = copy_file_to_cache(src, dest);
|
||||
if (ret == -1) {
|
||||
cc_log("failed to commit %s -> %s (%s)\n", src, dest, strerror(errno));
|
||||
stats_update(STATS_ERROR);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cc_log("failed to put %s in the cache (%s)\n", src, strerror(errno));
|
||||
stats_update(STATS_ERROR);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* copy file out of the cache with error checking taking into account compression and hard linking if desired */
|
||||
int retrieve_from_cache(const char *src, const char *dest, int hardlink)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
x_utimes(src);
|
||||
|
||||
if (strcmp(dest, "/dev/null") == 0) {
|
||||
ret = 0;
|
||||
} else {
|
||||
unlink(dest);
|
||||
/* only make a hardlink if the cache file is uncompressed */
|
||||
if (hardlink && test_if_compressed(src) == 0) {
|
||||
#ifdef _WIN32
|
||||
ret = CreateHardLinkA(dest, src, NULL) ? 0 : -1;
|
||||
#else
|
||||
ret = link(src, dest);
|
||||
#endif
|
||||
} else {
|
||||
ret = copy_file_from_cache(src, dest);
|
||||
}
|
||||
}
|
||||
|
||||
/* the cached file might have been deleted by some external process */
|
||||
if (ret == -1 && errno == ENOENT) {
|
||||
cc_log("hashfile missing for %s\n", dest);
|
||||
stats_update(STATS_MISSING);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ret == -1) {
|
||||
ret = copy_file_from_cache(src, dest);
|
||||
if (ret == -1) {
|
||||
cc_log("failed to retrieve %s -> %s (%s)\n", src, dest, strerror(errno));
|
||||
stats_update(STATS_ERROR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* make sure a directory exists */
|
||||
int create_dir(const char *dir)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(dir, &st) == 0) {
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
return 0;
|
||||
}
|
||||
errno = ENOTDIR;
|
||||
return 1;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (mkdir(dir) != 0 && errno != EEXIST) {
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
if (mkdir(dir, 0777) != 0 && errno != EEXIST) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
char const CACHEDIR_TAG[] =
|
||||
"Signature: 8a477f597d28d172789f06886806bc55\n"
|
||||
"# This file is a cache directory tag created by ccache.\n"
|
||||
"# For information about cache directory tags, see:\n"
|
||||
"# http://www.brynosaurus.com/cachedir/\n";
|
||||
|
||||
int create_cachedirtag(const char *dir)
|
||||
{
|
||||
char *filename;
|
||||
struct stat st;
|
||||
FILE *f;
|
||||
x_asprintf(&filename, "%s/CACHEDIR.TAG", dir);
|
||||
if (stat(filename, &st) == 0) {
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
goto success;
|
||||
}
|
||||
errno = EEXIST;
|
||||
goto error;
|
||||
}
|
||||
f = fopen(filename, "w");
|
||||
if (!f) goto error;
|
||||
if (fwrite(CACHEDIR_TAG, sizeof(CACHEDIR_TAG)-1, 1, f) != 1) {
|
||||
goto error;
|
||||
}
|
||||
if (fclose(f)) goto error;
|
||||
success:
|
||||
free(filename);
|
||||
return 0;
|
||||
error:
|
||||
free(filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
this is like asprintf() but dies if the malloc fails
|
||||
note that we use vsnprintf in a rather poor way to make this more portable
|
||||
*/
|
||||
void x_asprintf(char **ptr, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
*ptr = NULL;
|
||||
va_start(ap, format);
|
||||
if (vasprintf(ptr, format, ap) == -1) {
|
||||
fatal("out of memory in x_asprintf");
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
if (!ptr) fatal("out of memory in x_asprintf");
|
||||
}
|
||||
|
||||
/*
|
||||
this is like strdup() but dies if the malloc fails
|
||||
*/
|
||||
char *x_strdup(const char *s)
|
||||
{
|
||||
char *ret;
|
||||
ret = strdup(s);
|
||||
if (!ret) {
|
||||
fatal("out of memory in strdup\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
this is like malloc() but dies if the malloc fails
|
||||
*/
|
||||
void *x_malloc(size_t size)
|
||||
{
|
||||
void *ret;
|
||||
ret = malloc(size);
|
||||
if (!ret) {
|
||||
fatal("out of memory in malloc\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
this is like realloc() but dies if the malloc fails
|
||||
*/
|
||||
void *x_realloc(void *ptr, size_t size)
|
||||
{
|
||||
void *p2;
|
||||
#if 1
|
||||
/* Avoid invalid read in memcpy below */
|
||||
p2 = realloc(ptr, size);
|
||||
if (!p2) {
|
||||
fatal("out of memory in x_realloc");
|
||||
}
|
||||
#else
|
||||
if (!ptr) return x_malloc(size);
|
||||
p2 = malloc(size);
|
||||
if (!p2) {
|
||||
fatal("out of memory in x_realloc");
|
||||
}
|
||||
if (ptr) {
|
||||
/* Note invalid read as the memcpy reads beyond the memory allocated by ptr */
|
||||
memcpy(p2, ptr, size);
|
||||
free(ptr);
|
||||
}
|
||||
#endif
|
||||
return p2;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
revsusive directory traversal - used for cleanup
|
||||
fn() is called on all files/dirs in the tree
|
||||
*/
|
||||
void traverse(const char *dir, void (*fn)(const char *, struct stat *))
|
||||
{
|
||||
DIR *d;
|
||||
struct dirent *de;
|
||||
|
||||
d = opendir(dir);
|
||||
if (!d) return;
|
||||
|
||||
while ((de = readdir(d))) {
|
||||
char *fname;
|
||||
struct stat st;
|
||||
|
||||
if (strcmp(de->d_name,".") == 0) continue;
|
||||
if (strcmp(de->d_name,"..") == 0) continue;
|
||||
|
||||
if (strlen(de->d_name) == 0) continue;
|
||||
|
||||
x_asprintf(&fname, "%s/%s", dir, de->d_name);
|
||||
#ifdef _WIN32
|
||||
if (stat(fname, &st))
|
||||
#else
|
||||
if (lstat(fname, &st))
|
||||
#endif
|
||||
{
|
||||
if (errno != ENOENT) {
|
||||
perror(fname);
|
||||
}
|
||||
free(fname);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
traverse(fname, fn);
|
||||
}
|
||||
|
||||
fn(fname, &st);
|
||||
free(fname);
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
|
||||
/* return the base name of a file - caller frees */
|
||||
char *str_basename(const char *s)
|
||||
{
|
||||
char *p = strrchr(s, '/');
|
||||
if (p) {
|
||||
s = (p+1);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
p = strrchr(s, '\\');
|
||||
|
||||
if (p) {
|
||||
s = (p+1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return x_strdup(s);
|
||||
}
|
||||
|
||||
/* return the dir name of a file - caller frees */
|
||||
char *dirname(char *s)
|
||||
{
|
||||
char *p;
|
||||
s = x_strdup(s);
|
||||
p = strrchr(s, '/');
|
||||
#ifdef _WIN32
|
||||
p = strrchr(s, '\\');
|
||||
#endif
|
||||
if (p) {
|
||||
*p = 0;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
http://www.ecst.csuchico.edu/~beej/guide/ipc/flock.html
|
||||
http://cvs.php.net/viewvc.cgi/php-src/win32/flock.c?revision=1.2&view=markup
|
||||
Should return 0 for success, >0 otherwise
|
||||
*/
|
||||
int lock_fd(int fd)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
# if 1
|
||||
return _locking(fd, _LK_NBLCK, 1);
|
||||
# else
|
||||
HANDLE fl = (HANDLE)_get_osfhandle(fd);
|
||||
OVERLAPPED o;
|
||||
memset(&o, 0, sizeof(o));
|
||||
return (LockFileEx(fl, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &o))
|
||||
? 0 : GetLastError();
|
||||
# endif
|
||||
#else
|
||||
struct flock fl;
|
||||
int ret;
|
||||
|
||||
fl.l_type = F_WRLCK;
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 1;
|
||||
fl.l_pid = 0;
|
||||
|
||||
/* not sure why we would be getting a signal here,
|
||||
but one user claimed it is possible */
|
||||
do {
|
||||
ret = fcntl(fd, F_SETLKW, &fl);
|
||||
} while (ret == -1 && errno == EINTR);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* return size on disk of a file */
|
||||
size_t file_size(struct stat *st)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return (st->st_size + 1023) & ~1023;
|
||||
#else
|
||||
size_t size = st->st_blocks * 512;
|
||||
if ((size_t)st->st_size > size) {
|
||||
/* probably a broken stat() call ... */
|
||||
size = (st->st_size + 1023) & ~1023;
|
||||
}
|
||||
return size;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* a safe open/create for read-write */
|
||||
int safe_open(const char *fname)
|
||||
{
|
||||
int fd = open(fname, O_RDWR|O_BINARY);
|
||||
if (fd == -1 && errno == ENOENT) {
|
||||
fd = open(fname, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0666);
|
||||
if (fd == -1 && errno == EEXIST) {
|
||||
fd = open(fname, O_RDWR|O_BINARY);
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* display a kilobyte unsigned value in M, k or G */
|
||||
void display_size(unsigned v)
|
||||
{
|
||||
if (v > 1024*1024) {
|
||||
printf("%8.1f Gbytes", v/((double)(1024*1024)));
|
||||
} else if (v > 1024) {
|
||||
printf("%8.1f Mbytes", v/((double)(1024)));
|
||||
} else {
|
||||
printf("%8u Kbytes", v);
|
||||
}
|
||||
}
|
||||
|
||||
/* return a value in multiples of 1024 give a string that can end
|
||||
in K, M or G
|
||||
*/
|
||||
size_t value_units(const char *s)
|
||||
{
|
||||
char m;
|
||||
double v = atof(s);
|
||||
m = s[strlen(s)-1];
|
||||
switch (m) {
|
||||
case 'G':
|
||||
case 'g':
|
||||
default:
|
||||
v *= 1024*1024;
|
||||
break;
|
||||
case 'M':
|
||||
case 'm':
|
||||
v *= 1024;
|
||||
break;
|
||||
case 'K':
|
||||
case 'k':
|
||||
v *= 1;
|
||||
break;
|
||||
}
|
||||
return (size_t)v;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
a sane realpath() function, trying to cope with stupid path limits and
|
||||
a broken API
|
||||
*/
|
||||
char *x_realpath(const char *path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char namebuf[MAX_PATH];
|
||||
DWORD ret;
|
||||
|
||||
ret = GetFullPathNameA(path, sizeof(namebuf), namebuf, NULL);
|
||||
if (ret == 0 || ret >= sizeof(namebuf)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return x_strdup(namebuf);
|
||||
#else
|
||||
int maxlen;
|
||||
char *ret, *p;
|
||||
#ifdef PATH_MAX
|
||||
maxlen = PATH_MAX;
|
||||
#elif defined(MAXPATHLEN)
|
||||
maxlen = MAXPATHLEN;
|
||||
#elif defined(_PC_PATH_MAX)
|
||||
maxlen = pathconf(path, _PC_PATH_MAX);
|
||||
#endif
|
||||
if (maxlen < 4096) maxlen = 4096;
|
||||
|
||||
ret = x_malloc(maxlen);
|
||||
|
||||
#if HAVE_REALPATH
|
||||
p = realpath(path, ret);
|
||||
#else
|
||||
/* yes, there are such systems. This replacement relies on
|
||||
the fact that when we call x_realpath we only care about symlinks */
|
||||
{
|
||||
int len = readlink(path, ret, maxlen-1);
|
||||
if (len == -1) {
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
ret[len] = 0;
|
||||
p = ret;
|
||||
}
|
||||
#endif
|
||||
if (p) {
|
||||
p = x_strdup(p);
|
||||
free(ret);
|
||||
return p;
|
||||
}
|
||||
free(ret);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* a getcwd that will returns an allocated buffer */
|
||||
char *gnu_getcwd(void)
|
||||
{
|
||||
unsigned size = 128;
|
||||
|
||||
while (1) {
|
||||
char *buffer = (char *)x_malloc(size);
|
||||
if (getcwd(buffer, size) == buffer) {
|
||||
return buffer;
|
||||
}
|
||||
free(buffer);
|
||||
if (errno != ERANGE) {
|
||||
return 0;
|
||||
}
|
||||
size *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* create an empty file */
|
||||
int create_empty_file(const char *fname)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
return current users home directory or die
|
||||
*/
|
||||
const char *get_home_directory(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
static char home_path[MAX_PATH] = {0};
|
||||
HRESULT ret;
|
||||
|
||||
/* we already have the path */
|
||||
if (home_path[0] != 0) {
|
||||
return home_path;
|
||||
}
|
||||
|
||||
/* get the path to "Application Data" folder */
|
||||
ret = SHGetFolderPathA(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, home_path);
|
||||
if (SUCCEEDED(ret)) {
|
||||
return home_path;
|
||||
}
|
||||
|
||||
fprintf(stderr, "ccache: Unable to determine home directory\n");
|
||||
return NULL;
|
||||
#else
|
||||
const char *p = getenv("HOME");
|
||||
if (p) {
|
||||
return p;
|
||||
}
|
||||
#ifdef HAVE_GETPWUID
|
||||
{
|
||||
struct passwd *pwd = getpwuid(getuid());
|
||||
if (pwd) {
|
||||
return pwd->pw_dir;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
fatal("Unable to determine home directory");
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
int x_utimes(const char *filename)
|
||||
{
|
||||
#ifdef HAVE_UTIMES
|
||||
return utimes(filename, NULL);
|
||||
#else
|
||||
return utime(filename, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
/* perror for Win32 API calls, using GetLastError() instead of errno */
|
||||
void perror_win32(LPTSTR pszFunction)
|
||||
{
|
||||
LPTSTR pszMessage;
|
||||
DWORD dwLastError = GetLastError();
|
||||
|
||||
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
dwLastError,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR)&pszMessage,
|
||||
0, NULL );
|
||||
|
||||
fprintf(stderr, "%s: %s\n", pszFunction, pszMessage);
|
||||
LocalFree(pszMessage);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>ccache</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#ffffff" TEXT="#000000" VLINK="#292555" LINK="#292555" ALINK="#cc0033">
|
||||
<h2>ccache</h2>
|
||||
|
||||
ccache is a compiler cache. It acts as a caching pre-processor to
|
||||
C/C++ compilers, using the -E compiler switch and a hash to detect
|
||||
when a compilation can be satisfied from cache. This often results in
|
||||
a 5 to 10 times speedup in common compilations.<p>
|
||||
|
||||
The idea came from Erik Thiele wrote the original <a
|
||||
href="http://compilercache.sourceforge.net/">compilercache</a> program
|
||||
as a bourne shell script. ccache is a re-implementation of Erik's idea
|
||||
in C with more features and better performance.<p>
|
||||
|
||||
<h2>Latest release</h2>
|
||||
|
||||
The latest release is ccache 2.4.
|
||||
|
||||
<ul>
|
||||
<li>Added CCACHE_READONLY option
|
||||
<li>Added CCACHE_TEMPDIR option
|
||||
<li>fixed handling of hard-linked compilers on AIX
|
||||
<li>added O_BINARY support, to try and support win32 compiles
|
||||
<li>show cache directory in stats output
|
||||
<li>fixed handling of HOME environment variable
|
||||
</ul>
|
||||
|
||||
See the <a href="ccache-man.html">manual page</a> for details
|
||||
on the new options.<p>
|
||||
|
||||
You can get this release from the <a href="http://ccache.samba.org/ftp/ccache/">download directory</a>
|
||||
|
||||
<p>NOTE! This release changes the hash input slighly, so you will
|
||||
probably find that you will not get any hits against your existing
|
||||
cache when you upgrade.
|
||||
|
||||
<h2>Why bother?</h2>
|
||||
|
||||
Why bother with a compiler cache? If you ever run "make clean; make"
|
||||
then you can probably benefit from ccache. It is very common for
|
||||
developers to do a clean build of a project for a whole host of
|
||||
reasons, and this throws away all the information from your previous
|
||||
compiles.<p>
|
||||
|
||||
By using ccache you can get exactly the same effect as "make clean;
|
||||
make" but much faster. It also helps a lot when doing RPM builds,
|
||||
as RPM can make doing incremental builds tricky.<p>
|
||||
|
||||
I put the effort into writing ccache for 2 reasons. The first is the
|
||||
Samba build farm
|
||||
(<a href="http://build.samba.org/">http://build.samba.org/</a>)
|
||||
which constantly does clean builds of Samba on about 30 machines after each
|
||||
CVS commit. On some of those machines the build took over an hour. By
|
||||
using ccache we get the same effect as clean builds but about 6 times
|
||||
faster.<p>
|
||||
|
||||
The second reason is the autobuild system I used to run for
|
||||
Quantum. That system builds our whole Linux based OS from scratch
|
||||
after every CVS commit to catch compilation problems quickly. Using
|
||||
ccache those builds are much faster.
|
||||
|
||||
<h2>Is it safe?</h2>
|
||||
|
||||
Yes. The most important aspect of a compiler cache is to <b>always</b>
|
||||
produce exactly the same output that the real compiler would
|
||||
produce. The includes providing exactly the same object files and
|
||||
exactly the same compiler warnings that would be produced if you use
|
||||
the real compiler. The only way you should be able to tell that you
|
||||
are using ccache is the speed.<p>
|
||||
|
||||
I have coded ccache very carefully to try to provide these guarantees.
|
||||
|
||||
<h2>Features</h2>
|
||||
|
||||
<ul>
|
||||
<li> keeps statistics on hits/misses
|
||||
<li> automatic cache size management
|
||||
<li> can cache compiles that generate warnings
|
||||
<li> easy installation
|
||||
<li> very low overhead
|
||||
<li> uses hard links where possible to avoid copies
|
||||
</ul>
|
||||
|
||||
<h2>Documentation</h2>
|
||||
|
||||
See the <a href="ccache-man.html">manual page</a>
|
||||
|
||||
|
||||
<h2>Performance</h2>
|
||||
|
||||
Here are some results for compiling Samba on my Linux laptop. I have
|
||||
also included the results of using Erik's compilercache program
|
||||
(version 1.0.10) for comparison.<p>
|
||||
|
||||
<table border=1>
|
||||
<tr><th> </th> <th> ccache</th> <th> compilercache</th> </tr>
|
||||
<tr><td>normal </td> <td align=right>13m 4s </td><td align=right>13m 4s</td> </tr>
|
||||
<tr><td>uncached </td> <td align=right>13m 15s </td><td align=right>15m 41s</td> </tr>
|
||||
<tr><td>cached </td> <td align=right>2m 45s </td><td align=right>4m 26s</td> </tr>
|
||||
</table>
|
||||
|
||||
<h2>How to use it</h2>
|
||||
|
||||
You can use ccache in two ways. The first is just to prefix your
|
||||
compile commands with "ccache". For example, you could change the
|
||||
"CC=gcc" line in your Makefile to be "CC=ccache gcc".<p>
|
||||
|
||||
Alternatively, you can create symbolic links from your compilers name
|
||||
to ccache. This allows you to use ccache without any changes to your
|
||||
build system.
|
||||
|
||||
<h2>Download</h2>
|
||||
|
||||
You can download the latest release from the <a
|
||||
href="http://ccache.samba.org/ftp/ccache/">download directory</a>.<p>
|
||||
|
||||
For the bleeding edge, you can fetch ccache via CVS or
|
||||
rsync. To fetch via cvs use the following command:
|
||||
|
||||
<pre>
|
||||
cvs -d :pserver:cvs@pserver.samba.org:/cvsroot co ccache
|
||||
</pre>
|
||||
|
||||
To fetch via rsync use this command:
|
||||
|
||||
<pre>
|
||||
rsync -Pavz samba.org::ftp/unpacked/ccache .
|
||||
</pre>
|
||||
|
||||
<h2>Related projects</h2>
|
||||
|
||||
Here are some related programs you may find interesting
|
||||
|
||||
<ul>
|
||||
<li> <a href="http://distcc.samba.org/">distcc</a> - a distributed compilation system
|
||||
<li> <a href="http://cachecc1.sourceforge.net/">cachecc1</a> - a gcc specific cache
|
||||
<li> <a href="http://sourceforge.net/projects/gocache/">gocache</a> - a cross platform compiler cache
|
||||
</ul>
|
||||
<p>
|
||||
|
||||
<h2>Mailing list</h2>
|
||||
|
||||
<p>A <a href="http://lists.samba.org/mailman/listinfo/ccache/">mailing
|
||||
list</a> is available for discussion of ccache.
|
||||
|
||||
|
||||
<hr>
|
||||
<tiny>
|
||||
<a href="http://samba.org/~tridge/">Andrew Tridgell</a><br>
|
||||
<a href="mailto:bugs@ccache.samba.org">bugs@ccache.samba.org</a>
|
||||
</tiny>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
508
CHANGES
508
CHANGES
|
|
@ -2,488 +2,6 @@ SWIG (Simplified Wrapper and Interface Generator)
|
|||
|
||||
See CHANGES.current for current version.
|
||||
|
||||
Version 1.3.39 (21 March 2009)
|
||||
==============================
|
||||
|
||||
2009-03-19: bhy
|
||||
[Python] Fix the memory leak related to Python 3 unicode and C char* conversion,
|
||||
which can be shown in the following example before this fix:
|
||||
|
||||
from li_cstring import *
|
||||
i=0
|
||||
while True:
|
||||
i += 1
|
||||
n = str(i)*10
|
||||
test3(n)
|
||||
|
||||
This fix affected SWIG_AsCharPtrAndSize() so you cannot call this function with
|
||||
a null alloc and non-null cptr argument in Python 3, otherwise a runtime error
|
||||
will be raised.
|
||||
|
||||
2009-03-18: wsfulton
|
||||
[C#] std::vector<T> wrapper improvements for .NET 2 and also providing the
|
||||
necessary machinery to use the std::vector<T> wrappers with more advanced features such
|
||||
as LINQ - the C# proxy class now derives from IEnumerable<>. The default is now to
|
||||
generate code requiring .NET 2 as a minimum, although the C# code can be compiled
|
||||
for .NET 1 by defining the SWIG_DOTNET_1 C# preprocessor constant. See the
|
||||
std_vector.i file for more details.
|
||||
|
||||
*** POTENTIAL INCOMPATIBILITY ***
|
||||
|
||||
2009-03-12: wsfulton
|
||||
[Ruby] Fix #2676738 SWIG generated symbol name clashes.
|
||||
|
||||
2009-03-01: bhy
|
||||
[Python] Some fixes for Python 3.0.1 and higher support. In 3.0.1, the C API function
|
||||
PyObject_Compare is removed, so PyObject_RichCompareBool is used for replacement.
|
||||
Struct initilization of SwigPyObject and SwigPyObject_as_number changed to reflect
|
||||
the drop of tp_compare and nb_long.
|
||||
|
||||
2009-03-01: bhy
|
||||
[Python] Fix SF#2583160. Now the importer in Python shadow wrapper take care of the
|
||||
case that module already imported at other place.
|
||||
|
||||
2009-02-28: bhy
|
||||
[Python] Fix SF#2637352. Move struct declaration of SWIG_module in pyinit.swg before
|
||||
the method calls, since some C compiler don't allow declaration in middle of function
|
||||
body.
|
||||
|
||||
2009-02-21: wsfulton
|
||||
[Allegrocl] Fix seg fault wrapping some constant variable (%constant) types.
|
||||
|
||||
2009-02-20: wsfulton
|
||||
[CFFI] Fix seg faults when for %extend and using statements.
|
||||
|
||||
2009-02-20: wsfulton
|
||||
Fix SF #2605955: -co option which broke in 1.3.37.
|
||||
|
||||
2009-02-20: wsfulton
|
||||
New %insert("begin") section added. Also can be used as %begin. This is a new
|
||||
code section reserved entirely for users and the code within the section is generated
|
||||
at the top of the C/C++ wrapper file and so provides a means to put custom code
|
||||
into the wrapper file before anything else that SWIG generates.
|
||||
|
||||
2009-02-17: wsfulton
|
||||
'make clean-test-suite' will now run clean on ALL languages. Previously it only
|
||||
ran the correctly configured languages. This way it is now possible to clean up
|
||||
properly after running 'make partialcheck-test-suite'.
|
||||
|
||||
2009-02-14: wsfulton
|
||||
Extend attribute library support for structs/classes and the accessor functions use
|
||||
pass/return by value semantics. Two new macros are available and usage is identical
|
||||
to %attribute. These are %attributeval for structs/classes and %attributestring for
|
||||
string classes, like std::string. See attribute.swg for more details.
|
||||
|
||||
2009-02-13: wsfulton
|
||||
Add support for %extend and memberin typemaps. Previously the memberin typemaps were
|
||||
ignored for member variables within a %extend block.
|
||||
|
||||
2009-02-12: wsfulton
|
||||
Remove unnecessary temporary variable when wrapping return values that are references.
|
||||
Example of generated code for wrapping:
|
||||
|
||||
struct XYZ {
|
||||
std::string& refReturn();
|
||||
};
|
||||
|
||||
used to be:
|
||||
|
||||
std::string *result = 0 ;
|
||||
...
|
||||
{
|
||||
std::string &_result_ref = (arg1)->refReturn();
|
||||
result = (std::string *) &_result_ref;
|
||||
}
|
||||
|
||||
Now it is:
|
||||
|
||||
std::string *result = 0 ;
|
||||
...
|
||||
result = (std::string *) &(arg1)->refReturn();
|
||||
|
||||
2009-02-08: bhy
|
||||
Change the SIZE mapped by %pybuffer_mutable_binary and %pybuffer_binary in pybuffer.i from
|
||||
the length of the buffer to the number of items in the buffer.
|
||||
|
||||
2009-02-08: wsfulton
|
||||
Fix %feature not working for conversion operators, reported by Matt Sprague, for example:
|
||||
%feature("cs:methodmodifiers") operator bool "protected";
|
||||
|
||||
2009-02-07: wsfulton
|
||||
[MzScheme] Apply #2081967 configure changes for examples to build with recent PLT versions.
|
||||
Also fixes Makefile errors building SWIG executable when mzscheme package is installed
|
||||
(version 3.72 approx and later).
|
||||
|
||||
2009-02-04: talby
|
||||
[Perl] Fix SF#2564192 reported by David Kolovratnk.
|
||||
SWIG_AsCharPtrAndSize() now handles "get" magic.
|
||||
|
||||
Version 1.3.38 (31 January 2009)
|
||||
================================
|
||||
|
||||
2009-01-31: bhy
|
||||
[Python] Fix SF#2552488 reported by Gaetan Lehmann. Now %pythonprepend
|
||||
and %pythonappend have correct indentation.
|
||||
|
||||
2009-01-31: bhy
|
||||
[Python] Fix SF#2552048 reported by Gaetan Lehmann. The parameter list
|
||||
of static member function in generated proxy code should not have the
|
||||
'self' parameter.
|
||||
|
||||
2009-01-29: wsfulton
|
||||
Fix regression introduced in 1.3.37 where the default output directory
|
||||
for target language specific files (in the absence of -outdir) was no
|
||||
longer the same directory as the generated c/c++ file.
|
||||
|
||||
2009-01-28: wsfulton
|
||||
[Java, C#] Fix proxy class not being used when the global scope operator
|
||||
was used for parameters passed by value. Reported by David Piepgrass.
|
||||
|
||||
2009-01-15: wsfulton
|
||||
[Perl] Fix seg fault when running with -v option, reported by John Ky.
|
||||
|
||||
Version 1.3.37 (13 January 2009)
|
||||
================================
|
||||
|
||||
2009-01-13: mgossage
|
||||
[Lua] Added contract support for requiring that unsigned numbers are >=0
|
||||
Rewrote much of Examples/Lua/embed3.
|
||||
Added a lot to the Lua documentation.
|
||||
|
||||
2009-01-13: wsfulton
|
||||
Fix compilation error when using directors on protected virtual overloaded
|
||||
methods reported by Sam Hendley.
|
||||
|
||||
2009-01-12: drjoe
|
||||
[R] Fixed handling of integer arrays
|
||||
|
||||
2009-01-10: drjoe
|
||||
[R] Fix integer handling in r to deal correctly with signed
|
||||
and unsigned issues
|
||||
|
||||
2009-01-10: wsfulton
|
||||
Patch #1992756 from Colin McDonald - %contract not working for classes
|
||||
in namespace
|
||||
|
||||
2009-01-05: olly
|
||||
Mark SWIGPERL5, SWIGPHP5, and SWIGTCL8 as deprecated in the source
|
||||
code and remove documentation of them.
|
||||
|
||||
2008-12-30: wsfulton
|
||||
Bug #2430756. All the languages now define a macro in the generated C/C++
|
||||
wrapper file indicating which language is being wrapped. The macro name is the
|
||||
same as those defined when SWIG is run, eg SWIGJAVA, SWIGOCTAVE, SWIGCSHARP etc
|
||||
and are listed in the "Conditional Compilation" section in the documentation.
|
||||
|
||||
2008-12-23: wsfulton
|
||||
[Java] Fix #2153773 - %nojavaexception was clearing the exception feature
|
||||
instead of disabling it. Clearing checked Java exceptions also didn't work.
|
||||
The new %clearjavaexception can be used for clearing the exception feature.
|
||||
|
||||
2008-12-22: wsfulton
|
||||
Fix #2432801 - Make SwigValueWrapper exception safe for when copy constructors
|
||||
throw exceptions.
|
||||
|
||||
2008-12-21: wsfulton
|
||||
Apply patch #2440046 which fixes possible seg faults for member and global
|
||||
variable char arrays when the strings are larger than the string array size.
|
||||
|
||||
2008-12-20: wsfulton
|
||||
The ccache compiler cache has been adapted to work with SWIG and
|
||||
named ccache-swig. It now works with C/C++ compilers as well as SWIG
|
||||
and can result in impressive speedups when used to recompile unchanged
|
||||
code with either a C/C++ compiler or SWIG. Documentation is in CCache.html
|
||||
or the installed ccache-swig man page.
|
||||
|
||||
2008-12-12: wsfulton
|
||||
Apply patch from Kalyanov Dmitry which fixes parsing of nested structs
|
||||
containing comments.
|
||||
|
||||
2008-12-12: wsfulton
|
||||
Fix error message in some nested struct and %inline parsing error situations
|
||||
such as unterminated strings and comments.
|
||||
|
||||
2008-12-07: olly
|
||||
[PHP] Fix warnings when compiling generated wrapper with GCC 4.3.
|
||||
|
||||
2008-12-06: wsfulton
|
||||
[PHP] Deprecate %pragma(php4). Please use %pragma(php) instead.
|
||||
The following two warnings have been renamed:
|
||||
WARN_PHP4_MULTIPLE_INHERITANCE -> WARN_PHP_MULTIPLE_INHERITANCE
|
||||
WARN_PHP4_UNKNOWN_PRAGMA -> WARN_PHP_UNKNOWN_PRAGMA
|
||||
|
||||
*** POTENTIAL INCOMPATIBILITY ***
|
||||
|
||||
2008-12-04: bhy
|
||||
[Python] Applied patch SF#2158938: all the SWIG symbol names started with Py
|
||||
are changed, since they are inappropriate and discouraged in Python
|
||||
documentation (from http://www.python.org/doc/2.5.2/api/includes.html):
|
||||
|
||||
"All user visible names defined by Python.h (except those defined by
|
||||
the included standard headers) have one of the prefixes "Py" or "_Py".
|
||||
Names beginning with "_Py" are for internal use by the Python implementation
|
||||
and should not be used by extension writers. Structure member names do
|
||||
not have a reserved prefix.
|
||||
|
||||
Important: user code should never define names that begin with "Py" or "_Py".
|
||||
This confuses the reader, and jeopardizes the portability of the user
|
||||
code to future Python versions, which may define additional names beginning
|
||||
with one of these prefixes."
|
||||
|
||||
Here is a brief list of what changed:
|
||||
|
||||
PySwig* -> SwigPy*
|
||||
PyObject_ptr -> SwigPtr_PyObject
|
||||
PyObject_var -> SwigVar_PyObject
|
||||
PySequence_Base, PySequence_Cont, PySequence_Ref ->
|
||||
SwigPySequence_Base, SwigPySequence_Cont, SwigPySequence_Ref
|
||||
PyMap* -> SwigPyMap*
|
||||
|
||||
We provided a pyname_compat.i for backward compatibility. Users whose code having
|
||||
these symbols and do not want to change it could simply include this file
|
||||
at front of your code. A better solution is to run the converting tool on
|
||||
your code, which has been put in SWIG's SVN trunk (Tools/pyname_patch.py) and
|
||||
you can download it here:
|
||||
https://swig.svn.sourceforge.net/svnroot/swig/trunk/Tools/pyname_patch.py
|
||||
|
||||
*** POTENTIAL INCOMPATIBILITY ***
|
||||
|
||||
2008-12-02: wsfulton
|
||||
[Python] Apply patch #2143727 from Serge Monkewitz to fix importing base classes
|
||||
when the package option is specified in %module and that module is %import'ed.
|
||||
|
||||
2008-11-28: wsfulton
|
||||
[UTL] Fix #2080497. Some incorrect acceptance of types in the STL, eg a double * element
|
||||
passed into a vector<int *> constructor would be accepted, but the ensuing behaviour
|
||||
was undefined. Now the type conversion correctly raises an exception.
|
||||
|
||||
2008-11-24: wsfulton
|
||||
Add -outcurrentdir option. This sets the default output directory to the current
|
||||
directory instead of the path specified by the input file. This option enables
|
||||
behaviour similar to c/c++ compilers. Note that this controls the output directory,
|
||||
but only in the absence of the -o and/or -outdir options.
|
||||
|
||||
2008-11-23: wsfulton
|
||||
[ruby] Apply patch #2263850 to fix ruby/file.i ... rubyio.h filename change in
|
||||
ruby 1.9.
|
||||
|
||||
2008-11-23: wsfulton
|
||||
Apply patch #2319790 from Johan Hake to fix shared_ptr usage in std::tr1 namespace.
|
||||
|
||||
2008-11-21: wsfulton
|
||||
The use of the include path to find the input file is now deprecated.
|
||||
This makes the behaviour of SWIG the same as C/C++ compilers in preparation
|
||||
for use with ccache.
|
||||
|
||||
2008-11-16: wsfulton
|
||||
Fix -nopreprocess option to:
|
||||
- correctly report file names in warning and error messages.
|
||||
- use the original input filename that created the preprocessed output when
|
||||
determining the C++ wrapper file name (in the absence of -o). Previously
|
||||
the name of the input file containing the preprocessed output was used.
|
||||
|
||||
2008-11-11: wsfulton
|
||||
[Java] Add patch #2152691 from MATSUURA Takanori which fixes compiles using the
|
||||
Intel compiler
|
||||
|
||||
2008-11-01: wsfulton
|
||||
Add patch #2128249 from Anatoly Techtonik which corrects the C/C++ proxy
|
||||
class being reported for Python docstrings when %rename is used.
|
||||
|
||||
2008-11-01: wsfulton
|
||||
Add the strip encoder patch from Anatoly Techtonik #2130016. This enables an
|
||||
easy way to rename symbols by stripping a commonly used prefix in all the
|
||||
function/struct names. It works in the same way as the other encoders, such as
|
||||
title, lower, command etc outlined in CHANGES file dated 12/30/2005. Example
|
||||
below will rename wxAnotherWidget to AnotherWidget and wxDoSomething to
|
||||
DoSomething:
|
||||
|
||||
%rename("%(strip:[wx])s") "";
|
||||
|
||||
struct wxAnotherWidget {
|
||||
void wxDoSomething();
|
||||
};
|
||||
|
||||
2008-09-26: mutandiz
|
||||
[allegrocl]
|
||||
Lots of test-suite work.
|
||||
- Fix ordering of wrapper output and %{ %} header output.
|
||||
- Fix declarations of local vars in C wrappers.
|
||||
- Fix declaration of defined constants in C wrappers.
|
||||
- Fix declaration of EnumValues in C wrappers.
|
||||
- add some const typemaps to allegrocl.swg
|
||||
- add rename for operator bool() overloads.
|
||||
|
||||
2008-09-25: olly
|
||||
[PHP5] Fill in typemaps for SWIGTYPE and void * (SF#2095186).
|
||||
|
||||
2008-09-22: mutandiz (Mikel Bancroft)
|
||||
[allegrocl]
|
||||
- Support wrapping of types whose definitions are not seen by
|
||||
SWIG. They are treated as forward-referenced classes and if a
|
||||
definition is not seen are treated as (* :void).
|
||||
- Don't wrap the contents of unnamed namespaces.
|
||||
- More code cleanup. Removed some extraneous warnings.
|
||||
- start work on having the allegrocl mod pass the cpp test-suite.
|
||||
|
||||
2008-09-19: olly
|
||||
[PHP5] Add typemaps for long long and unsigned long long.
|
||||
|
||||
2008-09-18: wsfulton
|
||||
[C#] Added C# array typemaps provided by Antti Karanta.
|
||||
The arrays provide a way to use MarshalAs(UnmanagedType.LPArray)
|
||||
and pinning the array using 'fixed'. See arrays_csharp.i library file
|
||||
for details.
|
||||
|
||||
2008-09-18: wsfulton
|
||||
Document the optional module attribute in the %import directive,
|
||||
see Modules.html. Add a warning for Python wrappers when the
|
||||
module name for an imported base class is missing, requiring the
|
||||
module attribute to be added to %import, eg
|
||||
|
||||
%import(module="FooModule") foo.h
|
||||
|
||||
2008-09-18: olly
|
||||
[PHP5] Change the default input typemap for char * to turn PHP
|
||||
Null into C NULL (previously it was converted to an empty string).
|
||||
The new behaviour is consistent with how the corresponding output
|
||||
typemap works (SF#2025719).
|
||||
|
||||
If you want to keep the old behaviour, add the following typemap
|
||||
to your interface file (PHP's convert_to_string_ex() function does
|
||||
the converting from PHP Null to an empty string):
|
||||
|
||||
%typemap(in) char * {
|
||||
convert_to_string_ex($input);
|
||||
$1 = Z_STRVAL_PP($input);
|
||||
}
|
||||
|
||||
2008-09-18: olly
|
||||
[PHP5] Fix extra code added to proxy class constructors in the case
|
||||
where the only constructor takes no arguments.
|
||||
|
||||
2008-09-18: olly
|
||||
[PHP5] Fix wrapping of a renamed enumerated value of an enum class
|
||||
member (SF#2095273).
|
||||
|
||||
2008-09-17: mutandiz (Mikel Bancroft)
|
||||
[allegrocl]
|
||||
- Fix how forward reference typedefs are handled, so as not to conflict
|
||||
with other legit typedefs.
|
||||
- Don't (for now) perform an ffitype typemap lookup when trying to
|
||||
when calling compose_foreign_type(). This is actually a useful thing
|
||||
to do in certain cases, the test cases for which I can't currently
|
||||
locate :/. It's breaking some wrapping behavior that is more commonly
|
||||
seen, however. I'll readd in a more appropriate way when I can
|
||||
recreate the needed test case, or a user complains (which means
|
||||
they probably have a test case).
|
||||
- document the -isolate command-line arg in the 'swig -help' output.
|
||||
It was in the html docs, but not there.
|
||||
- small amount of code cleanup, removed some unused code.
|
||||
- some minor aesthetic changes.
|
||||
|
||||
2008-09-12: bhy
|
||||
[Python] Python 3.0 support branch merged into SWIG trunk. Thanks to
|
||||
Google Summer of Code 2008 for supporting this project! By default
|
||||
SWIG will generate interface files compatible with both Python 2.x
|
||||
and 3.0. And there's also some Python 3 new features that can be
|
||||
enabled by passing a "-py3" command line option to SWIG. These
|
||||
features are:
|
||||
|
||||
- Function annotation support
|
||||
Also, the parameter list of proxy function will be generated,
|
||||
even without the "-py3" option. However, the parameter list
|
||||
will fallback to *args if the function (or method) is overloaded.
|
||||
- Buffer interface support
|
||||
- Abstract base class support
|
||||
|
||||
For details of Python 3 support and these features, please see the
|
||||
"Python 3 Support" section in the "SWIG and Python" chapter of the SWIG
|
||||
documentation.
|
||||
|
||||
The "-apply" command line option and support of generating codes
|
||||
using apply() is removed. Since this is only required by very old
|
||||
Python.
|
||||
|
||||
This merge also patched SWIG's parser to solve a bug. By this patch,
|
||||
SWIG features able to be correctly applied on C++ conversion operator,
|
||||
such like this:
|
||||
|
||||
%feature("shadow") *::operator bool %{ ... %}
|
||||
|
||||
2008-09-02: richardb
|
||||
[Python] Commit patch #2089149: Director exception handling mangles
|
||||
returned exception. Exceptions raised by Python code in directors
|
||||
are now passed through to the caller without change. Also, remove
|
||||
the ": " prefix which used to be added to other director exceptions
|
||||
(eg, those due to incorrect return types).
|
||||
|
||||
2008-09-02: wsfulton
|
||||
[Python] Commit patch #1988296 GCItem multiple module linking issue when using
|
||||
directors.
|
||||
|
||||
2008-09-02: wsfulton
|
||||
[C#] Support for 'using' and 'fixed' blocks in the 'csin' typemap is now
|
||||
possible through the use of the pre attribute and the new terminator attribute, eg
|
||||
|
||||
%typemap(csin,
|
||||
pre=" using (CDate temp$csinput = new CDate($csinput)) {",
|
||||
terminator=" } // terminate temp$csinput using block",
|
||||
) const CDate &
|
||||
"$csclassname.getCPtr(temp$csinput)"
|
||||
|
||||
See CSharp.html for more info.
|
||||
|
||||
2008-09-01: wsfulton
|
||||
[CFFI] Commit patch #2079381 submitted by Boris Smilga - constant exprs put into
|
||||
no-eval context in DEFCENUM
|
||||
|
||||
2008-08-02: wuzzeb
|
||||
[Chicken,Allegro] Commit Patch 2019314
|
||||
Fixes a build error in chicken, and several build errors and other errors
|
||||
in Allegro CL
|
||||
|
||||
2008-07-19: wsfulton
|
||||
Fix building of Tcl examples/test-suite on Mac OSX reported by Gideon Simpson.
|
||||
|
||||
2008-07-17: wsfulton
|
||||
Fix SF #2019156 Configuring with --without-octave or --without-alllang
|
||||
did not disable octave.
|
||||
|
||||
2008-07-14: wsfulton
|
||||
[Java, C#] Fix director typemaps for pointers so that NULL pointers are correctly
|
||||
marshalled to C#/Java null in director methods.
|
||||
|
||||
2008-07-04: olly
|
||||
[PHP] For std_vector.i and std_map.i, rename empty() to is_empty()
|
||||
since "empty" is a PHP reserved word. Based on patch from Mark Klein
|
||||
in SF#1943417.
|
||||
|
||||
2008-07-04: olly
|
||||
[PHP] The deprecated command line option "-make" has been removed.
|
||||
Searches on Google codesearch suggest that nobody is using it now
|
||||
anyway.
|
||||
|
||||
2008-07-04: olly
|
||||
[PHP] The SWIG cdata.i library module is now supported.
|
||||
|
||||
2008-07-03: olly
|
||||
[PHP] The deprecated command line option "-phpfull" has been
|
||||
removed. We recommend building your extension as a dynamically
|
||||
loadable module.
|
||||
|
||||
2008-07-02: olly
|
||||
[PHP4] Support for PHP4 has been removed. The PHP developers are
|
||||
no longer making new PHP4 releases, and won't even be providing
|
||||
patches for critical security issues after 2008-08-08.
|
||||
|
||||
2008-07-02: olly
|
||||
[Python] Import the C extension differently for Python 2.6 and
|
||||
later so that an implicit relative import doesn't produce a
|
||||
deprecation warning for 2.6 and a failure for 2.7 and later.
|
||||
Patch from Richard Boulton in SF#2008229, plus follow-up patches
|
||||
from Richard and Haoyu Bai.
|
||||
|
||||
Version 1.3.36 (24 June 2008)
|
||||
=============================
|
||||
|
||||
|
|
@ -959,7 +477,7 @@ Version 1.3.34 (27 February 2008)
|
|||
};
|
||||
|
||||
Version 1.3.33 (November 23, 2007)
|
||||
==================================
|
||||
=================================
|
||||
|
||||
11/21/2007: mikel
|
||||
[allegrocl] omit private slot type info in the classes/types
|
||||
|
|
@ -1891,7 +1409,7 @@ Version 1.3.31 (November 20, 2006)
|
|||
[lua] update to typemap for object by value, to make it c89 compliant
|
||||
|
||||
Version 1.3.30 (November 13, 2006)
|
||||
==================================
|
||||
=================================
|
||||
|
||||
11/12/2006: wsfulton
|
||||
[java] Remove DetachCurrentThread patch from 08/11/2006 - it causes segfaults
|
||||
|
|
@ -6214,7 +5732,7 @@ Version 1.3.24 (December 14, 2004)
|
|||
compile with no errors, java shows some problems.
|
||||
|
||||
Version 1.3.23 (November 11, 2004)
|
||||
==================================
|
||||
=================================
|
||||
|
||||
11/05/2004: wsfulton
|
||||
Patch #982753 from Fabrice Salvaire: Adds dependencies generation for
|
||||
|
|
@ -8465,8 +7983,7 @@ Version 1.3.22 (September 4, 2004)
|
|||
exception instead.
|
||||
|
||||
Version 1.3.21 (January 11, 2004)
|
||||
=================================
|
||||
|
||||
==================================
|
||||
01/10/2004: cheetah (William Fulton)
|
||||
The output format for both warnings and errors can be selected for
|
||||
integration with your favourite IDE/editor. Editors and IDEs can usually
|
||||
|
|
@ -10240,7 +9757,6 @@ Version 1.3.20 (December 17, 2003)
|
|||
|
||||
Version 1.3.19 (March 28, 2003)
|
||||
===============================
|
||||
|
||||
03/28/2003: beazley
|
||||
Variety of minor bug fixes to the 1.3.18 release including:
|
||||
|
||||
|
|
@ -10827,7 +10343,6 @@ Version 1.3.18 (March 23, 2003)
|
|||
|
||||
Version 1.3.17 (November 22, 2002)
|
||||
==================================
|
||||
|
||||
11/19/2002: beazley
|
||||
Fixed [ 613922 ] preprocessor errors with HAVE_LONG_LONG.
|
||||
|
||||
|
|
@ -11183,7 +10698,6 @@ Version 1.3.16 (October 14, 2002)
|
|||
|
||||
Version 1.3.15 (September 9, 2002)
|
||||
==================================
|
||||
|
||||
09/09/2002: beazley
|
||||
Fixed nasty runtime type checking bug with subtypes and inheritance
|
||||
and templates.
|
||||
|
|
@ -12876,7 +12390,6 @@ Version 1.3.14 (August 12, 2002)
|
|||
|
||||
Version 1.3.13 (June 17, 2002)
|
||||
==============================
|
||||
|
||||
06/16/2002: beazley
|
||||
Fixed a bug with __FILE__ expansion in the preprocessor. On Windows,
|
||||
the backslash (\) is now converted to (\\) in the string literal
|
||||
|
|
@ -16008,7 +15521,6 @@ Version 1.3.10 (December 10, 2001)
|
|||
|
||||
Version 1.3.9 (September 25, 2001)
|
||||
==================================
|
||||
|
||||
9/25/2001: beazley
|
||||
Fixed parsing problem with type declarations like
|
||||
'char ** const'. SWIG parsed this correctly, but the
|
||||
|
|
@ -16021,7 +15533,6 @@ Version 1.3.9 (September 25, 2001)
|
|||
|
||||
Version 1.3.8 (September 23, 2001)
|
||||
==================================
|
||||
|
||||
9/23/2001: beazley
|
||||
Included improved distutils setup.py file in the Tools
|
||||
directory (look for the setup.py.tmpl file). Contributed by
|
||||
|
|
@ -17394,7 +16905,7 @@ Version 1.3 Alpha 5
|
|||
and function bodies. Preprocessor bug.
|
||||
|
||||
Version 1.3 Alpha 4 (September 4, 2000)
|
||||
=======================================
|
||||
======================================
|
||||
|
||||
9/3/00 : ttn
|
||||
Added instructions for maintainers in Examples/README on how
|
||||
|
|
@ -18480,7 +17991,6 @@ Version 1.3 Alpha 1 (February 11, 2000)
|
|||
|
||||
Version 1.1 Patch 5 (February 5, 1998)
|
||||
======================================
|
||||
|
||||
2/4/98 : Fixed a bug in the configure script when different package
|
||||
locations are specified (--with-tclincl, etc...).
|
||||
|
||||
|
|
@ -18733,7 +18243,6 @@ Version 1.1 Patch 3 (November 24, 1997)
|
|||
|
||||
Version 1.1 Patch 2 (September 4, 1997)
|
||||
=======================================
|
||||
|
||||
9/4/97 : Fixed problem with handling of virtual functions that
|
||||
was introduced by some changes in the C++ module.
|
||||
|
||||
|
|
@ -19869,7 +19378,7 @@ This release should fix most, if not all, of those problems.
|
|||
it generated alot of unnecessary code).
|
||||
|
||||
Version 1.1 Beta3 (January 9, 1997)
|
||||
===================================
|
||||
====================================
|
||||
|
||||
Note : A *huge* number of changes related to ongoing modifications.
|
||||
|
||||
|
|
@ -19992,7 +19501,6 @@ Version 1.1 Beta1 (October 30, 1996)
|
|||
|
||||
Version 1.0 Final (August 31, 1996)
|
||||
===================================
|
||||
|
||||
1. Fixed minor bug in C++ module
|
||||
|
||||
2. Fixed minor bug in pointer type-checker when using
|
||||
|
|
@ -20076,7 +19584,7 @@ number of immediate problems :
|
|||
3. A few minor fixes were made in the Makefile
|
||||
|
||||
Version 1.0 Beta 3 (June 14, 1996)
|
||||
==================================
|
||||
===================================
|
||||
|
||||
|
||||
There are lots of changes in this release :
|
||||
|
|
@ -20166,7 +19674,6 @@ let me know.
|
|||
|
||||
Version 1.0 Beta 2 (April 26, 1996)
|
||||
===================================
|
||||
|
||||
This release is identical to Beta1 except a few minor bugs are
|
||||
fixed and the SWIG library has been updated to work with Tcl 7.5/Tk 4.1.
|
||||
A tcl7.5 examples directory is now included.
|
||||
|
|
@ -20181,7 +19688,6 @@ A tcl7.5 examples directory is now included.
|
|||
|
||||
Version 1.0 Beta 1 (April 10, 1996).
|
||||
=====================================
|
||||
|
||||
This is the first "semi-official" release of SWIG. It has a
|
||||
number of substantial improvements over the Alpha release. These
|
||||
notes are in no particular order--hope I remembered everything....
|
||||
|
|
|
|||
|
|
@ -1,18 +1,3 @@
|
|||
Version 1.3.40 (in progress)
|
||||
============================
|
||||
Version 1.3.36 (in progress)
|
||||
=============================
|
||||
|
||||
2009-04-09: wsfulton
|
||||
Fix #2746858 - C macro expression using floating point numbers
|
||||
|
||||
2009-03-30: olly
|
||||
[PHP] The default out typemap for char[ANY] now returns the string up to a
|
||||
zero byte, or the end of the array if there is no zero byte. This
|
||||
is the same as Python does, and seems more generally useful than
|
||||
the previous behaviour of returning the whole contents of the array
|
||||
including any zero bytes. If you want the old behaviour, you can provide
|
||||
your own typemap to do this:
|
||||
|
||||
%typemap(out) char [ANY]
|
||||
%{
|
||||
RETVAL_STRINGL($1, $1_dim0, 1);
|
||||
%}
|
||||
|
|
|
|||
112
Doc/Manual/Allegrocl.html
Normal file → Executable file
112
Doc/Manual/Allegrocl.html
Normal file → Executable file
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<H1><a name="Allegrocl_nn1"></a>17 SWIG and Allegro Common Lisp</H1>
|
||||
<H1><a name="Allegrocl_nn1"></a>16 SWIG and Allegro Common Lisp</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -135,10 +135,10 @@ be unhappy to see some enterprising folk use this work to add
|
|||
to it.
|
||||
</p>
|
||||
|
||||
<H2><a name="Allegrocl_nn2"></a>17.1 Basics</H2>
|
||||
<H2><a name="Allegrocl_nn2"></a>16.1 Basics</H2>
|
||||
|
||||
|
||||
<H3><a name="Allegrocl_nn3"></a>17.1.1 Running Swig</H3>
|
||||
<H3><a name="Allegrocl_nn3"></a>16.1.1 Running Swig</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -360,7 +360,7 @@ need to link in the Allegro shared library. The library you create from
|
|||
the C++ wrapper will be what you then load into Allegro CL.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn4"></a>17.1.2 Command Line Options</H3>
|
||||
<H3><a name="Allegrocl_nn4"></a>16.1.2 Command Line Options</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -396,7 +396,7 @@ See <a href="#Allegrocl_nn47">Section 17.5 Identifier converter
|
|||
functions</a> for more details.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn5"></a>17.1.3 Inserting user code into generated files</H3>
|
||||
<H3><a name="Allegrocl_nn5"></a>16.1.3 Inserting user code into generated files</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -411,7 +411,7 @@ using the SWIG <tt>%insert(section) %{ ...code... %}</tt> directive:
|
|||
<pre>
|
||||
%module example
|
||||
|
||||
%{
|
||||
%insert("runtime") %{
|
||||
#include "header.h"
|
||||
%}
|
||||
|
||||
|
|
@ -432,11 +432,11 @@ generated lisp interface file
|
|||
</ul>
|
||||
<p>
|
||||
Note that the block <tt>%{ ... %}</tt> is effectively a shortcut for
|
||||
<tt>%insert("header") %{ ... %}</tt>.
|
||||
<tt>%insert("runtime") %{ ... %}</tt>.
|
||||
</p>
|
||||
|
||||
|
||||
<H2><a name="Allegrocl_nn6"></a>17.2 Wrapping Overview</H2>
|
||||
<H2><a name="Allegrocl_nn6"></a>16.2 Wrapping Overview</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -446,7 +446,7 @@ New users to SWIG are encouraged to read
|
|||
interested in generating an interface to C++.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn7"></a>17.2.1 Function Wrapping</H3>
|
||||
<H3><a name="Allegrocl_nn7"></a>16.2.1 Function Wrapping</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -499,7 +499,7 @@ interested in generating an interface to C++.
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Allegrocl_nn8"></a>17.2.2 Foreign Wrappers</H3>
|
||||
<H3><a name="Allegrocl_nn8"></a>16.2.2 Foreign Wrappers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -512,7 +512,7 @@ interested in generating an interface to C++.
|
|||
typemap.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn9"></a>17.2.3 FFI Wrappers</H3>
|
||||
<H3><a name="Allegrocl_nn9"></a>16.2.3 FFI Wrappers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -593,7 +593,7 @@ char *xxx();
|
|||
ff:def-foreign-call's.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn10"></a>17.2.4 Non-overloaded Defuns</H3>
|
||||
<H3><a name="Allegrocl_nn10"></a>16.2.4 Non-overloaded Defuns</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -606,7 +606,7 @@ char *xxx();
|
|||
this function can be manipulated via the <tt>lout</tt> typemap.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn11"></a>17.2.5 Overloaded Defuns</H3>
|
||||
<H3><a name="Allegrocl_nn11"></a>16.2.5 Overloaded Defuns</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -622,7 +622,7 @@ char *xxx();
|
|||
can be manipulated via the <tt>lout</tt> typemap.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn12"></a>17.2.6 What about constant and variable access?</H3>
|
||||
<H3><a name="Allegrocl_nn12"></a>16.2.6 What about constant and variable access?</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -635,7 +635,7 @@ char *xxx();
|
|||
into the foreign module.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn13"></a>17.2.7 Object Wrapping</H3>
|
||||
<H3><a name="Allegrocl_nn13"></a>16.2.7 Object Wrapping</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -657,7 +657,7 @@ char *xxx();
|
|||
foreign function interface.
|
||||
</p>
|
||||
|
||||
<H2><a name="Allegrocl_nn14"></a>17.3 Wrapping Details</H2>
|
||||
<H2><a name="Allegrocl_nn14"></a>16.3 Wrapping Details</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -665,7 +665,7 @@ char *xxx();
|
|||
translated into lisp.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn15"></a>17.3.1 Namespaces</H3>
|
||||
<H3><a name="Allegrocl_nn15"></a>16.3.1 Namespaces</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -742,7 +742,7 @@ namespace car {
|
|||
function such as <tt>(car '(1 2 3)</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn16"></a>17.3.2 Constants</H3>
|
||||
<H3><a name="Allegrocl_nn16"></a>16.3.2 Constants</H3>
|
||||
|
||||
|
||||
|
||||
|
|
@ -803,7 +803,7 @@ namespace car {
|
|||
not use the <tt>-nocwrap</tt> command-line option.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn17"></a>17.3.3 Variables</H3>
|
||||
<H3><a name="Allegrocl_nn17"></a>16.3.3 Variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -881,7 +881,7 @@ globalvar> (globalvar.nnn::glob_float)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Allegrocl_nn18"></a>17.3.4 Enumerations</H3>
|
||||
<H3><a name="Allegrocl_nn18"></a>16.3.4 Enumerations</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -957,7 +957,7 @@ EXPORT const int ACL_ENUM___FOO3__SWIG_0 = FOO3;
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Allegrocl_nn19"></a>17.3.5 Arrays</H3>
|
||||
<H3><a name="Allegrocl_nn19"></a>16.3.5 Arrays</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1105,10 +1105,10 @@ namespace BAR {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Allegrocl_nn20"></a>17.3.6 Classes and Structs and Unions (oh my!)</H3>
|
||||
<H3><a name="Allegrocl_nn20"></a>16.3.6 Classes and Structs and Unions (oh my!)</H3>
|
||||
|
||||
|
||||
<H4><a name="Allegrocl_nn21"></a>17.3.6.1 CLOS wrapping of</H4>
|
||||
<H4><a name="Allegrocl_nn21"></a>16.3.6.1 CLOS wrapping of</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1123,7 +1123,7 @@ namespace BAR {
|
|||
integer values.
|
||||
</p>
|
||||
|
||||
<H4><a name="Allegrocl_nn22"></a>17.3.6.2 CLOS Inheritance</H4>
|
||||
<H4><a name="Allegrocl_nn22"></a>16.3.6.2 CLOS Inheritance</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1136,7 +1136,7 @@ namespace BAR {
|
|||
parameter.
|
||||
</p>
|
||||
|
||||
<H4><a name="Allegrocl_nn23"></a>17.3.6.3 Member fields and functions</H4>
|
||||
<H4><a name="Allegrocl_nn23"></a>16.3.6.3 Member fields and functions</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1152,7 +1152,7 @@ namespace BAR {
|
|||
the interface does nothing for <tt>friend</tt> directives,
|
||||
</p>
|
||||
|
||||
<H4><a name="Allegrocl_nn24"></a>17.3.6.4 Why not directly access C++ classes using foreign types?</H4>
|
||||
<H4><a name="Allegrocl_nn24"></a>16.3.6.4 Why not directly access C++ classes using foreign types?</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1170,11 +1170,11 @@ namespace BAR {
|
|||
use the more robust wrapper functions.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn25"></a>17.3.7 Templates</H3>
|
||||
<H3><a name="Allegrocl_nn25"></a>16.3.7 Templates</H3>
|
||||
|
||||
|
||||
|
||||
<H4><a name="Allegrocl_nn26"></a>17.3.7.1 Generating wrapper code for templates</H4>
|
||||
<H4><a name="Allegrocl_nn26"></a>16.3.7.1 Generating wrapper code for templates</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1187,7 +1187,7 @@ namespace BAR {
|
|||
directive.
|
||||
</p>
|
||||
|
||||
<H4><a name="Allegrocl_nn27"></a>17.3.7.2 Implicit Template instantiation</H4>
|
||||
<H4><a name="Allegrocl_nn27"></a>16.3.7.2 Implicit Template instantiation</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1197,7 +1197,7 @@ namespace BAR {
|
|||
class schema.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn28"></a>17.3.8 Typedef, Templates, and Synonym Types</H3>
|
||||
<H3><a name="Allegrocl_nn28"></a>16.3.8 Typedef, Templates, and Synonym Types</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1277,7 +1277,7 @@ synonym>
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="Allegrocl_nn29"></a>17.3.8.1 Choosing a primary type</H4>
|
||||
<H4><a name="Allegrocl_nn29"></a>16.3.8.1 Choosing a primary type</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1298,7 +1298,7 @@ synonym>
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<H3><a name="Allegrocl_nn30"></a>17.3.9 Function overloading/Parameter defaulting</H3>
|
||||
<H3><a name="Allegrocl_nn30"></a>16.3.9 Function overloading/Parameter defaulting</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1461,7 +1461,7 @@ overload>
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Allegrocl_nn31"></a>17.3.10 Operator wrapping and Operator overloading</H3>
|
||||
<H3><a name="Allegrocl_nn31"></a>16.3.10 Operator wrapping and Operator overloading</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1607,7 +1607,7 @@ opoverload>
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Allegrocl_nn32"></a>17.3.11 Varargs</H3>
|
||||
<H3><a name="Allegrocl_nn32"></a>16.3.11 Varargs</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1628,7 +1628,7 @@ opoverload>
|
|||
with other ways such functions can be wrapped.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn33"></a>17.3.12 C++ Exceptions</H3>
|
||||
<H3><a name="Allegrocl_nn33"></a>16.3.12 C++ Exceptions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1640,7 +1640,7 @@ opoverload>
|
|||
implemented.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn34"></a>17.3.13 Pass by value, pass by reference</H3>
|
||||
<H3><a name="Allegrocl_nn34"></a>16.3.13 Pass by value, pass by reference</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1652,7 +1652,7 @@ opoverload>
|
|||
newly defined types.
|
||||
</p>
|
||||
|
||||
<H2><a name="Allegrocl_nn35"></a>17.4 Typemaps</H2>
|
||||
<H2><a name="Allegrocl_nn35"></a>16.4 Typemaps</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1663,7 +1663,7 @@ opoverload>
|
|||
on <a href="Typemaps.html#Typemaps">Typemaps</a> for more information.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn36"></a>17.4.1 Code Generation in the C++ Wrapper</H3>
|
||||
<H3><a name="Allegrocl_nn36"></a>16.4.1 Code Generation in the C++ Wrapper</H3>
|
||||
|
||||
|
||||
|
||||
|
|
@ -1693,7 +1693,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="Allegrocl_nn37"></a>17.4.1.1 IN Typemap</H4>
|
||||
<H4><a name="Allegrocl_nn37"></a>16.4.1.1 IN Typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1728,7 +1728,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="Allegrocl_nn38"></a>17.4.1.2 OUT Typemap</H4>
|
||||
<H4><a name="Allegrocl_nn38"></a>16.4.1.2 OUT Typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1752,7 +1752,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="Allegrocl_nn39"></a>17.4.1.3 CTYPE Typemap</H4>
|
||||
<H4><a name="Allegrocl_nn39"></a>16.4.1.3 CTYPE Typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1784,7 +1784,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
these <a href="Typemaps.html#Typemaps_nn25">common typemaps</a> here.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn40"></a>17.4.2 Code generation in Lisp wrappers</H3>
|
||||
<H3><a name="Allegrocl_nn40"></a>16.4.2 Code generation in Lisp wrappers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1803,7 +1803,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
<a href="#Allegrocl_nn15">16.3.1 Namespaces</a> for details.
|
||||
</p>
|
||||
|
||||
<H4><a name="Allegrocl_nn41"></a>17.4.2.1 LIN Typemap</H4>
|
||||
<H4><a name="Allegrocl_nn41"></a>16.4.2.1 LIN Typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1846,7 +1846,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="Allegrocl_nn42"></a>17.4.2.2 LOUT Typemap</H4>
|
||||
<H4><a name="Allegrocl_nn42"></a>16.4.2.2 LOUT Typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1889,7 +1889,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="Allegrocl_nn43"></a>17.4.2.3 FFITYPE Typemap</H4>
|
||||
<H4><a name="Allegrocl_nn43"></a>16.4.2.3 FFITYPE Typemap</H4>
|
||||
|
||||
|
||||
|
||||
|
|
@ -1939,7 +1939,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="Allegrocl_nn44"></a>17.4.2.4 LISPTYPE Typemap</H4>
|
||||
<H4><a name="Allegrocl_nn44"></a>16.4.2.4 LISPTYPE Typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1959,7 +1959,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="Allegrocl_nn45"></a>17.4.2.5 LISPCLASS Typemap</H4>
|
||||
<H4><a name="Allegrocl_nn45"></a>16.4.2.5 LISPCLASS Typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1983,7 +1983,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Allegrocl_nn46"></a>17.4.3 Modifying SWIG behavior using typemaps</H3>
|
||||
<H3><a name="Allegrocl_nn46"></a>16.4.3 Modifying SWIG behavior using typemaps</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2017,10 +2017,10 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="Allegrocl_nn47"></a>17.5 Identifier Converter functions</H2>
|
||||
<H2><a name="Allegrocl_nn47"></a>16.5 Identifier Converter functions</H2>
|
||||
|
||||
|
||||
<H3><a name="Allegrocl_nn48"></a>17.5.1 Creating symbols in the lisp environment</H3>
|
||||
<H3><a name="Allegrocl_nn48"></a>16.5.1 Creating symbols in the lisp environment</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2041,11 +2041,11 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
of arguments.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn49"></a>17.5.2 Existing identifier-converter functions</H3>
|
||||
<H3><a name="Allegrocl_nn49"></a>16.5.2 Existing identifier-converter functions</H3>
|
||||
|
||||
|
||||
<p>Two basic identifier routines have been defined.
|
||||
<H4><a name="Allegrocl_nn50"></a>17.5.2.1 identifier-convert-null</H4>
|
||||
<H4><a name="Allegrocl_nn50"></a>16.5.2.1 identifier-convert-null</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2054,7 +2054,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
strings, from which a symbol will be created.
|
||||
</p>
|
||||
|
||||
<H4><a name="Allegrocl_nn51"></a>17.5.2.2 identifier-convert-lispify</H4>
|
||||
<H4><a name="Allegrocl_nn51"></a>16.5.2.2 identifier-convert-lispify</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2063,7 +2063,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
same symbol transformations.
|
||||
</p>
|
||||
|
||||
<H4><a name="Allegrocl_nn52"></a>17.5.2.3 Default identifier to symbol conversions</H4>
|
||||
<H4><a name="Allegrocl_nn52"></a>16.5.2.3 Default identifier to symbol conversions</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2072,7 +2072,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
|
|||
default naming conventions.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn53"></a>17.5.3 Defining your own identifier-converter</H3>
|
||||
<H3><a name="Allegrocl_nn53"></a>16.5.3 Defining your own identifier-converter</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2128,7 +2128,7 @@ indicating the number of arguments passed to the routine indicated by
|
|||
this identifier.
|
||||
</p>
|
||||
|
||||
<H3><a name="Allegrocl_nn54"></a>17.5.4 Instructing SWIG to use a particular identifier-converter</H3>
|
||||
<H3><a name="Allegrocl_nn54"></a>16.5.4 Instructing SWIG to use a particular identifier-converter</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -5,18 +5,12 @@
|
|||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<H1><a name="CSharp"></a>18 SWIG and C#</H1>
|
||||
<H1><a name="CSharp"></a>17 SWIG and C#</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
<li><a href="#csharp_introduction">Introduction</a>
|
||||
<li><a href="#csharp_differences_java">Differences to the Java module</a>
|
||||
<li><a href="#CSharp_arrays">C# Arrays</a>
|
||||
<ul>
|
||||
<li><a href="#CSharp_arrays_swig_library">The SWIG C arrays library</a>
|
||||
<li><a href="#CSharp_arrays_pinvoke_default_array_marshalling">Managed arrays using P/Invoke default array marshalling</a>
|
||||
<li><a href="#CSharp_arrays_pinning">Managed arrays using pinning</a>
|
||||
</ul>
|
||||
<li><a href="#csharp_exceptions">C# Exceptions</a>
|
||||
<ul>
|
||||
<li><a href="#csharp_exception_example_check_typemap">C# exception example using "check" typemap</a>
|
||||
|
|
@ -45,7 +39,7 @@
|
|||
|
||||
|
||||
|
||||
<H2><a name="csharp_introduction"></a>18.1 Introduction</H2>
|
||||
<H2><a name="csharp_introduction"></a>17.1 Introduction</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -65,7 +59,7 @@ The <a href="http://msdn.microsoft.com">Microsoft Developer Network (MSDN)</a> h
|
|||
Monodoc, available from the Mono project, has a very useful section titled <a href="http://www.mono-project.com/Interop_with_Native_Libraries">Interop with native libraries</a>.
|
||||
</p>
|
||||
|
||||
<H2><a name="csharp_differences_java"></a>18.2 Differences to the Java module</H2>
|
||||
<H2><a name="csharp_differences_java"></a>17.2 Differences to the Java module</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -207,12 +201,7 @@ $jnicall -> $imcall
|
|||
|
||||
<li>
|
||||
<p>
|
||||
Unlike the "javain" typemap, the "csin" typemap does not support the 'pgcpp' attribute as the C# module does not have a premature garbage collection prevention parameter.
|
||||
The "csin" typemap supports additional optional attributes called 'cshin' and 'terminator'.
|
||||
The 'cshin' attribute should contain the parameter type and name whenever a <a href="Java.html#java_constructor_helper_function">constructor helper function</a> is generated due to the 'pre' or 'post' attributes.
|
||||
The 'terminator' attribute normally just contains a closing brace for when the 'pre' attribute contains an opening brace, such as when a C# <tt>using</tt> or <tt>fixed</tt> block is started.
|
||||
Note that 'pre', 'post', 'terminator' and 'cshin' attributes are not used for marshalling the property set.
|
||||
Please see the <a href="#csharp_date_marshalling">Date marshalling example</a> and <a href="#CSharp.html#csharp_date_properties">Date marshalling of properties example</a> for further understanding of these "csin" applicable attributes.
|
||||
Unlike the "javain" typemap, the "csin" typemap does not support the 'pgcpp' attribute as the C# module does not have a premature garbage collection prevention parameter. The "csin" typemap supports an additional optional attribute called 'cshin'. It should contain the parameter type and name whenever a <a href="Java.html#java_constructor_helper_function">constructor helper function</a> is generated due to the 'pre' or 'post' attributes. Note that 'pre', 'post' and 'cshin' attributes are not used for marshalling the property set. Please see the <a href="#csharp_date_marshalling">Date marshalling example</a> and <a href="#CSharp.html#csharp_date_properties">Date marshalling of properties example</a> for further understanding.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
|
|
@ -408,275 +397,7 @@ Windows users can also get the examples working using a
|
|||
<a href="http://www.cygwin.com">Cygwin</a> or <a href="http://www.mingw.org">MinGW</a> environment for automatic configuration of the example makefiles.
|
||||
Any one of the three C# compilers (Portable.NET, Mono or Microsoft) can be detected from within a Cygwin or Mingw environment if installed in your path.
|
||||
|
||||
<H2><a name="CSharp_arrays"></a>18.3 C# Arrays</H2>
|
||||
|
||||
|
||||
<p>
|
||||
There are various ways to pass arrays from C# to C/C++.
|
||||
The default wrapping treats arrays as pointers and as such simple type wrapper classes are generated,
|
||||
eg <tt>SWIGTYPE_p_int</tt> when wrapping the C type <tt>int []</tt> or <tt>int *</tt>.
|
||||
This gives a rather restricted use of the underlying unmanaged code and the most practical way to use arrays is to enhance or customise
|
||||
with one of the following three approaches; namely the SWIG C arrays library, P/Invoke default array marshalling or
|
||||
pinned arrays.
|
||||
</p>
|
||||
|
||||
<H3><a name="CSharp_arrays_swig_library"></a>18.3.1 The SWIG C arrays library</H3>
|
||||
|
||||
|
||||
<p>
|
||||
The C arrays library keeps all the array memory in the unmanaged layer.
|
||||
The library is available to all language modules and is documented in the <a href="Library.html#Library_carrays">carrays.i library</a> section.
|
||||
Please refer to this section for details, but for convenience, the C# usage for the two examples outlined there is shown below.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For the <tt>%array_functions</tt> example, the equivalent usage would be:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
SWIGTYPE_p_double a = example.new_doubleArray(10); // Create an array
|
||||
for (int i=0; i<10; i++)
|
||||
example.doubleArray_setitem(a,i,2*i); // Set a value
|
||||
example.print_array(a); // Pass to C
|
||||
example.delete_doubleArray(a); // Destroy array
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
and for the <tt>%array_class</tt> example, the equivalent usage would be:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
doubleArray c = new doubleArray(10); // Create double[10]
|
||||
for (int i=0; i<10; i++)
|
||||
c.setitem(i, 2*i); // Assign values
|
||||
example.print_array(c.cast()); // Pass to C
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
||||
<H3><a name="CSharp_arrays_pinvoke_default_array_marshalling"></a>18.3.2 Managed arrays using P/Invoke default array marshalling</H3>
|
||||
|
||||
|
||||
<p>
|
||||
In the P/Invoke default marshalling scheme, one needs to designate whether the invoked function will treat a managed
|
||||
array parameter as input, output, or both. When the function is invoked, the CLR allocates a separate chunk of memory as big as the given managed array,
|
||||
which is automatically released at the end of the function call. If the array parameter is marked as being input, the content of the managed array is copied
|
||||
into this buffer when the call is made. Correspondingly, if the array parameter is marked as being output, the contents of the reserved buffer are copied
|
||||
back into the managed array after the call returns. A pointer to to this buffer
|
||||
is passed to the native function.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The reason for allocating a separate buffer is to leave the CLR free to relocate the managed array object
|
||||
during garbage collection. If the overhead caused by the copying is causing a significant performance penalty, consider pinning the managed array and
|
||||
passing a direct reference as described in the next section.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For more information on the subject, see the
|
||||
<a href="http://msdn.microsoft.com/en-us/library/z6cfh6e6(VS.80).aspx">Default Marshaling for Arrays</a> article
|
||||
on MSDN.
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
The P/Invoke default marshalling is supported by the <tt>arrays_csharp.i</tt> library via the INPUT, OUTPUT and INOUT typemaps.
|
||||
Let's look at some example usage. Consider the following C function:
|
||||
</p>
|
||||
<div class="code">
|
||||
<pre>
|
||||
void myArrayCopy(int *sourceArray, int *targetArray, int nitems);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
We can now instruct SWIG to use the default marshalling typemaps by
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%include "arrays_csharp.i"
|
||||
|
||||
%apply int INPUT[] {int *sourceArray}
|
||||
%apply int OUTPUT[] {int *targetArray}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
As a result, we get the following method in the module class:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
public static void myArrayCopy(int[] sourceArray, int[] targetArray, int nitems) {
|
||||
examplePINVOKE.myArrayCopy(sourceArray, targetArray, nitems);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
If we look beneath the surface at the corresponding intermediary class code, we see
|
||||
that SWIG has generated code that uses attributes
|
||||
(from the System.Runtime.InteropServices namespace) to tell the CLR to use default
|
||||
marshalling for the arrays:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
[DllImport("example", EntryPoint="CSharp_myArrayCopy")]
|
||||
public static extern void myArrayCopy([In, MarshalAs(UnmanagedType.LPArray)]int[] jarg1,
|
||||
[Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg2, int jarg3);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
As an example of passing an inout array (i.e. the target function will both read from and
|
||||
write to the array), consider this C function that swaps a given number of elements
|
||||
in the given arrays:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
void myArraySwap(int *array1, int *array2, int nitems);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Now, we can instruct SWIG to wrap this by
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%include "arrays_csharp.i"
|
||||
|
||||
%apply int INOUT[] {int *array1}
|
||||
%apply int INOUT[] {int *array2}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
This results in the module class method
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
public static void myArraySwap(int[] array1, int[] array2, int nitems) {
|
||||
examplePINVOKE.myArraySwap(array1, array2, nitems);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
and intermediate class method
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
[DllImport("example", EntryPoint="CSharp_myArraySwap")]
|
||||
public static extern void myArraySwap([In, Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg1,
|
||||
[In, Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg2, int jarg3);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
||||
<H3><a name="CSharp_arrays_pinning"></a>18.3.3 Managed arrays using pinning</H3>
|
||||
|
||||
|
||||
<p>
|
||||
It is also possible to pin a given array in memory (i.e. fix its location in memory), obtain a
|
||||
direct pointer to it, and then pass this pointer to the wrapped C/C++ function. This approach
|
||||
involves no copying, but it makes the work of the garbage collector harder as
|
||||
the managed array object can not be relocated before the fix on the array is released. You should avoid
|
||||
fixing arrays in memory in cases where the control may re-enter the managed side via a callback and/or
|
||||
another thread may produce enough garbage to trigger garbage collection.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For more information, see the <a href="http://msdn.microsoft.com/en-us/library/f58wzh21(VS.80).aspx">fixed statement</a> in the C# language reference.
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
Now let's look at an example using pinning, thus avoiding the CLR making copies
|
||||
of the arrays passed as parameters. The <tt>arrays_csharp.i</tt> library file again provides the required support via the <tt>FIXED</tt> typemaps.
|
||||
Let's use the same function from the previous section:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
void myArrayCopy(int *sourceArray, int *targetArray, int nitems);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
We now need to declare the module class method unsafe, as we are using pointers:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%csmethodmodifiers myArrayCopy "public unsafe";
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Apply the appropriate typemaps to the array parameters:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%include "arrays_csharp.i"
|
||||
|
||||
%apply int FIXED[] {int *sourceArray}
|
||||
%apply int FIXED[] {int *targetArray}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Notice that there is no need for separate in, out or inout typemaps as is the
|
||||
case when using P/Invoke default marshalling.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
As a result, we get the following method in the module class:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
public unsafe static void myArrayCopy(int[] sourceArray, int[] targetArray, int nitems) {
|
||||
fixed ( int *swig_ptrTo_sourceArray = sourceArray ) {
|
||||
fixed ( int *swig_ptrTo_targetArray = targetArray ) {
|
||||
{
|
||||
examplePINVOKE.myArrayCopy((IntPtr)swig_ptrTo_sourceArray, (IntPtr)swig_ptrTo_targetArray, nitems);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
On the method signature level the only difference to the version using P/Invoke default
|
||||
marshalling is the "unsafe" quantifier, which is required because we are handling pointers.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Also the intermediate class method looks a little different from the default marshalling
|
||||
example - the method is expecting an IntPtr as the parameter type.
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
[DllImport("example", EntryPoint="CSharp_myArrayCopy")]
|
||||
public static extern void myArrayCopy(IntPtr jarg1, IntPtr jarg2, int jarg3);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<H2><a name="csharp_exceptions"></a>18.4 C# Exceptions</H2>
|
||||
<H2><a name="csharp_exceptions"></a>17.3 C# Exceptions</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -773,7 +494,7 @@ set so should only be used when a C# exception is not created.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="csharp_exception_example_check_typemap"></a>18.4.1 C# exception example using "check" typemap</H3>
|
||||
<H3><a name="csharp_exception_example_check_typemap"></a>17.3.1 C# exception example using "check" typemap</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -955,7 +676,7 @@ method and C# code does not handle pending exceptions via the canthrow attribute
|
|||
Actually it will issue this warning for any function beginning with <tt>SWIG_CSharpSetPendingException</tt>.
|
||||
</P>
|
||||
|
||||
<H3><a name="csharp_exception_example_percent_exception"></a>18.4.2 C# exception example using %exception</H3>
|
||||
<H3><a name="csharp_exception_example_percent_exception"></a>17.3.2 C# exception example using %exception</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1020,7 +741,7 @@ The managed code generated does check for the pending exception as mentioned ear
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="csharp_exception_example_exception_specifications"></a>18.4.3 C# exception example using exception specifications</H3>
|
||||
<H3><a name="csharp_exception_example_exception_specifications"></a>17.3.3 C# exception example using exception specifications</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1077,7 +798,7 @@ SWIGEXPORT void SWIGSTDCALL CSharp_evensonly(int jarg1) {
|
|||
Multiple catch handlers are generated should there be more than one exception specifications declared.
|
||||
</p>
|
||||
|
||||
<H3><a name="csharp_custom_application_exception"></a>18.4.4 Custom C# ApplicationException example</H3>
|
||||
<H3><a name="csharp_custom_application_exception"></a>17.3.4 Custom C# ApplicationException example</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1211,7 +932,7 @@ try {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="csharp_directors"></a>18.5 C# Directors</H2>
|
||||
<H2><a name="csharp_directors"></a>17.4 C# Directors</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1224,7 +945,7 @@ The following sections provide information on the C# director implementation and
|
|||
However, the <a href="Java.html#java_directors">Java directors</a> section should also be read in order to gain more insight into directors.
|
||||
</p>
|
||||
|
||||
<H3><a name="csharp_directors_example"></a>18.5.1 Directors example</H3>
|
||||
<H3><a name="csharp_directors_example"></a>17.4.1 Directors example</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1345,7 +1066,7 @@ CSharpDerived - UIntMethod(123)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="csharp_directors_implementation"></a>18.5.2 Directors implementation</H3>
|
||||
<H3><a name="csharp_directors_implementation"></a>17.4.2 Directors implementation</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1531,7 +1252,7 @@ void SwigDirector_Base::BaseBoolMethod(Base const &b, bool flag) {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="csharp_director_caveats"></a>18.5.3 Director caveats</H3>
|
||||
<H3><a name="csharp_director_caveats"></a>17.4.3 Director caveats</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1579,7 +1300,7 @@ However, a call from C# to <tt>CSharpDefaults.DefaultMethod()</tt> will of cours
|
|||
should pass the call on to <tt>CSharpDefaults.DefaultMethod(int)</tt>using the C++ default value, as shown above.
|
||||
</p>
|
||||
|
||||
<H2><a name="csharp_typemap_examples"></a>18.6 C# Typemap examples</H2>
|
||||
<H2><a name="csharp_typemap_examples"></a>17.5 C# Typemap examples</H2>
|
||||
|
||||
|
||||
This section includes a few examples of typemaps. For more examples, you
|
||||
|
|
@ -1587,7 +1308,7 @@ might look at the files "<tt>csharp.swg</tt>" and "<tt>typemaps.i</tt>" in
|
|||
the SWIG library.
|
||||
|
||||
|
||||
<H3><a name="csharp_memory_management_member_variables"></a>18.6.1 Memory management when returning references to member variables</H3>
|
||||
<H3><a name="csharp_memory_management_member_variables"></a>17.5.1 Memory management when returning references to member variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1711,7 +1432,7 @@ public class Bike : IDisposable {
|
|||
Note the <tt>addReference</tt> call.
|
||||
</p>
|
||||
|
||||
<H3><a name="csharp_memory_management_objects"></a>18.6.2 Memory management for objects passed to the C++ layer</H3>
|
||||
<H3><a name="csharp_memory_management_objects"></a>17.5.2 Memory management for objects passed to the C++ layer</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1830,7 +1551,7 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class.
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="csharp_date_marshalling"></a>18.6.3 Date marshalling using the csin typemap and associated attributes</H3>
|
||||
<H3><a name="csharp_date_marshalling"></a>17.5.3 Date marshalling using the csin typemap and associated attributes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1846,7 +1567,6 @@ Let's assume the code being wrapped is as follows:
|
|||
<pre>
|
||||
class CDate {
|
||||
public:
|
||||
CDate();
|
||||
CDate(int year, int month, int day);
|
||||
int getYear();
|
||||
int getMonth();
|
||||
|
|
@ -1929,8 +1649,8 @@ The typemaps to achieve this are shown below.
|
|||
<pre>
|
||||
%typemap(cstype) const CDate& "System.DateTime"
|
||||
%typemap(csin,
|
||||
pre=" CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);"
|
||||
) const CDate &
|
||||
pre=" CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);")
|
||||
const CDate &
|
||||
"$csclassname.getCPtr(temp$csinput)"
|
||||
|
||||
%typemap(cstype) CDate& "out System.DateTime"
|
||||
|
|
@ -1938,8 +1658,7 @@ The typemaps to achieve this are shown below.
|
|||
pre=" CDate temp$csinput = new CDate();",
|
||||
post=" $csinput = new System.DateTime(temp$csinput.getYear(),"
|
||||
" temp$csinput.getMonth(), temp$csinput.getDay(), 0, 0, 0);",
|
||||
cshin="out $csinput"
|
||||
) CDate &
|
||||
cshin="out $csinput") CDate &
|
||||
"$csclassname.getCPtr(temp$csinput)"
|
||||
|
||||
</pre>
|
||||
|
|
@ -2044,8 +1763,7 @@ will be possible with the following <tt>CDate *</tt> typemaps
|
|||
pre=" CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);",
|
||||
post=" $csinput = new System.DateTime(temp$csinput.getYear(),"
|
||||
" temp$csinput.getMonth(), temp$csinput.getDay(), 0, 0, 0);",
|
||||
cshin="ref $csinput"
|
||||
) CDate *
|
||||
cshin="ref $csinput") CDate *
|
||||
"$csclassname.getCPtr(temp$csinput)"
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2070,51 +1788,7 @@ public class example {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The following typemap is the same as the previous but demonstrates how a using block can be used for the temporary variable.
|
||||
The only change to the previous typemap is the introduction of the 'terminator' attribute to terminate the <tt>using</tt> block.
|
||||
The <tt>subtractYears</tt> method is nearly identical to the above <tt>addYears</tt> method.
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%typemap(csin,
|
||||
pre=" using (CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day)) {",
|
||||
post=" $csinput = new System.DateTime(temp$csinput.getYear(),"
|
||||
" temp$csinput.getMonth(), temp$csinput.getDay(), 0, 0, 0);",
|
||||
terminator=" } // terminate temp$csinput using block",
|
||||
cshin="ref $csinput"
|
||||
) CDate *
|
||||
"$csclassname.getCPtr(temp$csinput)"
|
||||
|
||||
void subtractYears(CDate *pDate, int years) {
|
||||
*pDate = CDate(pDate->getYear() - years, pDate->getMonth(), pDate->getDay());
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The resulting generated code shows the termination of the <tt>using</tt> block:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
public class example {
|
||||
public static void subtractYears(ref System.DateTime pDate, int years) {
|
||||
using (CDate temppDate = new CDate(pDate.Year, pDate.Month, pDate.Day)) {
|
||||
try {
|
||||
examplePINVOKE.subtractYears(CDate.getCPtr(temppDate), years);
|
||||
} finally {
|
||||
pDate = new System.DateTime(temppDate.getYear(), temppDate.getMonth(), temppDate.getDay(), 0, 0, 0);
|
||||
}
|
||||
} // terminate temppDate using block
|
||||
}
|
||||
...
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="csharp_date_properties"></a>18.6.4 A date example demonstrating marshalling of C# properties</H3>
|
||||
<H3><a name="csharp_date_properties"></a>17.5.4 A date example demonstrating marshalling of C# properties</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2153,8 +1827,7 @@ The typemap type required is thus <tt>CDate *</tt>. Given that the previous sect
|
|||
pre=" CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);",
|
||||
post=" $csinput = new System.DateTime(temp$csinput.getYear(),"
|
||||
" temp$csinput.getMonth(), temp$csinput.getDay(), 0, 0, 0);",
|
||||
cshin="ref $csinput"
|
||||
) CDate *
|
||||
cshin="ref $csinput") CDate *
|
||||
"$csclassname.getCPtr(temp$csinput)"
|
||||
|
||||
%typemap(csvarin, excode=SWIGEXCODE2) CDate * %{
|
||||
|
|
@ -2215,7 +1888,7 @@ Some points to note:
|
|||
</ul>
|
||||
|
||||
|
||||
<H3><a name="csharp_partial_classes"></a>18.6.5 Turning wrapped classes into partial classes</H3>
|
||||
<H3><a name="csharp_partial_classes"></a>17.5.5 Turning wrapped classes into partial classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2315,7 +1988,7 @@ demonstrating that the class contains methods calling both unmanaged code - <tt>
|
|||
The following example is an alternative approach to adding managed code to the generated proxy class.
|
||||
</p>
|
||||
|
||||
<H3><a name="csharp_extending_proxy_class"></a>18.6.6 Extending proxy classes with additional C# code</H3>
|
||||
<H3><a name="csharp_extending_proxy_class"></a>17.5.6 Extending proxy classes with additional C# code</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<H1><a name="Chicken"></a>19 SWIG and Chicken</H1>
|
||||
<H1><a name="Chicken"></a>18 SWIG and Chicken</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -72,7 +72,7 @@
|
|||
|
||||
</p>
|
||||
|
||||
<H2><a name="Chicken_nn2"></a>19.1 Preliminaries</H2>
|
||||
<H2><a name="Chicken_nn2"></a>18.1 Preliminaries</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -90,7 +90,7 @@
|
|||
CHICKEN.
|
||||
</p>
|
||||
|
||||
<H3><a name="Chicken_nn3"></a>19.1.1 Running SWIG in C mode</H3>
|
||||
<H3><a name="Chicken_nn3"></a>18.1.1 Running SWIG in C mode</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -123,7 +123,7 @@
|
|||
object files and linked into your project.
|
||||
</p>
|
||||
|
||||
<H3><a name="Chicken_nn4"></a>19.1.2 Running SWIG in C++ mode</H3>
|
||||
<H3><a name="Chicken_nn4"></a>18.1.2 Running SWIG in C++ mode</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -152,10 +152,10 @@
|
|||
object files and linked into your project.
|
||||
</p>
|
||||
|
||||
<H2><a name="Chicken_nn5"></a>19.2 Code Generation</H2>
|
||||
<H2><a name="Chicken_nn5"></a>18.2 Code Generation</H2>
|
||||
|
||||
|
||||
<H3><a name="Chicken_nn6"></a>19.2.1 Naming Conventions</H3>
|
||||
<H3><a name="Chicken_nn6"></a>18.2.1 Naming Conventions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -171,7 +171,7 @@
|
|||
<tt>%rename</tt> SWIG directive in the SWIG interface file.
|
||||
</p>
|
||||
|
||||
<H3><a name="Chicken_nn7"></a>19.2.2 Modules</H3>
|
||||
<H3><a name="Chicken_nn7"></a>18.2.2 Modules</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -193,7 +193,7 @@
|
|||
(uses <i>modulename</i>))</code> CHICKEN Scheme form.
|
||||
</p>
|
||||
|
||||
<H3><a name="Chicken_nn8"></a>19.2.3 Constants and Variables</H3>
|
||||
<H3><a name="Chicken_nn8"></a>18.2.3 Constants and Variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -230,7 +230,7 @@
|
|||
for info on how to apply the %feature.
|
||||
</p>
|
||||
|
||||
<H3><a name="Chicken_nn9"></a>19.2.4 Functions</H3>
|
||||
<H3><a name="Chicken_nn9"></a>18.2.4 Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -249,7 +249,7 @@
|
|||
parameters). The return values can then be accessed with <code>(call-with-values)</code>.
|
||||
</p>
|
||||
|
||||
<H3><a name="Chicken_nn10"></a>19.2.5 Exceptions</H3>
|
||||
<H3><a name="Chicken_nn10"></a>18.2.5 Exceptions</H3>
|
||||
|
||||
|
||||
<p>The SWIG chicken module has support for exceptions thrown from
|
||||
|
|
@ -291,7 +291,7 @@
|
|||
</pre></div>
|
||||
|
||||
|
||||
<H2><a name="Chicken_nn11"></a>19.3 TinyCLOS</H2>
|
||||
<H2><a name="Chicken_nn11"></a>18.3 TinyCLOS</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -334,7 +334,7 @@
|
|||
|
||||
</p>
|
||||
|
||||
<H2><a name="Chicken_nn12"></a>19.4 Linkage</H2>
|
||||
<H2><a name="Chicken_nn12"></a>18.4 Linkage</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -355,7 +355,7 @@
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="Chicken_nn13"></a>19.4.1 Static binary or shared library linked at compile time</H3>
|
||||
<H3><a name="Chicken_nn13"></a>18.4.1 Static binary or shared library linked at compile time</H3>
|
||||
|
||||
|
||||
<p>We can easily use csc to build a static binary.</p>
|
||||
|
|
@ -396,7 +396,7 @@ in which case the test script does not need to be linked with example.so. The t
|
|||
be run with <tt>csi</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="Chicken_nn14"></a>19.4.2 Building chicken extension libraries</H3>
|
||||
<H3><a name="Chicken_nn14"></a>18.4.2 Building chicken extension libraries</H3>
|
||||
|
||||
|
||||
<p>Building a shared library like in the above section only works if the library
|
||||
|
|
@ -454,7 +454,7 @@ distributed and used by anyone, even if SWIG is not installed.</p>
|
|||
<p>See the <tt>Examples/chicken/egg</tt> directory in the SWIG source for an example that builds
|
||||
two eggs, one using the first method and one using the second method.</p>
|
||||
|
||||
<H3><a name="Chicken_nn15"></a>19.4.3 Linking multiple SWIG modules with TinyCLOS</H3>
|
||||
<H3><a name="Chicken_nn15"></a>18.4.3 Linking multiple SWIG modules with TinyCLOS</H3>
|
||||
|
||||
|
||||
<p>Linking together multiple modules that share type information using the <code>%import</code>
|
||||
|
|
@ -478,7 +478,7 @@ with <code>(declare (uses ...))</code>.
|
|||
To create an extension library or an egg, just create a <tt>module_load.scm</tt> file that <code>(declare (uses ...))</code>
|
||||
all the modules.</p>
|
||||
|
||||
<H2><a name="Chicken_nn16"></a>19.5 Typemaps</H2>
|
||||
<H2><a name="Chicken_nn16"></a>18.5 Typemaps</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -487,7 +487,7 @@ all the modules.</p>
|
|||
<code>Lib/chicken/chicken.swg</code>.
|
||||
</p>
|
||||
|
||||
<H2><a name="Chicken_nn17"></a>19.6 Pointers</H2>
|
||||
<H2><a name="Chicken_nn17"></a>18.6 Pointers</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -520,7 +520,7 @@ all the modules.</p>
|
|||
type. flags is either zero or SWIG_POINTER_DISOWN (see below).
|
||||
</p>
|
||||
|
||||
<H3><a name="collection"></a>19.6.1 Garbage collection</H3>
|
||||
<H3><a name="collection"></a>18.6.1 Garbage collection</H3>
|
||||
|
||||
|
||||
<p>If the owner flag passed to <code>SWIG_NewPointerObj</code> is 1, <code>NewPointerObj</code> will add a
|
||||
|
|
@ -551,7 +551,7 @@ all the modules.</p>
|
|||
must be called manually.
|
||||
</p>
|
||||
|
||||
<H2><a name="Chicken_nn18"></a>19.7 Unsupported features and known problems</H2>
|
||||
<H2><a name="Chicken_nn18"></a>18.7 Unsupported features and known problems</H2>
|
||||
|
||||
|
||||
<ul>
|
||||
|
|
@ -561,7 +561,7 @@ all the modules.</p>
|
|||
<a href="SWIGPlus.html#SWIGPlus_default_args">%feature(compactdefaultargs)</a>.</li>
|
||||
</ul>
|
||||
|
||||
<H3><a name="Chicken_nn19"></a>19.7.1 TinyCLOS problems with Chicken version <= 1.92</H3>
|
||||
<H3><a name="Chicken_nn19"></a>18.7.1 TinyCLOS problems with Chicken version <= 1.92</H3>
|
||||
|
||||
|
||||
<p>In Chicken versions equal to or below 1.92, TinyCLOS has a limitation such that generic methods do not properly work on methods
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@
|
|||
<li><a href="SWIG.html#SWIG_nn33">Character strings and structures</a>
|
||||
<li><a href="SWIG.html#SWIG_nn34">Array members</a>
|
||||
<li><a href="SWIG.html#SWIG_structure_data_members">Structure data members</a>
|
||||
<li><a href="SWIG.html#SWIG_nn36">C constructors and destructors</a>
|
||||
<li><a href="SWIG.html#SWIG_nn36">C constructors and destructors </a>
|
||||
<li><a href="SWIG.html#SWIG_adding_member_functions">Adding member functions to C structures</a>
|
||||
<li><a href="SWIG.html#SWIG_nested_structs">Nested structures</a>
|
||||
<li><a href="SWIG.html#SWIG_nn39">Other things to note about structure wrapping</a>
|
||||
|
|
@ -272,7 +272,7 @@
|
|||
<li><a href="Library.html#Library_nn3">C Arrays and Pointers</a>
|
||||
<ul>
|
||||
<li><a href="Library.html#Library_nn4">cpointer.i</a>
|
||||
<li><a href="Library.html#Library_carrays">carrays.i</a>
|
||||
<li><a href="Library.html#Library_nn5">carrays.i</a>
|
||||
<li><a href="Library.html#Library_nn6">cmalloc.i</a>
|
||||
<li><a href="Library.html#Library_nn7">cdata.i</a>
|
||||
</ul>
|
||||
|
|
@ -390,7 +390,6 @@
|
|||
<li><a href="Typemaps.html#Typemaps_nn48">More about <tt>%apply</tt> and <tt>%clear</tt></a>
|
||||
<li><a href="Typemaps.html#Typemaps_nn49">Reducing wrapper code size</a>
|
||||
<li><a href="Typemaps.html#Typemaps_nn47">Passing data between typemaps</a>
|
||||
<li><a href="Typemaps.html#Typemaps_nn52">C++ "this" pointer</a>
|
||||
<li><a href="Typemaps.html#Typemaps_nn51">Where to go for more information?</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -498,33 +497,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="CCache.html#CCache">16 Using SWIG with ccache - ccache-swig(1) manpage</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
<li><a href="CCache.html#CCache_nn2">NAME</a>
|
||||
<li><a href="CCache.html#CCache_nn3">SYNOPSIS</a>
|
||||
<li><a href="CCache.html#CCache_nn4">DESCRIPTION</a>
|
||||
<li><a href="CCache.html#CCache_nn5">OPTIONS SUMMARY</a>
|
||||
<li><a href="CCache.html#CCache_nn6">OPTIONS</a>
|
||||
<li><a href="CCache.html#CCache_nn7">INSTALLATION</a>
|
||||
<li><a href="CCache.html#CCache_nn8">EXTRA OPTIONS</a>
|
||||
<li><a href="CCache.html#CCache_nn9">ENVIRONMENT VARIABLES</a>
|
||||
<li><a href="CCache.html#CCache_nn10">CACHE SIZE MANAGEMENT</a>
|
||||
<li><a href="CCache.html#CCache_nn11">CACHE COMPRESSION</a>
|
||||
<li><a href="CCache.html#CCache_nn12">HOW IT WORKS</a>
|
||||
<li><a href="CCache.html#CCache_nn13">USING CCACHE WITH DISTCC</a>
|
||||
<li><a href="CCache.html#CCache_nn14">SHARING A CACHE</a>
|
||||
<li><a href="CCache.html#CCache_nn15">HISTORY</a>
|
||||
<li><a href="CCache.html#CCache_nn16">DIFFERENCES FROM COMPILERCACHE</a>
|
||||
<li><a href="CCache.html#CCache_nn17">CREDITS</a>
|
||||
<li><a href="CCache.html#CCache_nn18">AUTHOR</a>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Allegrocl.html#Allegrocl">17 SWIG and Allegro Common Lisp</a></h3>
|
||||
<h3><a href="Allegrocl.html#Allegrocl">16 SWIG and Allegro Common Lisp</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -608,19 +581,13 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="CSharp.html#CSharp">18 SWIG and C#</a></h3>
|
||||
<h3><a href="CSharp.html#CSharp">17 SWIG and C#</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
<li><a href="CSharp.html#csharp_introduction">Introduction</a>
|
||||
<li><a href="CSharp.html#csharp_differences_java">Differences to the Java module</a>
|
||||
<li><a href="CSharp.html#CSharp_arrays">C# Arrays</a>
|
||||
<ul>
|
||||
<li><a href="CSharp.html#CSharp_arrays_swig_library">The SWIG C arrays library</a>
|
||||
<li><a href="CSharp.html#CSharp_arrays_pinvoke_default_array_marshalling">Managed arrays using P/Invoke default array marshalling</a>
|
||||
<li><a href="CSharp.html#CSharp_arrays_pinning">Managed arrays using pinning</a>
|
||||
</ul>
|
||||
<li><a href="CSharp.html#csharp_exceptions">C# Exceptions</a>
|
||||
<ul>
|
||||
<li><a href="CSharp.html#csharp_exception_example_check_typemap">C# exception example using "check" typemap</a>
|
||||
|
|
@ -647,7 +614,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Chicken.html#Chicken">19 SWIG and Chicken</a></h3>
|
||||
<h3><a href="Chicken.html#Chicken">18 SWIG and Chicken</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -685,7 +652,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Guile.html#Guile">20 SWIG and Guile</a></h3>
|
||||
<h3><a href="Guile.html#Guile">19 SWIG and Guile</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -720,7 +687,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Java.html#Java">21 SWIG and Java</a></h3>
|
||||
<h3><a href="Java.html#Java">20 SWIG and Java</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -862,7 +829,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Lisp.html#Lisp">22 SWIG and Common Lisp</a></h3>
|
||||
<h3><a href="Lisp.html#Lisp">21 SWIG and Common Lisp</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -885,7 +852,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Lua.html#Lua">23 SWIG and Lua</a></h3>
|
||||
<h3><a href="Lua.html#Lua">22 SWIG and Lua</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -914,35 +881,20 @@
|
|||
<li><a href="Lua.html#Lua_nn20">C++ templates</a>
|
||||
<li><a href="Lua.html#Lua_nn21">C++ Smart Pointers</a>
|
||||
<li><a href="Lua.html#Lua_nn22">C++ Exceptions</a>
|
||||
<li><a href="Lua.html#Lua_nn23">Writing your own custom wrappers</a>
|
||||
<li><a href="Lua.html#Lua_nn24">Adding additional Lua code</a>
|
||||
</ul>
|
||||
<li><a href="Lua.html#Lua_nn23">Typemaps</a>
|
||||
<li><a href="Lua.html#Lua_nn25">Details on the Lua binding</a>
|
||||
<ul>
|
||||
<li><a href="Lua.html#Lua_nn24">What is a typemap?</a>
|
||||
<li><a href="Lua.html#Lua_nn25">Using typemaps</a>
|
||||
<li><a href="Lua.html#Lua_nn26">Typemaps and arrays</a>
|
||||
<li><a href="Lua.html#Lua_nn27">Typemaps and pointer-pointer functions</a>
|
||||
</ul>
|
||||
<li><a href="Lua.html#Lua_nn28">Writing typemaps</a>
|
||||
<ul>
|
||||
<li><a href="Lua.html#Lua_nn29">Typemaps you can write</a>
|
||||
<li><a href="Lua.html#Lua_nn30">SWIG's Lua-C API</a>
|
||||
</ul>
|
||||
<li><a href="Lua.html#Lua_nn31">Customization of your Bindings</a>
|
||||
<ul>
|
||||
<li><a href="Lua.html#Lua_nn32">Writing your own custom wrappers</a>
|
||||
<li><a href="Lua.html#Lua_nn33">Adding additional Lua code</a>
|
||||
</ul>
|
||||
<li><a href="Lua.html#Lua_nn34">Details on the Lua binding</a>
|
||||
<ul>
|
||||
<li><a href="Lua.html#Lua_nn35">Binding global data into the module.</a>
|
||||
<li><a href="Lua.html#Lua_nn36">Userdata and Metatables</a>
|
||||
<li><a href="Lua.html#Lua_nn37">Memory management</a>
|
||||
<li><a href="Lua.html#Lua_nn26">Binding global data into the module.</a>
|
||||
<li><a href="Lua.html#Lua_nn27">Userdata and Metatables</a>
|
||||
<li><a href="Lua.html#Lua_nn28">Memory management</a>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Modula3.html#Modula3">24 SWIG and Modula-3</a></h3>
|
||||
<h3><a href="Modula3.html#Modula3">23 SWIG and Modula-3</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -983,7 +935,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Mzscheme.html#Mzscheme">25 SWIG and MzScheme</a></h3>
|
||||
<h3><a href="Mzscheme.html#Mzscheme">24 SWIG and MzScheme</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -993,7 +945,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Ocaml.html#Ocaml">26 SWIG and Ocaml</a></h3>
|
||||
<h3><a href="Ocaml.html#Ocaml">25 SWIG and Ocaml</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -1044,7 +996,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Octave.html#Octave">27 SWIG and Octave</a></h3>
|
||||
<h3><a href="Octave.html#Octave">26 SWIG and Octave</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -1079,7 +1031,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Perl5.html#Perl5">28 SWIG and Perl5</a></h3>
|
||||
<h3><a href="Perl5.html#Perl5">27 SWIG and Perl5</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -1146,7 +1098,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Php.html#Php">29 SWIG and PHP</a></h3>
|
||||
<h3><a href="Php.html#Php">28 SWIG and PHP</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -1154,6 +1106,7 @@
|
|||
<li><a href="Php.html#Php_nn1">Generating PHP Extensions</a>
|
||||
<ul>
|
||||
<li><a href="Php.html#Php_nn1_1">Building a loadable extension</a>
|
||||
<li><a href="Php.html#Php_nn1_2">Building extensions into PHP</a>
|
||||
<li><a href="Php.html#Php_nn1_3">Using PHP Extensions</a>
|
||||
</ul>
|
||||
<li><a href="Php.html#Php_nn2">Basic PHP interface</a>
|
||||
|
|
@ -1176,7 +1129,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Pike.html#Pike">30 SWIG and Pike</a></h3>
|
||||
<h3><a href="Pike.html#Pike">29 SWIG and Pike</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -1200,7 +1153,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Python.html#Python">31 SWIG and Python</a></h3>
|
||||
<h3><a href="Python.html#Python">30 SWIG and Python</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -1241,7 +1194,7 @@
|
|||
<li><a href="Python.html#Python_nn30">Memory management</a>
|
||||
<li><a href="Python.html#Python_nn31">Python 2.2 and classic classes</a>
|
||||
</ul>
|
||||
<li><a href="Python.html#Python_directors">Cross language polymorphism</a>
|
||||
<li><a href="Python.html#directors">Cross language polymorphism</a>
|
||||
<ul>
|
||||
<li><a href="Python.html#Python_nn33">Enabling directors</a>
|
||||
<li><a href="Python.html#Python_nn34">Director classes</a>
|
||||
|
|
@ -1296,17 +1249,11 @@
|
|||
<li><a href="Python.html#Python_nn71">%feature("docstring")</a>
|
||||
</ul>
|
||||
<li><a href="Python.html#Python_nn72">Python Packages</a>
|
||||
<li><a href="Python.html#Python_python3support">Python 3 Support</a>
|
||||
<ul>
|
||||
<li><a href="Python.html#Python_nn74">Function annotation</a>
|
||||
<li><a href="Python.html#Python_nn75">Buffer interface</a>
|
||||
<li><a href="Python.html#Python_nn76">Abstract base classes</a>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Ruby.html#Ruby">32 SWIG and Ruby</a></h3>
|
||||
<h3><a href="Ruby.html#Ruby">31 SWIG and Ruby</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -1440,7 +1387,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Tcl.html#Tcl">33 SWIG and Tcl</a></h3>
|
||||
<h3><a href="Tcl.html#Tcl">32 SWIG and Tcl</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -1505,7 +1452,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="R.html#R">34 SWIG and R</a></h3>
|
||||
<h3><a href="R.html#R">33 SWIG and R</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
@ -1521,7 +1468,7 @@
|
|||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
<h3><a href="Extending.html#Extending">35 Extending SWIG to support new languages</a></h3>
|
||||
<h3><a href="Extending.html#Extending">34 Extending SWIG to support new languages</a></h3>
|
||||
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
|
|
|
|||
|
|
@ -1019,20 +1019,6 @@ but this will:
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
SWIG provides macros for disabling and clearing features. Many of these can be found in the <tt>swig.swg</tt> library file.
|
||||
The typical pattern is to define three macros; one to define the feature itself, one to disable the feature and one to clear the feature.
|
||||
The three macros below show this for the "except" feature:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
#define %exception %feature("except")
|
||||
#define %noexception %feature("except","0")
|
||||
#define %clearexception %feature("except","")
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Customization_features_default_args"></a>11.3.4 Features and default arguments</H3>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Extending"></a>35 Extending SWIG to support new languages</H1>
|
||||
<H1><a name="Extending"></a>34 Extending SWIG to support new languages</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -73,7 +73,7 @@
|
|||
|
||||
|
||||
|
||||
<H2><a name="Extending_nn2"></a>35.1 Introduction</H2>
|
||||
<H2><a name="Extending_nn2"></a>34.1 Introduction</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -89,7 +89,7 @@ Also, this chapter is not meant to be a hand-holding tutorial. As a starting po
|
|||
you should probably look at one of SWIG's existing modules.
|
||||
</p>
|
||||
|
||||
<H2><a name="Extending_nn3"></a>35.2 Prerequisites</H2>
|
||||
<H2><a name="Extending_nn3"></a>34.2 Prerequisites</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -119,7 +119,7 @@ obvious, but almost all SWIG directives as well as the low-level generation of
|
|||
wrapper code are driven by C++ datatypes.
|
||||
</p>
|
||||
|
||||
<H2><a name="Extending_nn4"></a>35.3 The Big Picture</H2>
|
||||
<H2><a name="Extending_nn4"></a>34.3 The Big Picture</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -156,7 +156,7 @@ role in making the system work. For example, both typemaps and declaration anno
|
|||
based on pattern matching and interact heavily with the underlying type system.
|
||||
</p>
|
||||
|
||||
<H2><a name="Extending_nn5"></a>35.4 Execution Model</H2>
|
||||
<H2><a name="Extending_nn5"></a>34.4 Execution Model</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -201,7 +201,7 @@ latter stage of compilation.
|
|||
The next few sections briefly describe some of these stages.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn6"></a>35.4.1 Preprocessing</H3>
|
||||
<H3><a name="Extending_nn6"></a>34.4.1 Preprocessing</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -232,11 +232,10 @@ of <tt>swig.swg</tt> looks like this:
|
|||
...
|
||||
/* Code insertion directives such as %wrapper %{ ... %} */
|
||||
|
||||
#define %begin %insert("begin")
|
||||
#define %runtime %insert("runtime")
|
||||
#define %header %insert("header")
|
||||
#define %wrapper %insert("wrapper")
|
||||
#define %init %insert("init")
|
||||
#define %wrapper %insert("wrapper")
|
||||
#define %header %insert("header")
|
||||
#define %runtime %insert("runtime")
|
||||
|
||||
/* Access control directives */
|
||||
|
||||
|
|
@ -282,7 +281,7 @@ been expanded as well as everything else that goes into the low-level
|
|||
construction of the wrapper code.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn7"></a>35.4.2 Parsing</H3>
|
||||
<H3><a name="Extending_nn7"></a>34.4.2 Parsing</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -383,7 +382,7 @@ returning a <tt>foo</tt> and taking types <tt>a</tt> and <tt>b</tt> as
|
|||
arguments).
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn8"></a>35.4.3 Parse Trees</H3>
|
||||
<H3><a name="Extending_nn8"></a>34.4.3 Parse Trees</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -449,8 +448,7 @@ of the output.
|
|||
<p>
|
||||
The contents of each parse tree node consist of a collection of attribute/value
|
||||
pairs. Internally, the nodes are simply represented by hash tables. A display of
|
||||
the entire parse-tree structure can be obtained using <tt>swig -debug-top <n></tt>, where <tt>n</tt> is
|
||||
the stage being processed.
|
||||
the entire parse-tree structure can be obtained using <tt>swig -dump_tree</tt>.
|
||||
There are a number of other parse tree display options, for example, <tt>swig -debug-module <n></tt> will
|
||||
avoid displaying system parse information and only display the parse tree pertaining to the user's module at
|
||||
stage <tt>n</tt> of processing.
|
||||
|
|
@ -638,7 +636,7 @@ $ swig -c++ -python -debug-module 4 example.i
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn9"></a>35.4.4 Attribute namespaces</H3>
|
||||
<H3><a name="Extending_nn9"></a>34.4.4 Attribute namespaces</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -657,7 +655,7 @@ that matches the name of the target language. For example, <tt>python:foo</tt>
|
|||
<tt>perl:foo</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn10"></a>35.4.5 Symbol Tables</H3>
|
||||
<H3><a name="Extending_nn10"></a>34.4.5 Symbol Tables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -748,7 +746,7 @@ example.i:5. Previous declaration is foo_i(int )
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn11"></a>35.4.6 The %feature directive</H3>
|
||||
<H3><a name="Extending_nn11"></a>34.4.6 The %feature directive</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -804,7 +802,7 @@ For example, the exception code above is simply
|
|||
stored without any modifications.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn12"></a>35.4.7 Code Generation</H3>
|
||||
<H3><a name="Extending_nn12"></a>34.4.7 Code Generation</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -926,7 +924,7 @@ public :
|
|||
The role of these functions is described shortly.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn13"></a>35.4.8 SWIG and XML</H3>
|
||||
<H3><a name="Extending_nn13"></a>34.4.8 SWIG and XML</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -939,7 +937,7 @@ internal data structures, it may be useful to keep XML in the back of
|
|||
your mind as a model.
|
||||
</p>
|
||||
|
||||
<H2><a name="Extending_nn14"></a>35.5 Primitive Data Structures</H2>
|
||||
<H2><a name="Extending_nn14"></a>34.5 Primitive Data Structures</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -985,7 +983,7 @@ typedef Hash Typetab;
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn15"></a>35.5.1 Strings</H3>
|
||||
<H3><a name="Extending_nn15"></a>34.5.1 Strings</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1126,7 +1124,7 @@ Returns the number of replacements made (if any).
|
|||
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn16"></a>35.5.2 Hashes</H3>
|
||||
<H3><a name="Extending_nn16"></a>34.5.2 Hashes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1203,7 +1201,7 @@ Returns the list of hash table keys.
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="Extending_nn17"></a>35.5.3 Lists</H3>
|
||||
<H3><a name="Extending_nn17"></a>34.5.3 Lists</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1292,7 +1290,7 @@ If <tt>t</tt> is not a standard object, it is assumed to be a <tt>char *</tt>
|
|||
and is used to create a String object.
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn18"></a>35.5.4 Common operations</H3>
|
||||
<H3><a name="Extending_nn18"></a>34.5.4 Common operations</H3>
|
||||
|
||||
|
||||
The following operations are applicable to all datatypes.
|
||||
|
|
@ -1347,7 +1345,7 @@ objects and report errors.
|
|||
Gets the line number associated with <tt>x</tt>.
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn19"></a>35.5.5 Iterating over Lists and Hashes</H3>
|
||||
<H3><a name="Extending_nn19"></a>34.5.5 Iterating over Lists and Hashes</H3>
|
||||
|
||||
|
||||
To iterate over the elements of a list or a hash table, the following functions are used:
|
||||
|
|
@ -1392,7 +1390,7 @@ for (j = First(j); j.item; j= Next(j)) {
|
|||
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn20"></a>35.5.6 I/O</H3>
|
||||
<H3><a name="Extending_nn20"></a>34.5.6 I/O</H3>
|
||||
|
||||
|
||||
Special I/O functions are used for all internal I/O. These operations
|
||||
|
|
@ -1528,7 +1526,7 @@ Similarly, the preprocessor and parser all operate on string-files.
|
|||
|
||||
</div>
|
||||
|
||||
<H2><a name="Extending_nn21"></a>35.6 Navigating and manipulating parse trees</H2>
|
||||
<H2><a name="Extending_nn21"></a>34.6 Navigating and manipulating parse trees</H2>
|
||||
|
||||
|
||||
Parse trees are built as collections of hash tables. Each node is a hash table in which
|
||||
|
|
@ -1662,7 +1660,7 @@ Deletes a node from the parse tree. Deletion reconnects siblings and properly u
|
|||
the parent so that sibling nodes are unaffected.
|
||||
</div>
|
||||
|
||||
<H2><a name="Extending_nn22"></a>35.7 Working with attributes</H2>
|
||||
<H2><a name="Extending_nn22"></a>34.7 Working with attributes</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1779,7 +1777,7 @@ the attribute is optional. <tt>Swig_restore()</tt> must always be called after
|
|||
function.
|
||||
</div>
|
||||
|
||||
<H2><a name="Extending_nn23"></a>35.8 Type system</H2>
|
||||
<H2><a name="Extending_nn23"></a>34.8 Type system</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1788,7 +1786,7 @@ pointers, references, and pointers to members. A detailed discussion of
|
|||
type theory is impossible here. However, let's cover the highlights.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn24"></a>35.8.1 String encoding of types</H3>
|
||||
<H3><a name="Extending_nn24"></a>34.8.1 String encoding of types</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1889,7 +1887,7 @@ make the final type, the two parts are just joined together using
|
|||
string concatenation.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn25"></a>35.8.2 Type construction</H3>
|
||||
<H3><a name="Extending_nn25"></a>34.8.2 Type construction</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2058,7 +2056,7 @@ Returns the prefix of a type. For example, if <tt>ty</tt> is
|
|||
<tt>ty</tt> is unmodified.
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn26"></a>35.8.3 Type tests</H3>
|
||||
<H3><a name="Extending_nn26"></a>34.8.3 Type tests</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2145,7 +2143,7 @@ Checks if <tt>ty</tt> is a varargs type.
|
|||
Checks if <tt>ty</tt> is a templatized type.
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn27"></a>35.8.4 Typedef and inheritance</H3>
|
||||
<H3><a name="Extending_nn27"></a>34.8.4 Typedef and inheritance</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2247,7 +2245,7 @@ Fully reduces <tt>ty</tt> according to typedef rules. Resulting datatype
|
|||
will consist only of primitive typenames.
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn28"></a>35.8.5 Lvalues</H3>
|
||||
<H3><a name="Extending_nn28"></a>34.8.5 Lvalues</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2284,7 +2282,7 @@ Literal y; // type = 'Literal', ltype='p.char'
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn29"></a>35.8.6 Output functions</H3>
|
||||
<H3><a name="Extending_nn29"></a>34.8.6 Output functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2346,7 +2344,7 @@ SWIG, but is most commonly associated with type-descriptor objects
|
|||
that appear in wrappers (e.g., <tt>SWIGTYPE_p_double</tt>).
|
||||
</div>
|
||||
|
||||
<H2><a name="Extending_nn30"></a>35.9 Parameters</H2>
|
||||
<H2><a name="Extending_nn30"></a>34.9 Parameters</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2445,7 +2443,7 @@ included. Used to emit prototypes.
|
|||
Returns the number of required (non-optional) arguments in <tt>p</tt>.
|
||||
</div>
|
||||
|
||||
<H2><a name="Extending_nn31"></a>35.10 Writing a Language Module</H2>
|
||||
<H2><a name="Extending_nn31"></a>34.10 Writing a Language Module</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2460,7 +2458,7 @@ describes the creation of a minimal Python module. You should be able to extra
|
|||
this to other languages.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn32"></a>35.10.1 Execution model</H3>
|
||||
<H3><a name="Extending_nn32"></a>34.10.1 Execution model</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2470,7 +2468,7 @@ the parsing of command line options, all aspects of code generation are controll
|
|||
different methods of the <tt>Language</tt> that must be defined by your module.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn33"></a>35.10.2 Starting out</H3>
|
||||
<H3><a name="Extending_nn33"></a>34.10.2 Starting out</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2578,7 +2576,7 @@ that activates your module. For example, <tt>swig -python foo.i</tt>. The
|
|||
messages from your new module should appear.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn34"></a>35.10.3 Command line options</H3>
|
||||
<H3><a name="Extending_nn34"></a>34.10.3 Command line options</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2637,7 +2635,7 @@ to mark the option as valid. If you forget to do this, SWIG will terminate wit
|
|||
unrecognized command line option error.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn35"></a>35.10.4 Configuration and preprocessing</H3>
|
||||
<H3><a name="Extending_nn35"></a>34.10.4 Configuration and preprocessing</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2686,7 +2684,7 @@ an implementation file <tt>python.cxx</tt> and a configuration file
|
|||
<tt>python.swg</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn36"></a>35.10.5 Entry point to code generation</H3>
|
||||
<H3><a name="Extending_nn36"></a>34.10.5 Entry point to code generation</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2744,7 +2742,7 @@ int Python::top(Node *n) {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn37"></a>35.10.6 Module I/O and wrapper skeleton</H3>
|
||||
<H3><a name="Extending_nn37"></a>34.10.6 Module I/O and wrapper skeleton</H3>
|
||||
|
||||
|
||||
<!-- please report bugs in this section to mgossage -->
|
||||
|
|
@ -2886,7 +2884,7 @@ functionWrapper : void Shape_y_set(Shape *self,double y)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Extending_nn38"></a>35.10.7 Low-level code generators</H3>
|
||||
<H3><a name="Extending_nn38"></a>34.10.7 Low-level code generators</H3>
|
||||
|
||||
|
||||
<!-- please report bugs in this section to mgossage -->
|
||||
|
|
@ -3040,7 +3038,7 @@ but without the typemaps, there is still work to do.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="Extending_nn39"></a>35.10.8 Configuration files</H3>
|
||||
<H3><a name="Extending_nn39"></a>34.10.8 Configuration files</H3>
|
||||
|
||||
|
||||
<!-- please report bugs in this section to ttn -->
|
||||
|
|
@ -3115,7 +3113,7 @@ entirely upcased.
|
|||
|
||||
<p>
|
||||
At the end of the new section is the place to put the aforementioned
|
||||
nickname kludges (should they be needed). See Perl5 for
|
||||
nickname kludges (should they be needed). See Perl5 and Php4 for
|
||||
examples of what to do. [If this is still unclear after you've read
|
||||
the code, ping me and I'll expand on this further. --ttn]
|
||||
</p>
|
||||
|
|
@ -3190,7 +3188,7 @@ politely displays the ignoring language message.
|
|||
</dl>
|
||||
|
||||
|
||||
<H3><a name="Extending_nn40"></a>35.10.9 Runtime support</H3>
|
||||
<H3><a name="Extending_nn40"></a>34.10.9 Runtime support</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3199,7 +3197,7 @@ Discuss the kinds of functions typically needed for SWIG runtime support (e.g.
|
|||
the SWIG files that implement those functions.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn41"></a>35.10.10 Standard library files</H3>
|
||||
<H3><a name="Extending_nn41"></a>34.10.10 Standard library files</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3218,7 +3216,7 @@ The following are the minimum that are usually supported:
|
|||
Please copy these and modify for any new language.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn42"></a>35.10.11 Examples and test cases</H3>
|
||||
<H3><a name="Extending_nn42"></a>34.10.11 Examples and test cases</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3247,7 +3245,7 @@ during this process, see the section on <a href="#n37a">configuration
|
|||
files</a>.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_nn43"></a>35.10.12 Documentation</H3>
|
||||
<H3><a name="Extending_nn43"></a>34.10.12 Documentation</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3279,7 +3277,7 @@ Some topics that you'll want to be sure to address include:
|
|||
if available.
|
||||
</ul>
|
||||
|
||||
<H3><a name="Extending_prerequisites"></a>35.10.13 Prerequisites for adding a new language module to the SWIG distribution</H3>
|
||||
<H3><a name="Extending_prerequisites"></a>34.10.13 Prerequisites for adding a new language module to the SWIG distribution</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3336,7 +3334,7 @@ should be added should there be an area not already covered by
|
|||
the existing tests.
|
||||
</p>
|
||||
|
||||
<H3><a name="Extending_coding_style_guidelines"></a>35.10.14 Coding style guidelines</H3>
|
||||
<H3><a name="Extending_coding_style_guidelines"></a>34.10.14 Coding style guidelines</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3360,13 +3358,13 @@ The generated C/C++ code should also follow this style as close as possible. How
|
|||
should be avoided as unlike the SWIG developers, users will never have consistent tab settings.
|
||||
</p>
|
||||
|
||||
<H2><a name="Extending_nn44"></a>35.11 Typemaps</H2>
|
||||
<H2><a name="Extending_nn44"></a>34.11 Typemaps</H2>
|
||||
|
||||
|
||||
<H3><a name="Extending_nn45"></a>35.11.1 Proxy classes</H3>
|
||||
<H3><a name="Extending_nn45"></a>34.11.1 Proxy classes</H3>
|
||||
|
||||
|
||||
<H2><a name="Extending_nn46"></a>35.12 Guide to parse tree nodes</H2>
|
||||
<H2><a name="Extending_nn46"></a>34.12 Guide to parse tree nodes</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<H1><a name="Guile"></a>20 SWIG and Guile</H1>
|
||||
<H1><a name="Guile"></a>19 SWIG and Guile</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
<p>
|
||||
This section details guile-specific support in SWIG.
|
||||
|
||||
<H2><a name="Guile_nn2"></a>20.1 Meaning of "Module"</H2>
|
||||
<H2><a name="Guile_nn2"></a>19.1 Meaning of "Module"</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -55,7 +55,7 @@ There are three different concepts of "module" involved, defined
|
|||
separately for SWIG, Guile, and Libtool. To avoid horrible confusion,
|
||||
we explicitly prefix the context, e.g., "guile-module".
|
||||
|
||||
<H2><a name="Guile_nn3"></a>20.2 Using the SCM or GH Guile API</H2>
|
||||
<H2><a name="Guile_nn3"></a>19.2 Using the SCM or GH Guile API</H2>
|
||||
|
||||
|
||||
<p>The guile module can currently export wrapper files that use the guile GH interface or the
|
||||
|
|
@ -103,7 +103,7 @@ for the specific API. Currently only the guile language module has created a ma
|
|||
but there is no reason other languages (like mzscheme or chicken) couldn't also use this.
|
||||
If that happens, there is A LOT less code duplication in the standard typemaps.</p>
|
||||
|
||||
<H2><a name="Guile_nn4"></a>20.3 Linkage</H2>
|
||||
<H2><a name="Guile_nn4"></a>19.3 Linkage</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -111,7 +111,7 @@ Guile support is complicated by a lack of user community cohesiveness,
|
|||
which manifests in multiple shared-library usage conventions. A set of
|
||||
policies implementing a usage convention is called a <b>linkage</b>.
|
||||
|
||||
<H3><a name="Guile_nn5"></a>20.3.1 Simple Linkage</H3>
|
||||
<H3><a name="Guile_nn5"></a>19.3.1 Simple Linkage</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -206,7 +206,7 @@ placed between the <code>define-module</code> form and the
|
|||
<code>SWIG_init</code> via a preprocessor define to avoid symbol
|
||||
clashes. For this case, however, passive linkage is available.
|
||||
|
||||
<H3><a name="Guile_nn6"></a>20.3.2 Passive Linkage</H3>
|
||||
<H3><a name="Guile_nn6"></a>19.3.2 Passive Linkage</H3>
|
||||
|
||||
|
||||
<p>Passive linkage is just like simple linkage, but it generates an
|
||||
|
|
@ -216,7 +216,7 @@ package name (see below).
|
|||
<p>You should use passive linkage rather than simple linkage when you
|
||||
are using multiple modules.
|
||||
|
||||
<H3><a name="Guile_nn7"></a>20.3.3 Native Guile Module Linkage</H3>
|
||||
<H3><a name="Guile_nn7"></a>19.3.3 Native Guile Module Linkage</H3>
|
||||
|
||||
|
||||
<p>SWIG can also generate wrapper code that does all the Guile module
|
||||
|
|
@ -257,7 +257,7 @@ Newer Guile versions have a shorthand procedure for this:
|
|||
</div>
|
||||
</ul>
|
||||
|
||||
<H3><a name="Guile_nn8"></a>20.3.4 Old Auto-Loading Guile Module Linkage</H3>
|
||||
<H3><a name="Guile_nn8"></a>19.3.4 Old Auto-Loading Guile Module Linkage</H3>
|
||||
|
||||
|
||||
<p>Guile used to support an autoloading facility for object-code
|
||||
|
|
@ -283,7 +283,7 @@ option, SWIG generates an exported module initialization function with
|
|||
an appropriate name.
|
||||
|
||||
|
||||
<H3><a name="Guile_nn9"></a>20.3.5 Hobbit4D Linkage</H3>
|
||||
<H3><a name="Guile_nn9"></a>19.3.5 Hobbit4D Linkage</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -308,7 +308,7 @@ my/lib/libfoo.so.X.Y.Z and friends. This scheme is still very
|
|||
experimental; the (hobbit4d link) conventions are not well understood.
|
||||
</p>
|
||||
|
||||
<H2><a name="Guile_nn10"></a>20.4 Underscore Folding</H2>
|
||||
<H2><a name="Guile_nn10"></a>19.4 Underscore Folding</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -320,7 +320,7 @@ complained so far.
|
|||
<code>%rename</code> to specify the Guile name of the wrapped
|
||||
functions and variables (see CHANGES).
|
||||
|
||||
<H2><a name="Guile_nn11"></a>20.5 Typemaps</H2>
|
||||
<H2><a name="Guile_nn11"></a>19.5 Typemaps</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -412,7 +412,7 @@ constant will appear as a scheme variable. See
|
|||
<a href="Customization.html#features">Features and the %feature directive</a>
|
||||
for info on how to apply the %feature.</p>
|
||||
|
||||
<H2><a name="Guile_nn12"></a>20.6 Representation of pointers as smobs</H2>
|
||||
<H2><a name="Guile_nn12"></a>19.6 Representation of pointers as smobs</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -433,7 +433,7 @@ representing the expected pointer type. See also
|
|||
If the Scheme object passed was not a SWIG smob representing a compatible
|
||||
pointer, a <code>wrong-type-arg</code> exception is raised.
|
||||
|
||||
<H3><a name="Guile_nn13"></a>20.6.1 GH Smobs</H3>
|
||||
<H3><a name="Guile_nn13"></a>19.6.1 GH Smobs</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -462,7 +462,7 @@ that created them, so the first module we check will most likely be correct.
|
|||
Once we have a swig_type_info structure, we loop through the linked list of
|
||||
casts, using pointer comparisons.</p>
|
||||
|
||||
<H3><a name="Guile_nn14"></a>20.6.2 SCM Smobs</H3>
|
||||
<H3><a name="Guile_nn14"></a>19.6.2 SCM Smobs</H3>
|
||||
|
||||
|
||||
<p>The SCM interface (using the "-scm" argument to swig) uses swigrun.swg.
|
||||
|
|
@ -477,7 +477,7 @@ in the smob tag. If a generated GOOPS module has been loaded, smobs will be wra
|
|||
GOOPS class.</p>
|
||||
|
||||
|
||||
<H3><a name="Guile_nn15"></a>20.6.3 Garbage Collection</H3>
|
||||
<H3><a name="Guile_nn15"></a>19.6.3 Garbage Collection</H3>
|
||||
|
||||
|
||||
<p>Garbage collection is a feature of the new SCM interface, and it is automatically included
|
||||
|
|
@ -491,7 +491,7 @@ is exactly like described in <a href="Customization.html#ownership">
|
|||
Object ownership and %newobject</a> in the SWIG manual. All typemaps use an $owner var, and
|
||||
the guile module replaces $owner with 0 or 1 depending on feature:new.</p>
|
||||
|
||||
<H2><a name="Guile_nn16"></a>20.7 Exception Handling</H2>
|
||||
<H2><a name="Guile_nn16"></a>19.7 Exception Handling</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -517,7 +517,7 @@ mapping:
|
|||
The default when not specified here is to use "swig-error".
|
||||
See Lib/exception.i for details.
|
||||
|
||||
<H2><a name="Guile_nn17"></a>20.8 Procedure documentation</H2>
|
||||
<H2><a name="Guile_nn17"></a>19.8 Procedure documentation</H2>
|
||||
|
||||
|
||||
<p>If invoked with the command-line option <code>-procdoc
|
||||
|
|
@ -553,7 +553,7 @@ like this:
|
|||
typemap argument <code>doc</code>. See <code>Lib/guile/typemaps.i</code> for
|
||||
details.
|
||||
|
||||
<H2><a name="Guile_nn18"></a>20.9 Procedures with setters</H2>
|
||||
<H2><a name="Guile_nn18"></a>19.9 Procedures with setters</H2>
|
||||
|
||||
|
||||
<p>For global variables, SWIG creates a single wrapper procedure
|
||||
|
|
@ -581,7 +581,7 @@ struct members, the procedures <code>(<var>struct</var>-<var>member</var>-get
|
|||
pointer)</code> and <code>(<var>struct-member</var>-set pointer
|
||||
value)</code> are <em>not</em> generated.
|
||||
|
||||
<H2><a name="Guile_nn19"></a>20.10 GOOPS Proxy Classes</H2>
|
||||
<H2><a name="Guile_nn19"></a>19.10 GOOPS Proxy Classes</H2>
|
||||
|
||||
|
||||
<p>SWIG can also generate classes and generic functions for use with
|
||||
|
|
@ -730,7 +730,7 @@ Notice that <Foo> is used before it is defined. The fix is to just put th
|
|||
<code>%import "foo.h"</code> before the <code>%inline</code> block.
|
||||
</p>
|
||||
|
||||
<H3><a name="Guile_nn20"></a>20.10.1 Naming Issues</H3>
|
||||
<H3><a name="Guile_nn20"></a>19.10.1 Naming Issues</H3>
|
||||
|
||||
|
||||
<p>As you can see in the example above, there are potential naming conflicts. The default exported
|
||||
|
|
@ -769,7 +769,7 @@ guile-modules. For example,</p>
|
|||
|
||||
<p>TODO: Renaming class name prefixes?</p>
|
||||
|
||||
<H3><a name="Guile_nn21"></a>20.10.2 Linking</H3>
|
||||
<H3><a name="Guile_nn21"></a>19.10.2 Linking</H3>
|
||||
|
||||
|
||||
<p>The guile-modules generated above all need to be linked together. GOOPS support requires
|
||||
|
|
|
|||
|
|
@ -414,8 +414,7 @@ SWIG_LINK_LIBRARIES(example ${PYTHON_LIBRARIES})
|
|||
</pre></div>
|
||||
<p>
|
||||
The above example will generate native build files such as makefiles, nmake files and Visual Studio projects
|
||||
which will invoke SWIG and compile the generated C++ files into _example.so (UNIX) or _example.pyd (Windows).
|
||||
For other target languages on Windows a dll, instead of a .pyd file, is usually generated.
|
||||
which will invoke SWIG and compile the generated C++ files into _example.so (UNIX) or _example.dll (Windows).
|
||||
</p>
|
||||
|
||||
<H2><a name="Introduction_nn12"></a>2.7 Hands off code generation</H2>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<H1><a name="Java"></a>21 SWIG and Java</H1>
|
||||
<H1><a name="Java"></a>20 SWIG and Java</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -154,7 +154,7 @@ It covers most SWIG features, but certain low-level details are covered in less
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="java_overview"></a>21.1 Overview</H2>
|
||||
<H2><a name="java_overview"></a>20.1 Overview</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -189,7 +189,7 @@ Various customisation tips and techniques using SWIG directives are covered.
|
|||
The latter sections cover the advanced techniques of using typemaps for complete control of the wrapping process.
|
||||
</p>
|
||||
|
||||
<H2><a name="java_preliminaries"></a>21.2 Preliminaries</H2>
|
||||
<H2><a name="java_preliminaries"></a>20.2 Preliminaries</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -205,7 +205,7 @@ Run <tt>make -k check</tt> from the SWIG root directory after installing SWIG on
|
|||
The Java module requires your system to support shared libraries and dynamic loading.
|
||||
This is the commonly used method to load JNI code so your system will more than likely support this.</p>
|
||||
|
||||
<H3><a name="running_swig"></a>21.2.1 Running SWIG</H3>
|
||||
<H3><a name="running_swig"></a>20.2.1 Running SWIG</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -258,7 +258,7 @@ The following sections have further practical examples and details on how you mi
|
|||
compiling and using the generated files.
|
||||
</p>
|
||||
|
||||
<H3><a name="java_commandline"></a>21.2.2 Additional Commandline Options</H3>
|
||||
<H3><a name="java_commandline"></a>20.2.2 Additional Commandline Options</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -295,7 +295,7 @@ swig -java -help
|
|||
Their use will become clearer by the time you have finished reading this section on SWIG and Java.
|
||||
</p>
|
||||
|
||||
<H3><a name="getting_right_headers"></a>21.2.3 Getting the right header files</H3>
|
||||
<H3><a name="getting_right_headers"></a>20.2.3 Getting the right header files</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -310,7 +310,7 @@ They are usually in directories like this:</p>
|
|||
<p>
|
||||
The exact location may vary on your machine, but the above locations are typical. </p>
|
||||
|
||||
<H3><a name="compiling_dynamic"></a>21.2.4 Compiling a dynamic module</H3>
|
||||
<H3><a name="compiling_dynamic"></a>20.2.4 Compiling a dynamic module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -346,16 +346,16 @@ The name of the shared library output file is important.
|
|||
If the name of your SWIG module is "<tt>example</tt>", the name of the corresponding shared library file should be "<tt>libexample.so</tt>" (or equivalent depending on your machine, see <a href="#dynamic_linking_problems">Dynamic linking problems</a> for more information).
|
||||
The name of the module is specified using the <tt>%module</tt> directive or<tt> -module</tt> command line option.</p>
|
||||
|
||||
<H3><a name="using_module"></a>21.2.5 Using your module</H3>
|
||||
<H3><a name="using_module"></a>20.2.5 Using your module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
To load your shared native library module in Java, simply use Java's <tt>System.loadLibrary</tt> method in a Java class:</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
// runme.java
|
||||
// main.java
|
||||
|
||||
public class runme {
|
||||
public class main {
|
||||
static {
|
||||
System.loadLibrary("example");
|
||||
}
|
||||
|
|
@ -372,7 +372,7 @@ Compile all the Java files and run:
|
|||
|
||||
<div class="code"><pre>
|
||||
$ javac *.java
|
||||
$ java runme
|
||||
$ java main
|
||||
24
|
||||
$
|
||||
</pre></div>
|
||||
|
|
@ -381,7 +381,7 @@ $
|
|||
If it doesn't work have a look at the following section which discusses problems loading the shared library.
|
||||
</p>
|
||||
|
||||
<H3><a name="dynamic_linking_problems"></a>21.2.6 Dynamic linking problems</H3>
|
||||
<H3><a name="dynamic_linking_problems"></a>20.2.6 Dynamic linking problems</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -394,12 +394,12 @@ You may get an exception similar to this:
|
|||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
$ java runme
|
||||
$ java main
|
||||
Exception in thread "main" java.lang.UnsatisfiedLinkError: no example in java.library.path
|
||||
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1312)
|
||||
at java.lang.Runtime.loadLibrary0(Runtime.java:749)
|
||||
at java.lang.System.loadLibrary(System.java:820)
|
||||
at runme.<clinit>(runme.java:5)
|
||||
at main.<clinit>(main.java:5)
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -426,7 +426,7 @@ The following exception is indicative of this:
|
|||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
$ java runme
|
||||
$ java main
|
||||
Exception in thread "main" java.lang.UnsatisfiedLinkError: libexample.so: undefined
|
||||
symbol: fact
|
||||
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
|
||||
|
|
@ -434,7 +434,7 @@ symbol: fact
|
|||
at java.lang.ClassLoader.loadLibrary(ClassLoader.java, Compiled Code)
|
||||
at java.lang.Runtime.loadLibrary0(Runtime.java, Compiled Code)
|
||||
at java.lang.System.loadLibrary(System.java, Compiled Code)
|
||||
at runme.<clinit>(runme.java:5)
|
||||
at main.<clinit>(main.java:5)
|
||||
$
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -455,7 +455,7 @@ The following section also contains some C++ specific linking problems and solut
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="compilation_problems_cpp"></a>21.2.7 Compilation problems and compiling with C++</H3>
|
||||
<H3><a name="compilation_problems_cpp"></a>20.2.7 Compilation problems and compiling with C++</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -508,7 +508,7 @@ Finally make sure the version of JDK header files matches the version of Java th
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="building_windows"></a>21.2.8 Building on Windows</H3>
|
||||
<H3><a name="building_windows"></a>20.2.8 Building on Windows</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -517,7 +517,7 @@ You will want to produce a DLL that can be loaded by the Java Virtual Machine.
|
|||
This section covers the process of using SWIG with Microsoft Visual C++ 6 although the procedure may be similar with other compilers.
|
||||
In order for everything to work, you will need to have a JDK installed on your machine in order to read the JNI header files.</p>
|
||||
|
||||
<H4><a name="visual_studio"></a>21.2.8.1 Running SWIG from Visual Studio</H4>
|
||||
<H4><a name="visual_studio"></a>20.2.8.1 Running SWIG from Visual Studio</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -556,7 +556,7 @@ To run the native code in the DLL (example.dll), make sure that it is in your pa
|
|||
If the library fails to load have a look at <a href="#dynamic_linking_problems">Dynamic linking problems</a>.
|
||||
</p>
|
||||
|
||||
<H4><a name="nmake"></a>21.2.8.2 Using NMAKE</H4>
|
||||
<H4><a name="nmake"></a>20.2.8.2 Using NMAKE</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -615,7 +615,7 @@ Of course you may want to make changes for it to work for C++ by adding in the -
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="java_basic_tour"></a>21.3 A tour of basic C/C++ wrapping</H2>
|
||||
<H2><a name="java_basic_tour"></a>20.3 A tour of basic C/C++ wrapping</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -625,7 +625,7 @@ variables are wrapped with JavaBean type getters and setters and so forth.
|
|||
This section briefly covers the essential aspects of this wrapping.
|
||||
</p>
|
||||
|
||||
<H3><a name="module_packages_classes"></a>21.3.1 Modules, packages and generated Java classes</H3>
|
||||
<H3><a name="module_packages_classes"></a>20.3.1 Modules, packages and generated Java classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -659,7 +659,7 @@ swig -java -package com.bloggs.swig -outdir com/bloggs/swig example.i
|
|||
|
||||
SWIG won't create the directory, so make sure it exists beforehand.
|
||||
|
||||
<H3><a name="functions"></a>21.3.2 Functions</H3>
|
||||
<H3><a name="functions"></a>20.3.2 Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -693,7 +693,7 @@ System.out.println(example.fact(4));
|
|||
</pre></div>
|
||||
|
||||
|
||||
<H3><a name="global_variables"></a>21.3.3 Global variables</H3>
|
||||
<H3><a name="global_variables"></a>20.3.3 Global variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -780,7 +780,7 @@ extern char *path; // Read-only (due to %immutable)
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="constants"></a>21.3.4 Constants</H3>
|
||||
<H3><a name="constants"></a>20.3.4 Constants</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -920,7 +920,7 @@ Or if you decide this practice isn't so bad and your own class implements <tt>ex
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="enumerations"></a>21.3.5 Enumerations</H3>
|
||||
<H3><a name="enumerations"></a>20.3.5 Enumerations</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -934,7 +934,7 @@ The final two approaches use simple integers for each enum item.
|
|||
Before looking at the various approaches for wrapping named C/C++ enums, anonymous enums are considered.
|
||||
</p>
|
||||
|
||||
<H4><a name="anonymous_enums"></a>21.3.5.1 Anonymous enums</H4>
|
||||
<H4><a name="anonymous_enums"></a>20.3.5.1 Anonymous enums</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -997,7 +997,7 @@ As in the case of constants, you can access them through either the module class
|
|||
</p>
|
||||
|
||||
|
||||
<H4><a name="typesafe_enums"></a>21.3.5.2 Typesafe enums</H4>
|
||||
<H4><a name="typesafe_enums"></a>20.3.5.2 Typesafe enums</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1090,7 +1090,7 @@ When upgrading to JDK 1.5 or later, proper Java enums could be used instead, wit
|
|||
The following section details proper Java enum generation.
|
||||
</p>
|
||||
|
||||
<H4><a name="proper_enums"></a>21.3.5.3 Proper Java enums</H4>
|
||||
<H4><a name="proper_enums"></a>20.3.5.3 Proper Java enums</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1143,7 +1143,7 @@ The additional support methods need not be generated if none of the enum items h
|
|||
<a href="#simpler_enum_classes">Simpler Java enums for enums without initializers</a> section.
|
||||
</p>
|
||||
|
||||
<H4><a name="typeunsafe_enums"></a>21.3.5.4 Type unsafe enums</H4>
|
||||
<H4><a name="typeunsafe_enums"></a>20.3.5.4 Type unsafe enums</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1191,7 +1191,7 @@ Note that unlike typesafe enums, this approach requires users to mostly use diff
|
|||
Thus the upgrade path to proper enums provided in JDK 1.5 is more painful.
|
||||
</p>
|
||||
|
||||
<H4><a name="simple_enums"></a>21.3.5.5 Simple enums</H4>
|
||||
<H4><a name="simple_enums"></a>20.3.5.5 Simple enums</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1210,7 +1210,7 @@ SWIG-1.3.21 and earlier versions wrapped all enums using this approach.
|
|||
The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.
|
||||
</p>
|
||||
|
||||
<H3><a name="pointers"></a>21.3.6 Pointers</H3>
|
||||
<H3><a name="pointers"></a>20.3.6 Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1298,7 +1298,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return
|
|||
a NULL pointer if the conversion can't be performed.
|
||||
</p>
|
||||
|
||||
<H3><a name="structures"></a>21.3.7 Structures</H3>
|
||||
<H3><a name="structures"></a>20.3.7 Structures</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1466,7 +1466,7 @@ x.setA(3); // Modify x.a - this is the same as b.f.a
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="classes"></a>21.3.8 C++ classes</H3>
|
||||
<H3><a name="classes"></a>20.3.8 C++ classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1529,7 +1529,7 @@ int bar = Spam.getBar();
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="inheritance"></a>21.3.9 C++ inheritance</H3>
|
||||
<H3><a name="inheritance"></a>20.3.9 C++ inheritance</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1590,7 +1590,7 @@ Note that Java does not support multiple inheritance so any multiple inheritance
|
|||
A warning is given when multiple inheritance is detected and only the first base class is used.
|
||||
</p>
|
||||
|
||||
<H3><a name="pointers_refs_arrays"></a>21.3.10 Pointers, references, arrays and pass by value</H3>
|
||||
<H3><a name="pointers_refs_arrays"></a>20.3.10 Pointers, references, arrays and pass by value</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1645,7 +1645,7 @@ to hold the result and a pointer is returned (Java will release this memory
|
|||
when the returned object's finalizer is run by the garbage collector).
|
||||
</p>
|
||||
|
||||
<H4><a name="null_pointers"></a>21.3.10.1 Null pointers</H4>
|
||||
<H4><a name="null_pointers"></a>20.3.10.1 Null pointers</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1669,7 +1669,7 @@ For <tt>spam1</tt> and <tt>spam4</tt> above the Java <tt>null</tt> gets translat
|
|||
The converse also occurs, that is, NULL pointers are translated into <tt>null</tt> Java objects when returned from a C/C++ function.
|
||||
</p>
|
||||
|
||||
<H3><a name="overloaded_functions"></a>21.3.11 C++ overloaded functions</H3>
|
||||
<H3><a name="overloaded_functions"></a>20.3.11 C++ overloaded functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1784,7 +1784,7 @@ void spam(unsigned short); // Ignored
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="java_default_arguments"></a>21.3.12 C++ default arguments</H3>
|
||||
<H3><a name="java_default_arguments"></a>20.3.12 C++ default arguments</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1827,7 +1827,7 @@ Further details on default arguments and how to restore this approach are given
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="namespaces"></a>21.3.13 C++ namespaces</H3>
|
||||
<H3><a name="namespaces"></a>20.3.13 C++ namespaces</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1887,7 +1887,7 @@ symbols separate, consider wrapping them as separate SWIG modules.
|
|||
Each SWIG module can be placed into a separate package.
|
||||
</p>
|
||||
|
||||
<H3><a name="templates"></a>21.3.14 C++ templates</H3>
|
||||
<H3><a name="templates"></a>20.3.14 C++ templates</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1936,7 +1936,7 @@ Obviously, there is more to template wrapping than shown in this example.
|
|||
More details can be found in the <a href="SWIGPlus.html#SWIGPlus">SWIG and C++</a> chapter.
|
||||
</p>
|
||||
|
||||
<H3><a name="smart_pointers"></a>21.3.15 C++ Smart Pointers</H3>
|
||||
<H3><a name="smart_pointers"></a>20.3.15 C++ Smart Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2020,7 +2020,7 @@ Foo f = p.__deref__(); // Returns underlying Foo *
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="further_details"></a>21.4 Further details on the generated Java classes</H2>
|
||||
<H2><a name="further_details"></a>20.4 Further details on the generated Java classes</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2035,7 +2035,7 @@ Finally enum classes are covered.
|
|||
First, the crucial intermediary JNI class is considered.
|
||||
</p>
|
||||
|
||||
<H3><a name="imclass"></a>21.4.1 The intermediary JNI class</H3>
|
||||
<H3><a name="imclass"></a>20.4.1 The intermediary JNI class</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2155,7 +2155,7 @@ If <tt>name</tt> is the same as <tt>modulename</tt> then the module class name g
|
|||
from <tt>modulename</tt> to <tt>modulenameModule</tt>.
|
||||
</p>
|
||||
|
||||
<H4><a name="imclass_pragmas"></a>21.4.1.1 The intermediary JNI class pragmas</H4>
|
||||
<H4><a name="imclass_pragmas"></a>20.4.1.1 The intermediary JNI class pragmas</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2234,7 +2234,7 @@ For example, let's change the intermediary JNI class access to public.
|
|||
All the methods in the intermediary JNI class will then be callable outside of the package as the method modifiers are public by default.
|
||||
</p>
|
||||
|
||||
<H3><a name="java_module_class"></a>21.4.2 The Java module class</H3>
|
||||
<H3><a name="java_module_class"></a>20.4.2 The Java module class</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2265,7 +2265,7 @@ example.egg(new Foo());
|
|||
The primary reason for having the module class wrapping the calls in the intermediary JNI class is to implement static type checking. In this case only a <tt>Foo</tt> can be passed to the <tt>egg</tt> function, whereas any <tt>long</tt> can be passed to the <tt>egg</tt> function in the intermediary JNI class.
|
||||
</p>
|
||||
|
||||
<H4><a name="module_class_pragmas"></a>21.4.2.1 The Java module class pragmas</H4>
|
||||
<H4><a name="module_class_pragmas"></a>20.4.2.1 The Java module class pragmas</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2316,7 +2316,7 @@ See <a href="#imclass_pragmas">The intermediary JNI class pragmas</a> section fo
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="java_proxy_classes"></a>21.4.3 Java proxy classes</H3>
|
||||
<H3><a name="java_proxy_classes"></a>20.4.3 Java proxy classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2392,7 +2392,7 @@ int y = f.spam(5, new Foo());
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="memory_management"></a>21.4.3.1 Memory management</H4>
|
||||
<H4><a name="memory_management"></a>20.4.3.1 Memory management</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2554,7 +2554,7 @@ and
|
|||
</p>
|
||||
|
||||
|
||||
<H4><a name="inheritance_mirroring"></a>21.4.3.2 Inheritance</H4>
|
||||
<H4><a name="inheritance_mirroring"></a>20.4.3.2 Inheritance</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2670,7 +2670,7 @@ However, true cross language polymorphism can be achieved using the <a href="#ja
|
|||
</p>
|
||||
|
||||
|
||||
<H4><a name="proxy_classes_gc"></a>21.4.3.3 Proxy classes and garbage collection</H4>
|
||||
<H4><a name="proxy_classes_gc"></a>20.4.3.3 Proxy classes and garbage collection</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2753,7 +2753,7 @@ The section on <a href="#java_typemaps">Java typemaps</a> details how to specify
|
|||
See the <a href="http://www.devx.com/Java/Article/30192">How to Handle Java Finalization's Memory-Retention Issues</a> article for alternative approaches to managing memory by avoiding finalizers altogether.
|
||||
</p>
|
||||
|
||||
<H4><a name="java_pgcpp"></a>21.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling</H4>
|
||||
<H4><a name="java_pgcpp"></a>20.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2857,11 +2857,7 @@ and therefore there is no possibility of premature garbage collection. In practi
|
|||
|
||||
<p>
|
||||
The premature garbage collection prevention parameter for proxy classes is generated by default whenever proxy classes are passed by value, reference or with a pointer.
|
||||
The implementation for this extra parameter generation requires the "jtype" typemap to contain <tt>long</tt> and the "jstype" typemap to contain the name of a proxy class.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The additional parameter does impose a slight performance overhead and the parameter generation can be suppressed globally with the <tt>-nopgcpp</tt> commandline option.
|
||||
The additional parameters do impose a slight performance overhead and the parameter generation can be suppressed globally with the <tt>-nopgcpp</tt> commandline option.
|
||||
More selective suppression is possible with the 'nopgcpp' attribute in the "jtype" <a href="#java_typemaps">Java typemap</a>.
|
||||
The attribute is a flag and so should be set to "1" to enable the suppression, or it can be omitted or set to "0" to disable.
|
||||
For example:
|
||||
|
|
@ -2875,7 +2871,7 @@ For example:
|
|||
<b>Compatibility note:</b> The generation of this additional parameter did not occur in versions prior to SWIG-1.3.30.
|
||||
</p>
|
||||
|
||||
<H4><a name="java_multithread_libraries"></a>21.4.3.5 Single threaded applications and thread safety</H4>
|
||||
<H4><a name="java_multithread_libraries"></a>20.4.3.5 Single threaded applications and thread safety</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2963,7 +2959,7 @@ for (int i=0; i<100000; i++) {
|
|||
</pre></div>
|
||||
|
||||
|
||||
<H3><a name="type_wrapper_classes"></a>21.4.4 Type wrapper classes</H3>
|
||||
<H3><a name="type_wrapper_classes"></a>20.4.4 Type wrapper classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3050,7 +3046,7 @@ public static void spam(SWIGTYPE_p_int x, SWIGTYPE_p_int y, int z) { ... }
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="enum_classes"></a>21.4.5 Enum classes</H3>
|
||||
<H3><a name="enum_classes"></a>20.4.5 Enum classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3059,7 +3055,7 @@ The <a href="#enumerations">Enumerations</a> section discussed these but omitted
|
|||
The following sub-sections detail the various types of enum classes that can be generated.
|
||||
</p>
|
||||
|
||||
<H4><a name="typesafe_enums_classes"></a>21.4.5.1 Typesafe enum classes</H4>
|
||||
<H4><a name="typesafe_enums_classes"></a>20.4.5.1 Typesafe enum classes</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3143,7 +3139,7 @@ The <tt>swigValue</tt> method is used for marshalling in the other direction.
|
|||
The <tt>toString</tt> method is overridden so that the enum name is available.
|
||||
</p>
|
||||
|
||||
<H4><a name="proper_enums_classes"></a>21.4.5.2 Proper Java enum classes</H4>
|
||||
<H4><a name="proper_enums_classes"></a>20.4.5.2 Proper Java enum classes</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3221,7 +3217,7 @@ These needn't be generated if the enum being wrapped does not have any initializ
|
|||
<a href="#simpler_enum_classes">Simpler Java enums for enums without initializers</a> section describes how typemaps can be used to achieve this.
|
||||
</p>
|
||||
|
||||
<H4><a name="typeunsafe_enums_classes"></a>21.4.5.3 Type unsafe enum classes</H4>
|
||||
<H4><a name="typeunsafe_enums_classes"></a>20.4.5.3 Type unsafe enum classes</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3252,7 +3248,7 @@ public final class Beverage {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="java_directors"></a>21.5 Cross language polymorphism using directors</H2>
|
||||
<H2><a name="java_directors"></a>20.5 Cross language polymorphism using directors</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3274,7 +3270,7 @@ The upshot is that C++ classes can be extended in Java and from C++ these extens
|
|||
Neither C++ code nor Java code needs to know where a particular method is implemented: the combination of proxy classes, director classes, and C wrapper functions transparently takes care of all the cross-language method routing.
|
||||
</p>
|
||||
|
||||
<H3><a name="java_enabling_directors"></a>21.5.1 Enabling directors</H3>
|
||||
<H3><a name="java_enabling_directors"></a>20.5.1 Enabling directors</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3345,7 +3341,7 @@ public:
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="java_directors_classes"></a>21.5.2 Director classes</H3>
|
||||
<H3><a name="java_directors_classes"></a>20.5.2 Director classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3372,7 +3368,7 @@ If the correct implementation is in Java, the Java API is used to call the metho
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="java_directors_overhead"></a>21.5.3 Overhead and code bloat</H3>
|
||||
<H3><a name="java_directors_overhead"></a>20.5.3 Overhead and code bloat</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3390,7 +3386,7 @@ This situation can be optimized by selectively enabling director methods (using
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="java_directors_example"></a>21.5.4 Simple directors example</H3>
|
||||
<H3><a name="java_directors_example"></a>20.5.4 Simple directors example</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3455,7 +3451,7 @@ DirectorDerived::upcall_method() invoked.
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="java_directors_threading"></a>21.5.5 Director threading issues</H3>
|
||||
<H3><a name="java_directors_threading"></a>20.5.5 Director threading issues</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3475,7 +3471,7 @@ Macros can be defined on the commandline when compiling your C++ code, or altern
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="java_allprotected"></a>21.6 Accessing protected members</H2>
|
||||
<H2><a name="java_allprotected"></a>20.6 Accessing protected members</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3571,7 +3567,7 @@ class MyProtectedBase extends ProtectedBase
|
|||
|
||||
|
||||
|
||||
<H2><a name="common_customization"></a>21.7 Common customization features</H2>
|
||||
<H2><a name="common_customization"></a>20.7 Common customization features</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3583,7 +3579,7 @@ be awkward. This section describes some common SWIG features that are used
|
|||
to improve the interface to existing C/C++ code.
|
||||
</p>
|
||||
|
||||
<H3><a name="helper_functions"></a>21.7.1 C/C++ helper functions</H3>
|
||||
<H3><a name="helper_functions"></a>20.7.1 C/C++ helper functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3649,7 +3645,7 @@ hard to implement. It is possible to improve on this using Java code, typemaps,
|
|||
customization features as covered in later sections, but sometimes helper functions are a quick and easy solution to difficult cases.
|
||||
</p>
|
||||
|
||||
<H3><a name="class_extension"></a>21.7.2 Class extension with %extend</H3>
|
||||
<H3><a name="class_extension"></a>20.7.2 Class extension with %extend</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3712,7 +3708,7 @@ Vector(2,3,4)
|
|||
in any way---the extensions only show up in the Java interface.
|
||||
</p>
|
||||
|
||||
<H3><a name="exception_handling"></a>21.7.3 Exception handling with %exception and %javaexception</H3>
|
||||
<H3><a name="exception_handling"></a>20.7.3 Exception handling with %exception and %javaexception</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3760,7 +3756,7 @@ will produce a familiar looking Java exception:
|
|||
Exception in thread "main" java.lang.OutOfMemoryError: Not enough memory
|
||||
at exampleJNI.malloc(Native Method)
|
||||
at example.malloc(example.java:16)
|
||||
at runme.main(runme.java:112)
|
||||
at main.main(main.java:112)
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
@ -3820,9 +3816,7 @@ public:
|
|||
In the example above, <tt>java.lang.Exception</tt> is a checked exception class and so ought to be declared in the throws clause of <tt>getitem</tt>.
|
||||
Classes can be specified for adding to the throws clause using <tt>%javaexception(classes)</tt> instead of <tt>%exception</tt>,
|
||||
where <tt>classes</tt> is a string containing one or more comma separated Java classes.
|
||||
The <tt>%clearjavaexception</tt> feature is the equivalent to <tt>%clearexception</tt> and clears previously declared exception handlers.
|
||||
The <tt>%nojavaexception</tt> feature is the equivalent to <tt>%noexception</tt> and disables the exception handler.
|
||||
See <a href="Customization.html#Customization_clearing_features">Clearing features</a> for the difference on disabling and clearing features.
|
||||
The <tt>%nojavaexception</tt> feature is the equivalent to <tt>%noexception</tt> and clears previously declared exception handlers.
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
|
|
@ -3871,7 +3865,7 @@ to raise exceptions. See the <a href="Library.html#Library">SWIG Library</a> ch
|
|||
The typemap example <a href="#exception_typemap">Handling C++ exception specifications as Java exceptions</a> provides further exception handling capabilities.
|
||||
</p>
|
||||
|
||||
<H3><a name="method_access"></a>21.7.4 Method access with %javamethodmodifiers</H3>
|
||||
<H3><a name="method_access"></a>20.7.4 Method access with %javamethodmodifiers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3897,7 +3891,7 @@ protected static void protect_me() {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="tips_techniques"></a>21.8 Tips and techniques</H2>
|
||||
<H2><a name="tips_techniques"></a>20.8 Tips and techniques</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3907,7 +3901,7 @@ strings and arrays. This chapter discusses the common techniques for
|
|||
solving these problems.
|
||||
</p>
|
||||
|
||||
<H3><a name="input_output_parameters"></a>21.8.1 Input and output parameters using primitive pointers and references</H3>
|
||||
<H3><a name="input_output_parameters"></a>20.8.1 Input and output parameters using primitive pointers and references</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4081,7 +4075,7 @@ void foo(Bar *OUTPUT);
|
|||
will not have the intended effect since <tt>typemaps.i</tt> does not define an OUTPUT rule for <tt>Bar</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="simple_pointers"></a>21.8.2 Simple pointers</H3>
|
||||
<H3><a name="simple_pointers"></a>20.8.2 Simple pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4147,7 +4141,7 @@ System.out.println("3 + 4 = " + result);
|
|||
See the <a href="Library.html#Library">SWIG Library</a> chapter for further details.
|
||||
</p>
|
||||
|
||||
<H3><a name="c_arrays"></a>21.8.3 Wrapping C arrays with Java arrays</H3>
|
||||
<H3><a name="c_arrays"></a>20.8.3 Wrapping C arrays with Java arrays</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4214,7 +4208,7 @@ Please be aware that the typemaps in this library are not efficient as all the e
|
|||
There is an alternative approach using the SWIG array library and this is covered in the next section.
|
||||
</p>
|
||||
|
||||
<H3><a name="unbounded_c_arrays"></a>21.8.4 Unbounded C Arrays</H3>
|
||||
<H3><a name="unbounded_c_arrays"></a>20.8.4 Unbounded C Arrays</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4359,7 +4353,7 @@ well suited for applications in which you need to create buffers,
|
|||
package binary data, etc.
|
||||
</p>
|
||||
|
||||
<H3><a name="java_heap_allocations"></a>21.8.5 Overriding new and delete to allocate from Java heap</H3>
|
||||
<H3><a name="java_heap_allocations"></a>20.8.5 Overriding new and delete to allocate from Java heap</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4476,7 +4470,7 @@ model and use these functions in place of malloc and free in your own
|
|||
code.
|
||||
</p>
|
||||
|
||||
<H2><a name="java_typemaps"></a>21.9 Java typemaps</H2>
|
||||
<H2><a name="java_typemaps"></a>20.9 Java typemaps</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4497,7 +4491,7 @@ Before proceeding, it should be stressed that typemaps are not a required
|
|||
part of using SWIG---the default wrapping behavior is enough in most cases.
|
||||
Typemaps are only used if you want to change some aspect of the generated code.
|
||||
|
||||
<H3><a name="default_primitive_type_mappings"></a>21.9.1 Default primitive type mappings</H3>
|
||||
<H3><a name="default_primitive_type_mappings"></a>20.9.1 Default primitive type mappings</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4649,7 +4643,7 @@ However, the mappings allow the full range of values for each C type from Java.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="Java_default_non_primitive_typemaps"></a>21.9.2 Default typemaps for non-primitive types</H3>
|
||||
<H3><a name="Java_default_non_primitive_typemaps"></a>20.9.2 Default typemaps for non-primitive types</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4664,7 +4658,7 @@ So in summary, the C/C++ pointer to non-primitive types is cast into the 64 bit
|
|||
The Java type is either the proxy class or type wrapper class.
|
||||
</p>
|
||||
|
||||
<H3><a name="jvm64"></a>21.9.3 Sixty four bit JVMs</H3>
|
||||
<H3><a name="jvm64"></a>20.9.3 Sixty four bit JVMs</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4677,7 +4671,7 @@ Unfortunately it won't of course hold true for JNI code.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="what_is_typemap"></a>21.9.4 What is a typemap?</H3>
|
||||
<H3><a name="what_is_typemap"></a>20.9.4 What is a typemap?</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4800,7 +4794,7 @@ int c = example.count('e',"Hello World");
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="typemaps_c_to_java_types"></a>21.9.5 Typemaps for mapping C/C++ types to Java types</H3>
|
||||
<H3><a name="typemaps_c_to_java_types"></a>20.9.5 Typemaps for mapping C/C++ types to Java types</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -5060,7 +5054,7 @@ These are listed below:
|
|||
|
||||
</table>
|
||||
|
||||
<H3><a name="typemap_attributes"></a>21.9.6 Java typemap attributes</H3>
|
||||
<H3><a name="typemap_attributes"></a>20.9.6 Java typemap attributes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -5106,7 +5100,7 @@ The "javain" typemap has the optional 'pre', 'post' and 'pgcppname' attributes.
|
|||
Note that when the 'pre' or 'post' attributes are specified and the associated type is used in a constructor, a constructor helper function is generated. This is necessary as the Java proxy constructor wrapper makes a call to a support constructor using a <i>this</i> call. In Java the <i>this</i> call must be the first statement in the constructor body. The constructor body thus calls the helper function and the helper function instead makes the JNI call, ensuring the 'pre' code is called before the JNI call is made. There is a <a href="#java_date_marshalling">Date marshalling</a> example showing 'pre', 'post' and 'pgcppname' attributes in action.
|
||||
</p>
|
||||
|
||||
<H3><a name="special_variables"></a>21.9.7 Java special variables</H3>
|
||||
<H3><a name="special_variables"></a>20.9.7 Java special variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -5249,7 +5243,7 @@ This special variable expands to the intermediary class name. Usually this is th
|
|||
unless the jniclassname attribute is specified in the <a href="Java.html#java_module_directive">%module directive</a>.
|
||||
</p>
|
||||
|
||||
<H3><a name="typemaps_for_c_and_cpp"></a>21.9.8 Typemaps for both C and C++ compilation</H3>
|
||||
<H3><a name="typemaps_for_c_and_cpp"></a>20.9.8 Typemaps for both C and C++ compilation</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -5286,7 +5280,7 @@ If you do not intend your code to be targeting both C and C++ then your typemaps
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="java_code_typemaps"></a>21.9.9 Java code typemaps</H3>
|
||||
<H3><a name="java_code_typemaps"></a>20.9.9 Java code typemaps</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -5482,7 +5476,7 @@ For the typemap to be used in all type wrapper classes, all the different types
|
|||
Again this is the same that is in "<tt>java.swg</tt>", barring the method modifier for <tt>getCPtr</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="java_directors_typemaps"></a>21.9.10 Director specific typemaps</H3>
|
||||
<H3><a name="java_directors_typemaps"></a>20.9.10 Director specific typemaps</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -5707,7 +5701,7 @@ The basic strategy here is to provide a default package typemap for the majority
|
|||
|
||||
</div>
|
||||
|
||||
<H2><a name="typemap_examples"></a>21.10 Typemap Examples</H2>
|
||||
<H2><a name="typemap_examples"></a>20.10 Typemap Examples</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -5717,7 +5711,7 @@ the SWIG library.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="simpler_enum_classes"></a>21.10.1 Simpler Java enums for enums without initializers</H3>
|
||||
<H3><a name="simpler_enum_classes"></a>20.10.1 Simpler Java enums for enums without initializers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -5796,7 +5790,7 @@ This would be done by using the original versions of these typemaps in "enums.sw
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="exception_typemap"></a>21.10.2 Handling C++ exception specifications as Java exceptions</H3>
|
||||
<H3><a name="exception_typemap"></a>20.10.2 Handling C++ exception specifications as Java exceptions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -5921,7 +5915,7 @@ We could alternatively have used <tt>%rename</tt> to rename <tt>what()</tt> into
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="nan_exception_typemap"></a>21.10.3 NaN Exception - exception handling for a particular type</H3>
|
||||
<H3><a name="nan_exception_typemap"></a>20.10.3 NaN Exception - exception handling for a particular type</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -6076,7 +6070,7 @@ If we were a martyr to the JNI cause, we could replace the succinct code within
|
|||
If we had, we would have put it in the "in" typemap which, like all JNI and Java typemaps, also supports the 'throws' attribute.
|
||||
</p>
|
||||
|
||||
<H3><a name="converting_java_string_arrays"></a>21.10.4 Converting Java String arrays to char ** </H3>
|
||||
<H3><a name="converting_java_string_arrays"></a>20.10.4 Converting Java String arrays to char ** </H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -6170,9 +6164,9 @@ When this module is compiled, our wrapped C functions can be used by the followi
|
|||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
// File runme.java
|
||||
// File main.java
|
||||
|
||||
public class runme {
|
||||
public class main {
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -6198,7 +6192,7 @@ When compiled and run we get:
|
|||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
$ java runme
|
||||
$ java main
|
||||
argv[0] = Cat
|
||||
argv[1] = Dog
|
||||
argv[2] = Cow
|
||||
|
|
@ -6220,7 +6214,7 @@ Lastly the "jni", "jtype" and "jstype" typemaps are also required to specify
|
|||
what Java types to use.
|
||||
</p>
|
||||
|
||||
<H3><a name="expanding_java_object"></a>21.10.5 Expanding a Java object to multiple arguments</H3>
|
||||
<H3><a name="expanding_java_object"></a>20.10.5 Expanding a Java object to multiple arguments</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -6302,7 +6296,7 @@ example.foo(new String[]{"red", "green", "blue", "white"});
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="using_typemaps_return_arguments"></a>21.10.6 Using typemaps to return arguments</H3>
|
||||
<H3><a name="using_typemaps_return_arguments"></a>20.10.6 Using typemaps to return arguments</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -6389,9 +6383,9 @@ The following Java program demonstrates this:
|
|||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
// File: runme.java
|
||||
// File: main.java
|
||||
|
||||
public class runme {
|
||||
public class main {
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -6416,11 +6410,11 @@ When compiled and run we get:
|
|||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
$ java runme
|
||||
$ java main
|
||||
1 12.0 340.0
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="adding_downcasts"></a>21.10.7 Adding Java downcasts to polymorphic return types</H3>
|
||||
<H3><a name="adding_downcasts"></a>20.10.7 Adding Java downcasts to polymorphic return types</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -6476,7 +6470,7 @@ We get:
|
|||
<div class="code"><pre>
|
||||
Ambulance started
|
||||
java.lang.ClassCastException
|
||||
at runme.main(runme.java:16)
|
||||
at main.main(main.java:16)
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -6626,7 +6620,7 @@ SWIG usually generates code which constructs the proxy classes using Java code a
|
|||
Note that the JNI code above uses a number of string lookups to call a constructor, whereas this would not occur using byte compiled Java code.
|
||||
</p>
|
||||
|
||||
<H3><a name="adding_equals_method"></a>21.10.8 Adding an equals method to the Java classes</H3>
|
||||
<H3><a name="adding_equals_method"></a>20.10.8 Adding an equals method to the Java classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -6670,7 +6664,7 @@ System.out.println("foo1? " + foo1.equals(foo2));
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="void_pointers"></a>21.10.9 Void pointers and a common Java base class</H3>
|
||||
<H3><a name="void_pointers"></a>20.10.9 Void pointers and a common Java base class</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -6729,7 +6723,7 @@ This example contains some useful functionality which you may want in your code.
|
|||
<li> It also has a function which effectively implements a cast from the type of the proxy/type wrapper class to a void pointer. This is necessary for passing a proxy class or a type wrapper class to a function that takes a void pointer.
|
||||
</ul>
|
||||
|
||||
<H3><a name="struct_pointer_pointer"></a>21.10.10 Struct pointer to pointer</H3>
|
||||
<H3><a name="struct_pointer_pointer"></a>20.10.10 Struct pointer to pointer</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -6909,7 +6903,7 @@ The C functional interface has been completely morphed into an object-oriented i
|
|||
the Butler class would behave much like any pure Java class and feel more natural to Java users.
|
||||
</p>
|
||||
|
||||
<H3><a name="java_memory_management_member_variables"></a>21.10.11 Memory management when returning references to member variables</H3>
|
||||
<H3><a name="java_memory_management_member_variables"></a>20.10.11 Memory management when returning references to member variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7032,7 +7026,7 @@ public class Bike {
|
|||
Note the <tt>addReference</tt> call.
|
||||
</p>
|
||||
|
||||
<H3><a name="java_memory_management_objects"></a>21.10.12 Memory management for objects passed to the C++ layer</H3>
|
||||
<H3><a name="java_memory_management_objects"></a>20.10.12 Memory management for objects passed to the C++ layer</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7148,7 +7142,7 @@ The 'javacode' typemap simply adds in the specified code into the Java proxy cla
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="java_date_marshalling"></a>21.10.13 Date marshalling using the javain typemap and associated attributes</H3>
|
||||
<H3><a name="java_date_marshalling"></a>20.10.13 Date marshalling using the javain typemap and associated attributes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7325,7 +7319,7 @@ A few things to note:
|
|||
|
||||
|
||||
|
||||
<H2><a name="java_directors_faq"></a>21.11 Living with Java Directors</H2>
|
||||
<H2><a name="java_directors_faq"></a>20.11 Living with Java Directors</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7506,10 +7500,10 @@ public abstract class UserVisibleFoo extends Foo {
|
|||
</li>
|
||||
</ol>
|
||||
|
||||
<H2><a name="odds_ends"></a>21.12 Odds and ends</H2>
|
||||
<H2><a name="odds_ends"></a>20.12 Odds and ends</H2>
|
||||
|
||||
|
||||
<H3><a name="javadoc_comments"></a>21.12.1 JavaDoc comments</H3>
|
||||
<H3><a name="javadoc_comments"></a>20.12.1 JavaDoc comments</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7565,7 +7559,7 @@ public class Barmy {
|
|||
|
||||
|
||||
|
||||
<H3><a name="functional_interface"></a>21.12.2 Functional interface without proxy classes</H3>
|
||||
<H3><a name="functional_interface"></a>20.12.2 Functional interface without proxy classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7626,7 +7620,7 @@ All destructors have to be called manually for example the <tt>delete_Foo(foo)</
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="using_own_jni_functions"></a>21.12.3 Using your own JNI functions</H3>
|
||||
<H3><a name="using_own_jni_functions"></a>20.12.3 Using your own JNI functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7676,7 +7670,7 @@ This directive is only really useful if you want to mix your own hand crafted JN
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="performance"></a>21.12.4 Performance concerns and hints</H3>
|
||||
<H3><a name="performance"></a>20.12.4 Performance concerns and hints</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7697,7 +7691,7 @@ However, you will have to be careful about memory management and make sure that
|
|||
This method normally calls the C++ destructor or <tt>free()</tt> for C code.
|
||||
</p>
|
||||
|
||||
<H3><a name="java_debugging"></a>21.12.5 Debugging</H3>
|
||||
<H3><a name="java_debugging"></a>20.12.5 Debugging</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7719,7 +7713,7 @@ The -verbose:jni and -verbose:gc are also useful options for monitoring code beh
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="java_examples"></a>21.13 Examples</H2>
|
||||
<H2><a name="java_examples"></a>20.13 Examples</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
<li><a href="#Library_nn3">C Arrays and Pointers</a>
|
||||
<ul>
|
||||
<li><a href="#Library_nn4">cpointer.i</a>
|
||||
<li><a href="#Library_carrays">carrays.i</a>
|
||||
<li><a href="#Library_nn5">carrays.i</a>
|
||||
<li><a href="#Library_nn6">cmalloc.i</a>
|
||||
<li><a href="#Library_nn7">cdata.i</a>
|
||||
</ul>
|
||||
|
|
@ -316,7 +316,7 @@ In this example, the function <tt>int_to_uint()</tt> would be used to cast type
|
|||
<b>Note:</b> When working with simple pointers, typemaps can often be used to provide more seamless operation.
|
||||
</p>
|
||||
|
||||
<H3><a name="Library_carrays"></a>8.2.2 carrays.i</H3>
|
||||
<H3><a name="Library_nn5"></a>8.2.2 carrays.i</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -419,9 +419,7 @@ delete_doubleArray(a) # Destroy array
|
|||
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<b><tt>%array_class(type,name)</tt></b>
|
||||
</p>
|
||||
<div class="indent">
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Lisp_nn1"></a>22 SWIG and Common Lisp</H1>
|
||||
<H1><a name="Lisp_nn1"></a>21 SWIG and Common Lisp</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
Lisp, Common Foreign Function Interface(CFFI), CLisp and UFFI
|
||||
foreign function interfaces.
|
||||
</p>
|
||||
<H2><a name="Lisp_nn2"></a>22.1 Allegro Common Lisp</H2>
|
||||
<H2><a name="Lisp_nn2"></a>21.1 Allegro Common Lisp</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
<a href="Allegrocl.html#Allegrocl_nn1">here</a>
|
||||
</p>
|
||||
|
||||
<H2><a name="Lisp_nn3"></a>22.2 Common Foreign Function Interface(CFFI)</H2>
|
||||
<H2><a name="Lisp_nn3"></a>21.2 Common Foreign Function Interface(CFFI)</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -77,7 +77,7 @@ swig -cffi -module <i>module-name</i> <i>file-name</i>
|
|||
files and the various things which you can do with them.
|
||||
</p>
|
||||
|
||||
<H3><a name="Lisp_nn4"></a>22.2.1 Additional Commandline Options </H3>
|
||||
<H3><a name="Lisp_nn4"></a>21.2.1 Additional Commandline Options </H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -118,7 +118,7 @@ swig -cffi -help
|
|||
|
||||
</table>
|
||||
|
||||
<H3><a name="Lisp_nn5"></a>22.2.2 Generating CFFI bindings</H3>
|
||||
<H3><a name="Lisp_nn5"></a>21.2.2 Generating CFFI bindings</H3>
|
||||
|
||||
|
||||
As we mentioned earlier the ideal way to use SWIG is to use interface
|
||||
|
|
@ -392,7 +392,7 @@ The feature <i>intern_function</i> ensures that all C names are
|
|||
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lisp_nn6"></a>22.2.3 Generating CFFI bindings for C++ code</H3>
|
||||
<H3><a name="Lisp_nn6"></a>21.2.3 Generating CFFI bindings for C++ code</H3>
|
||||
|
||||
|
||||
<p>This feature to SWIG (for CFFI) is very new and still far from
|
||||
|
|
@ -568,7 +568,7 @@ If you have any questions, suggestions, patches, etc., related to CFFI
|
|||
module feel free to contact us on the SWIG mailing list, and
|
||||
also please add a "[CFFI]" tag in the subject line.
|
||||
|
||||
<H3><a name="Lisp_nn7"></a>22.2.4 Inserting user code into generated files</H3>
|
||||
<H3><a name="Lisp_nn7"></a>21.2.4 Inserting user code into generated files</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -583,7 +583,7 @@ using the SWIG <tt>%insert(section) %{ ...code... %}</tt> directive:
|
|||
<pre>
|
||||
%module example
|
||||
|
||||
%{
|
||||
%insert("runtime") %{
|
||||
#include "header.h"
|
||||
%}
|
||||
|
||||
|
|
@ -604,11 +604,11 @@ generated lisp interface file:
|
|||
</ul>
|
||||
<p>
|
||||
Note that the block <tt>%{ ... %}</tt> is effectively a shortcut for
|
||||
<tt>%insert("header") %{ ... %}</tt>.
|
||||
<tt>%insert("runtime") %{ ... %}</tt>.
|
||||
</p>
|
||||
|
||||
|
||||
<H2><a name="Lisp_nn8"></a>22.3 CLISP</H2>
|
||||
<H2><a name="Lisp_nn8"></a>21.3 CLISP</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -638,7 +638,7 @@ swig -clisp -module <i>module-name</i> <i>file-name</i>
|
|||
interface file for the CLISP module. The CLISP module tries to
|
||||
produce code which is both human readable and easily modifyable.
|
||||
</p>
|
||||
<H3><a name="Lisp_nn9"></a>22.3.1 Additional Commandline Options </H3>
|
||||
<H3><a name="Lisp_nn9"></a>21.3.1 Additional Commandline Options </H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -671,7 +671,7 @@ and global variables will be created otherwise only definitions for<br/>
|
|||
|
||||
</table>
|
||||
|
||||
<H3><a name="Lisp_nn10"></a>22.3.2 Details on CLISP bindings</H3>
|
||||
<H3><a name="Lisp_nn10"></a>21.3.2 Details on CLISP bindings</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -795,7 +795,7 @@ struct bar {
|
|||
|
||||
</pre></div>
|
||||
|
||||
<H2><a name="Lisp_nn11"></a>22.4 UFFI </H2>
|
||||
<H2><a name="Lisp_nn11"></a>21.4 UFFI </H2>
|
||||
|
||||
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Lua_nn1"></a>23 SWIG and Lua</H1>
|
||||
<H1><a name="Lua_nn1"></a>22 SWIG and Lua</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -34,29 +34,14 @@
|
|||
<li><a href="#Lua_nn20">C++ templates</a>
|
||||
<li><a href="#Lua_nn21">C++ Smart Pointers</a>
|
||||
<li><a href="#Lua_nn22">C++ Exceptions</a>
|
||||
<li><a href="#Lua_nn23">Writing your own custom wrappers</a>
|
||||
<li><a href="#Lua_nn24">Adding additional Lua code</a>
|
||||
</ul>
|
||||
<li><a href="#Lua_nn23">Typemaps</a>
|
||||
<li><a href="#Lua_nn25">Details on the Lua binding</a>
|
||||
<ul>
|
||||
<li><a href="#Lua_nn24">What is a typemap?</a>
|
||||
<li><a href="#Lua_nn25">Using typemaps</a>
|
||||
<li><a href="#Lua_nn26">Typemaps and arrays</a>
|
||||
<li><a href="#Lua_nn27">Typemaps and pointer-pointer functions</a>
|
||||
</ul>
|
||||
<li><a href="#Lua_nn28">Writing typemaps</a>
|
||||
<ul>
|
||||
<li><a href="#Lua_nn29">Typemaps you can write</a>
|
||||
<li><a href="#Lua_nn30">SWIG's Lua-C API</a>
|
||||
</ul>
|
||||
<li><a href="#Lua_nn31">Customization of your Bindings</a>
|
||||
<ul>
|
||||
<li><a href="#Lua_nn32">Writing your own custom wrappers</a>
|
||||
<li><a href="#Lua_nn33">Adding additional Lua code</a>
|
||||
</ul>
|
||||
<li><a href="#Lua_nn34">Details on the Lua binding</a>
|
||||
<ul>
|
||||
<li><a href="#Lua_nn35">Binding global data into the module.</a>
|
||||
<li><a href="#Lua_nn36">Userdata and Metatables</a>
|
||||
<li><a href="#Lua_nn37">Memory management</a>
|
||||
<li><a href="#Lua_nn26">Binding global data into the module.</a>
|
||||
<li><a href="#Lua_nn27">Userdata and Metatables</a>
|
||||
<li><a href="#Lua_nn28">Memory management</a>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -67,13 +52,13 @@
|
|||
<p>
|
||||
Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight configuration language for any program that needs one. Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++). Its also a <em>really</em> tiny language, less than 6000 lines of code, which compiles to <100 kilobytes of binary code. It can be found at <a href="http://www.lua.org">http://www.lua.org</a>
|
||||
</p>
|
||||
<H2><a name="Lua_nn2"></a>23.1 Preliminaries</H2>
|
||||
<H2><a name="Lua_nn2"></a>22.1 Preliminaries</H2>
|
||||
|
||||
|
||||
<p>
|
||||
The current SWIG implementation is designed to work with Lua 5.0.x and Lua 5.1.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. ((Currently SWIG generated code has only been tested on Windows with MingW, though given the nature of Lua, is should not have problems on other OS's)). It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms).
|
||||
</p>
|
||||
<H2><a name="Lua_nn3"></a>23.2 Running SWIG</H2>
|
||||
<H2><a name="Lua_nn3"></a>22.2 Running SWIG</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -105,7 +90,7 @@ This creates a C/C++ source file <tt>example_wrap.c</tt> or <tt>example_wrap.cxx
|
|||
<p>
|
||||
The name of the wrapper file is derived from the name of the input file. For example, if the input file is <tt>example.i</tt>, the name of the wrapper file is <tt>example_wrap.c</tt>. To change this, you can use the -o option. The wrappered module will export one function <tt>"int luaopen_example(lua_State* L)"</tt> which must be called to register the module with the Lua interpreter. The name "luaopen_example" depends upon the name of the module.
|
||||
</p>
|
||||
<H3><a name="Lua_nn4"></a>23.2.1 Compiling and Linking and Interpreter</H3>
|
||||
<H3><a name="Lua_nn4"></a>22.2.1 Compiling and Linking and Interpreter</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -152,7 +137,7 @@ $ gcc -c example.c -o example.o
|
|||
$ gcc -I/usr/include/lua -L/usr/lib/lua min.o example_wrap.o example.o -o my_lua
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lua_nn5"></a>23.2.2 Compiling a dynamic module</H3>
|
||||
<H3><a name="Lua_nn5"></a>22.2.2 Compiling a dynamic module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -220,7 +205,7 @@ Is quite obvious (Go back and consult the Lua documents on how to enable loadlib
|
|||
|
||||
|
||||
|
||||
<H3><a name="Lua_nn6"></a>23.2.3 Using your module</H3>
|
||||
<H3><a name="Lua_nn6"></a>22.2.3 Using your module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -238,19 +223,19 @@ $ ./my_lua
|
|||
>
|
||||
</pre></div>
|
||||
|
||||
<H2><a name="Lua_nn7"></a>23.3 A tour of basic C/C++ wrapping</H2>
|
||||
<H2><a name="Lua_nn7"></a>22.3 A tour of basic C/C++ wrapping</H2>
|
||||
|
||||
|
||||
<p>
|
||||
By default, SWIG tries to build a very natural Lua interface to your C/C++ code. This section briefly covers the essential aspects of this wrapping.
|
||||
</p>
|
||||
<H3><a name="Lua_nn8"></a>23.3.1 Modules</H3>
|
||||
<H3><a name="Lua_nn8"></a>22.3.1 Modules</H3>
|
||||
|
||||
|
||||
<p>
|
||||
The SWIG module directive specifies the name of the Lua module. If you specify `module example', then everything is wrapped into a Lua table 'example' containing all the functions and variables. When choosing a module name, make sure you don't use the same name as a built-in Lua command or standard module name.
|
||||
</p>
|
||||
<H3><a name="Lua_nn9"></a>23.3.2 Functions</H3>
|
||||
<H3><a name="Lua_nn9"></a>22.3.2 Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -288,7 +273,7 @@ It is also possible to rename the module with an assignment.
|
|||
24
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lua_nn10"></a>23.3.3 Global variables</H3>
|
||||
<H3><a name="Lua_nn10"></a>22.3.3 Global variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -362,7 +347,7 @@ nil
|
|||
3.142
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lua_nn11"></a>23.3.4 Constants and enums</H3>
|
||||
<H3><a name="Lua_nn11"></a>22.3.4 Constants and enums</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -385,7 +370,7 @@ example.SUNDAY=0
|
|||
<p>
|
||||
Constants are not guaranteed to remain constant in Lua. The name of the constant could be accidentally reassigned to refer to some other object. Unfortunately, there is no easy way for SWIG to generate code that prevents this. You will just have to be careful.
|
||||
</p>
|
||||
<H3><a name="Lua_nn12"></a>23.3.5 Pointers</H3>
|
||||
<H3><a name="Lua_nn12"></a>22.3.5 Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -423,7 +408,7 @@ Lua enforces the integrity of its userdata, so it is virtually impossible to cor
|
|||
nil
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lua_nn13"></a>23.3.6 Structures</H3>
|
||||
<H3><a name="Lua_nn13"></a>22.3.6 Structures</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -509,7 +494,7 @@ Because the pointer points inside the structure, you can modify the contents and
|
|||
> x.a = 3 -- Modifies the same structure
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lua_nn14"></a>23.3.7 C++ classes</H3>
|
||||
<H3><a name="Lua_nn14"></a>22.3.7 C++ classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -570,7 +555,7 @@ It is not (currently) possible to access static members of an instance:
|
|||
-- does NOT work
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lua_nn15"></a>23.3.8 C++ inheritance</H3>
|
||||
<H3><a name="Lua_nn15"></a>22.3.8 C++ inheritance</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -595,7 +580,7 @@ then the function <tt>spam()</tt> accepts a Foo pointer or a pointer to any clas
|
|||
<p>
|
||||
It is safe to use multiple inheritance with SWIG.
|
||||
</p>
|
||||
<H3><a name="Lua_nn16"></a>23.3.9 Pointers, references, values, and arrays</H3>
|
||||
<H3><a name="Lua_nn16"></a>22.3.9 Pointers, references, values, and arrays</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -626,7 +611,7 @@ Foo spam7();
|
|||
<p>
|
||||
then all three functions will return a pointer to some Foo object. Since the third function (spam7) returns a value, newly allocated memory is used to hold the result and a pointer is returned (Lua will release this memory when the return value is garbage collected). The other two are pointers which are assumed to be managed by the C code and so will not be garbage collected.
|
||||
</p>
|
||||
<H3><a name="Lua_nn17"></a>23.3.10 C++ overloaded functions</H3>
|
||||
<H3><a name="Lua_nn17"></a>22.3.10 C++ overloaded functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -712,7 +697,7 @@ Please refer to the "SWIG and C++" chapter for more information about overloadin
|
|||
<p>
|
||||
Dealing with the Lua coercion mechanism, the priority is roughly (integers, floats, strings, userdata). But it is better to rename the functions rather than rely upon the ordering.
|
||||
</p>
|
||||
<H3><a name="Lua_nn18"></a>23.3.11 C++ operators</H3>
|
||||
<H3><a name="Lua_nn18"></a>22.3.11 C++ operators</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -824,7 +809,7 @@ It is also possible to overload the operator<tt>[]</tt>, but currently this cann
|
|||
};
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lua_nn19"></a>23.3.12 Class extension with %extend</H3>
|
||||
<H3><a name="Lua_nn19"></a>22.3.12 Class extension with %extend</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -879,7 +864,7 @@ true
|
|||
<p>
|
||||
Extend works with both C and C++ code, on classes and structs. It does not modify the underlying object in any way---the extensions only show up in the Lua interface. The only item to take note of is the code has to use the '$self' instead of 'this', and that you cannot access protected/private members of the code (as you are not officially part of the class).
|
||||
</p>
|
||||
<H3><a name="Lua_nn20"></a>23.3.13 C++ templates</H3>
|
||||
<H3><a name="Lua_nn20"></a>22.3.13 C++ templates</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -914,7 +899,7 @@ In Lua:
|
|||
<p>
|
||||
Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter. Some more complicated examples will appear later.
|
||||
</p>
|
||||
<H3><a name="Lua_nn21"></a>23.3.14 C++ Smart Pointers</H3>
|
||||
<H3><a name="Lua_nn21"></a>22.3.14 C++ Smart Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -966,7 +951,7 @@ If you ever need to access the underlying pointer returned by <tt>operator->(
|
|||
> f = p:__deref__() -- Returns underlying Foo *
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lua_nn22"></a>23.3.15 C++ Exceptions</H3>
|
||||
<H3><a name="Lua_nn22"></a>22.3.15 C++ Exceptions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1018,9 +1003,8 @@ stack traceback:
|
|||
</pre></div>
|
||||
|
||||
<p>
|
||||
SWIG is able to throw numeric types, enums, chars, char*'s and std::string's without problem. It has also written typemaps for std::exception and its derived classes, which convert the exception into and error string. </p>
|
||||
<p>
|
||||
However its not so simple for to throw other types of objects.
|
||||
SWIG is able to throw numeric types, enums, chars, char*'s and std::string's without problem.
|
||||
However its not so simple for to throw objects.
|
||||
Thrown objects are not valid outside the 'catch' block. Therefore they cannot be
|
||||
returned to the interpreter.
|
||||
The obvious ways to overcome this would be to either return a copy of the object, or so convert the object to a string and
|
||||
|
|
@ -1054,6 +1038,10 @@ To get a more useful behaviour out of SWIG you must either: provide a way to con
|
|||
throw objects which can be copied.
|
||||
</p>
|
||||
<p>
|
||||
SWIG has typemaps for std::exception and its children already written, so a function which throws any of these will
|
||||
automatically have its exception converted into an error string.
|
||||
</p>
|
||||
<p>
|
||||
If you have your own class which you want output as a string you will need to add a typemap something like this:
|
||||
</p>
|
||||
<div class="code"><pre>
|
||||
|
|
@ -1110,271 +1098,7 @@ add exception specification to functions or globally (respectively).
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="Lua_nn23"></a>23.4 Typemaps</H2>
|
||||
|
||||
|
||||
<p>This section explains what typemaps are and the usage of them. The default wrappering behaviour of SWIG is enough in most cases. However sometimes SWIG may need a little additional assistance to know which typemap to apply to provide the best wrappering. This section will be explaining how to use typemaps to best effect</p>
|
||||
|
||||
<H3><a name="Lua_nn24"></a>23.4.1 What is a typemap?</H3>
|
||||
|
||||
|
||||
<p>A typemap is nothing more than a code generation rule that is attached to a specific C datatype. For example, to convert integers from Lua to C, you might define a typemap like this:</p>
|
||||
|
||||
<div class="code"><pre>%module example
|
||||
|
||||
%typemap(in) int {
|
||||
$1 = (int) lua_tonumber(L,$input);
|
||||
printf("Received an integer : %d\n",$1);
|
||||
}
|
||||
%inline %{
|
||||
extern int fact(int n);
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p><i>Note: you shouldn't use this typemap, as SWIG already has a typemap for this task. This is purely for example.</i></p>
|
||||
|
||||
<p>Typemaps are always associated with some specific aspect of code generation. In this case, the "in" method refers to the conversion of input arguments to C/C++. The datatype int is the datatype to which the typemap will be applied. The supplied C code is used to convert values. In this code a number of special variable prefaced by a $ are used. The $1 variable is placeholder for a local variable of type int. The $input is the index on the Lua stack for the value to be used.</p>
|
||||
|
||||
<p>When this example is compiled into a Lua module, it operates as follows:</p>
|
||||
|
||||
<div class="targetlang"><pre>> require "example"
|
||||
> print(example.fact(6))
|
||||
Received an integer : 6
|
||||
720
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Lua_nn25"></a>23.4.2 Using typemaps</H3>
|
||||
|
||||
|
||||
<p>There are many ready written typemaps built into SWIG for all common types (int, float, short, long, char*, enum and more), which SWIG uses automatically, with no effort required on your part.</p>
|
||||
|
||||
<p>However for more complex functions which use input/output parameters or arrays, you will need to make use of <typemaps.i>, which contains typemaps for these situations. For example, consider these functions:</p>
|
||||
|
||||
<div class="code"><pre>void add(int x, int y, int *result) {
|
||||
*result = x + y;
|
||||
}
|
||||
|
||||
int sub(int *x1, int *y1) {
|
||||
return *x1-*y1;
|
||||
}
|
||||
|
||||
void swap(int *sx, int *sy) {
|
||||
int t=*sx;
|
||||
*sx=*sy;
|
||||
*sy=t;
|
||||
}
|
||||
</pre></div>
|
||||
|
||||
<p>It is clear to the programmer, that 'result' is an output parameter, 'x1' and 'y1' are input parameters and 'sx' and 'sy' are input/output parameters. However is not apparent to SWIG, so SWIG must to informed about which kind they are, so it can wrapper accordingly.</p>
|
||||
|
||||
<p>One means would be to rename the argument name to help SWIG, eg <tt>void add(int x, int y, int *OUTPUT)</tt>, however it is easier to use the <tt>%apply</tt> to achieve the same result, as shown below.</p>
|
||||
|
||||
<div class="code"><pre>%include <typemaps.i>
|
||||
%apply int* OUTPUT {int *result}; // int *result is output
|
||||
%apply int* INPUT {int *x1, int *y1}; // int *x1 and int *y1 are input
|
||||
%apply int* INOUT {int *sx, int *sy}; // int *sx and int *sy are input and output
|
||||
|
||||
void add(int x, int y, int *result);
|
||||
int sub(int *x1, int *y1);
|
||||
void swap(int *sx, int *sy);
|
||||
</pre></div>
|
||||
|
||||
<p>When wrapped, it gives the following results:</p>
|
||||
|
||||
<div class="targetlang"><pre>> require "example"
|
||||
> print(example.add(1,2))
|
||||
3
|
||||
> print(demo.sub(1,2))
|
||||
-1
|
||||
> a,b=1,2
|
||||
> c,d=demo.swap(a,b)
|
||||
> print(a,b,c,d)
|
||||
1 2 2 1
|
||||
</pre></div>
|
||||
|
||||
<p>Notice, that 'result' is not required in the arguments to call the function, as it an output parameter only. For 'sx' and 'sy' they must be passed in (as they are input), but the original value is not modified (Lua does not have a pass by reference feature). The modified results are then returned as two return values. All INPUT/OUTPUT/INOUT arguments will behave in a similar manner.</p>
|
||||
|
||||
<p>Note: C++ references must be handled exactly the same way. However SWIG will automatically wrap a <tt>const int&</tt> as an input parameter (since that it obviously input).</p>
|
||||
|
||||
<H3><a name="Lua_nn26"></a>23.4.3 Typemaps and arrays</H3>
|
||||
|
||||
|
||||
<p>Arrays present a challenge for SWIG, because like pointers SWIG does not know whether these are input or output values, nor
|
||||
does SWIG have any indication of how large an array should be. However with the proper guidance SWIG can easily wrapper
|
||||
arrays for convenient usage.</p>
|
||||
|
||||
<p>Given the functions:</p>
|
||||
<div class="code"><pre>extern void sort_int(int* arr, int len);
|
||||
extern void sort_double(double* arr, int len);
|
||||
</pre></div>
|
||||
|
||||
<p>There are basically two ways that SWIG can deal with this. The first way, uses the <tt><carrays.i></tt> library
|
||||
to create an array in C/C++ then this can be filled within Lua and passed into the function. It works, but its a bit tedious.
|
||||
More details can be found in the <a href="Library.html#Library_nn5">carrays.i</a> documention.</p>
|
||||
|
||||
<p>The second and more intuitive way, would be to pass a Lua table directly into the function, and have SWIG automatically convert between Lua-table and C-array. Within the <tt><typemaps.i></tt> file there are typemaps ready written to perform this task. To use them is again a matter of using %appy in the correct manner.</p>
|
||||
|
||||
<p>The wrapper file below, shows both the use of carrays as well as the use of the typemap to wrap arrays. </p>
|
||||
|
||||
<div class="code"><pre>// using the C-array
|
||||
%include <carrays.i>
|
||||
// this declares a batch of function for manipulating C integer arrays
|
||||
%array_functions(int,int)
|
||||
|
||||
extern void sort_int(int* arr, int len); // the function to wrap
|
||||
|
||||
// using typemaps
|
||||
%include <typemaps.i>
|
||||
%apply (double *INOUT,int) {(double* arr,int len)};
|
||||
|
||||
extern void sort_double(double* arr, int len); // the function to wrap
|
||||
</pre></div>
|
||||
|
||||
<p>Once wrappered, the functions can both be called, though with different ease of use:</p>
|
||||
|
||||
<div class="targetlang"><pre>require "example"
|
||||
ARRAY_SIZE=10
|
||||
|
||||
-- passing a C array to the sort_int()
|
||||
arr=example.new_int(ARRAY_SIZE) -- create the array
|
||||
for i=0,ARRAY_SIZE-1 do -- index 0..9 (just like C)
|
||||
example.int_setitem(arr,i,math.random(1000))
|
||||
end
|
||||
example.sort_int(arr,ARRAY_SIZE) -- call the function
|
||||
example.delete_int(arr) -- must delete the allocated memory
|
||||
|
||||
-- use a typemap to call with a Lua-table
|
||||
-- one item of note: the typemap creates a copy, rather than edit-in-place
|
||||
t={} -- a Lua table
|
||||
for i=1,ARRAY_SIZE do -- index 1..10 (Lua style)
|
||||
t[i]=math.random(1000)/10
|
||||
end
|
||||
t=example.sort_double(t) -- replace t with the result
|
||||
</pre></div>
|
||||
|
||||
<p>Obviously the first version could be made less tedious by writing a Lua function to perform the conversion from a table
|
||||
to a C-array. The <tt>%luacode</tt> directive is good for this. See SWIG\Examples\lua\arrays for an example of this.</p>
|
||||
|
||||
<p><b>Warning:</b> in C indexes start at ZERO, in Lua indexes start at ONE. SWIG expects C-arrays to be filled for 0..N-1
|
||||
and Lua tables to be 1..N, (the indexing follows the norm for the language). In the typemap when it converts the table to an array it quietly changes the indexing accordingly. Take note of this behaviour if you have a C function which returns indexes.</p>
|
||||
|
||||
<p>Note: SWIG also can support arrays of pointers in a similar manner.</p>
|
||||
|
||||
<H3><a name="Lua_nn27"></a>23.4.4 Typemaps and pointer-pointer functions</H3>
|
||||
|
||||
|
||||
<p>Several C++ libraries use a pointer-pointer functions to create its objects. These functions require a pointer to a pointer which is then filled with the pointer to the new object. Microsoft's COM and DirectX as well as many other libraries have this kind of function. An example is given below:</p>
|
||||
|
||||
<div class="code"><pre>struct iMath; // some structure
|
||||
int Create_Math(iMath** pptr); // its creator (assume it mallocs)
|
||||
</pre></div>
|
||||
|
||||
<p>Which would be used with the following C code:</p>
|
||||
|
||||
<div class="code"><pre>iMath* ptr;
|
||||
int ok;
|
||||
ok=Create_Math(&ptr);
|
||||
// do things with ptr
|
||||
//...
|
||||
free(ptr); // dispose of iMath
|
||||
</pre></div>
|
||||
|
||||
<p>SWIG has a ready written typemap to deal with such a kind of function in <typemaps.i>. It provides the correct wrappering as well as setting the flag to inform Lua that the object in question should be garbage collected. Therefore the code is simply:</p>
|
||||
|
||||
<div class="code"><pre>%include <typemaps.i>
|
||||
%apply SWIGTYPE** OUTPUT{iMath **pptr }; // tell SWIG its an output
|
||||
|
||||
struct iMath; // some structure
|
||||
int Create_Math(iMath** pptr); // its creator (assume it mallocs)
|
||||
</pre></div>
|
||||
|
||||
<p>The usage is as follows:</p>
|
||||
|
||||
<div class="targetlang"><pre>ok,ptr=Create_Math() -- ptr is a iMath* which is returned with the int (ok)
|
||||
ptr=nil -- the iMath* will be GC'ed as normal
|
||||
</pre></div>
|
||||
|
||||
<H2><a name="Lua_nn28"></a>23.5 Writing typemaps</H2>
|
||||
|
||||
|
||||
<p>This section describes how you can modify SWIG's default wrapping behavior for various C/C++ datatypes using the <tt>%typemap</tt> directive. This is an advanced topic that assumes familiarity with the Lua C API as well as the material in the "<a href="Typemaps.html#Typemaps">Typemaps</a>" chapter.</p>
|
||||
|
||||
<p>Before proceeding, it should be stressed that writing typemaps is rarely needed unless you want to change some aspect of the wrappering, or to achieve an effect which in not available with the default bindings.</p>
|
||||
|
||||
<p>Before proceeding, you should read the previous section on using typemaps, as well as read the ready written typemaps found in luatypemaps.swg and typemaps.i. These are both well documented and fairly easy to read. You should not attempt to write your own typemaps until you have read and can understand both of these files (they may well also give you a idea to base your worn on).</p>
|
||||
|
||||
<H3><a name="Lua_nn29"></a>23.5.1 Typemaps you can write</H3>
|
||||
|
||||
|
||||
<p>There are many different types of typemap that can be written, the full list can be found in the "<a href="Typemaps.html#Typemaps">Typemaps</a>" chapter. However the following are the most commonly used ones.</p>
|
||||
|
||||
<ul>
|
||||
<li><tt>in</tt> this is for input arguments to functions</li>
|
||||
<li><tt>out</tt> this is for return types from functions</li>
|
||||
<li><tt>argout</tt> this is for a function argument which is actually returning something</li>
|
||||
<li><tt>typecheck</tt> this is used to determine which overloaded function should be called
|
||||
(the syntax for the typecheck is different from the typemap, see typemaps for details).</li>
|
||||
</ul>
|
||||
|
||||
<H3><a name="Lua_nn30"></a>23.5.2 SWIG's Lua-C API</H3>
|
||||
|
||||
|
||||
<p>This section explains the SWIG specific Lua-C API. It does not cover the main Lua-C api, as this is well documented and not worth covering.</p>
|
||||
|
||||
<p><tt>int SWIG_ConvertPtr(lua_State* L,int index,void** ptr,swig_type_info *type,int flags);</tt></p>
|
||||
|
||||
<div class="indent">
|
||||
This is the standard function used for converting a Lua userdata to a void*. It takes the value at the given index in the Lua state and converts it to a userdata. It will then provide the neccesary type checks, confirming that the pointer is compatible with the type given in 'type'. Then finally setting '*ptr' to the pointer.
|
||||
If flags is set to SWIG_POINTER_DISOWN, this is will clear any ownership flag set on the object.<br>
|
||||
The returns a value which can be checked with the macro SWIG_IsOK()
|
||||
</div>
|
||||
|
||||
<p><tt>void SWIG_NewPointerObj(lua_State* L,void* ptr,swig_type_info *type,int own);</tt></p>
|
||||
|
||||
<div class="indent">
|
||||
This is the opposite of SWIG_ConvertPtr, as it pushes a new userdata which wrappers the pointer 'ptr' of type 'type'.
|
||||
The parameter 'own' specifies if the object is owned be Lua and if it is 1 then Lua will GC the object when the userdata is disposed of.
|
||||
</div>
|
||||
|
||||
<p><tt>void* SWIG_MustGetPtr(lua_State* L,int index,swig_type_info *type,int flags,int argnum,const char* func_name);</tt></p>
|
||||
|
||||
<div class="indent">
|
||||
This function is a version of SWIG_ConvertPtr(), except that it will either work, or it will trigger a lua_error() with a text error message. This function is rarely used, and may be deprecated in the future.
|
||||
</div>
|
||||
|
||||
<p><tt>SWIG_fail</tt></p>
|
||||
|
||||
<div class="indent">
|
||||
This macro, when called within the context of a SWIG wrappered function, will jump to the error handler code. This will call any cleanup code (freeing any temp variables) and then triggers a lua_error.<br>
|
||||
A common use for this code is:<br><pre>
|
||||
if (!SWIG_IsOK(SWIG_ConvertPtr( .....)){
|
||||
lua_pushstring(L,"something bad happened");
|
||||
SWIG_fail;
|
||||
}</pre></div>
|
||||
|
||||
<p><tt>SWIG_fail_arg(char* func_name,int argnum,char* type)</tt></p>
|
||||
|
||||
<div class="indent">
|
||||
This macro, when called within the context of a SWIG wrappered function, will display the error message and jump to the error handler code. The error message is of the form
|
||||
<pre>
|
||||
"Error in <i>func_name</i> (arg <i>argnum</i>), expected '<i>type</i>' got '<i>whatever the type was</i>'"
|
||||
</pre></div>
|
||||
|
||||
<p><tt>SWIG_fail_ptr(const char* fn_name,int argnum,swig_type_info* type);</tt></p>
|
||||
|
||||
<div class="indent">
|
||||
Similar to SWIG_fail_arg, except that it will display the swig_type_info information instead.</div>
|
||||
|
||||
<H2><a name="Lua_nn31"></a>23.6 Customization of your Bindings</H2>
|
||||
|
||||
|
||||
<p>
|
||||
This section covers adding of some small extra bits to your module to add the last finishing touches.
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
<H3><a name="Lua_nn32"></a>23.6.1 Writing your own custom wrappers</H3>
|
||||
<H3><a name="Lua_nn23"></a>22.3.16 Writing your own custom wrappers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1393,7 +1117,7 @@ int native_function(lua_State*L) // my native code
|
|||
The <tt>%native</tt> directive in the above example, tells SWIG that there is a function <tt>int native_function(lua_State*L);</tt> which is to be added into the module under the name '<tt>my_func</tt>'. SWIG will not add any wrappering for this function, beyond adding it into the function table. How you write your code is entirely up to you.
|
||||
</p>
|
||||
|
||||
<H3><a name="Lua_nn33"></a>23.6.2 Adding additional Lua code</H3>
|
||||
<H3><a name="Lua_nn24"></a>22.3.17 Adding additional Lua code</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1431,7 +1155,7 @@ Good uses for this feature is adding of new code, or writing helper functions to
|
|||
See Examples/lua/arrays for an example of this code.
|
||||
</p>
|
||||
|
||||
<H2><a name="Lua_nn34"></a>23.7 Details on the Lua binding</H2>
|
||||
<H2><a name="Lua_nn25"></a>22.4 Details on the Lua binding</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1442,7 +1166,7 @@ See Examples/lua/arrays for an example of this code.
|
|||
</i>
|
||||
</p>
|
||||
|
||||
<H3><a name="Lua_nn35"></a>23.7.1 Binding global data into the module.</H3>
|
||||
<H3><a name="Lua_nn26"></a>22.4.1 Binding global data into the module.</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1502,7 +1226,7 @@ end
|
|||
<p>
|
||||
That way when you call '<tt>a=example.Foo</tt>', the interpreter looks at the table 'example' sees that there is no field 'Foo' and calls __index. This will in turn check in '.get' table and find the existence of 'Foo' and then return the value of the C function call 'Foo_get()'. Similarly for the code '<tt>example.Foo=10</tt>', the interpreter will check the table, then call the __newindex which will then check the '.set' table and call the C function 'Foo_set(10)'.
|
||||
</p>
|
||||
<H3><a name="Lua_nn36"></a>23.7.2 Userdata and Metatables</H3>
|
||||
<H3><a name="Lua_nn27"></a>22.4.2 Userdata and Metatables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1582,7 +1306,7 @@ Note: Both the opaque structures (like the FILE*) and normal wrappered classes/s
|
|||
<p>
|
||||
Note: Operator overloads are basically done in the same way, by adding functions such as '__add' & '__call' to the classes metatable. The current implementation is a bit rough as it will add any member function beginning with '__' into the metatable too, assuming its an operator overload.
|
||||
</p>
|
||||
<H3><a name="Lua_nn37"></a>23.7.3 Memory management</H3>
|
||||
<H3><a name="Lua_nn28"></a>22.4.3 Memory management</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -18,19 +18,15 @@ HTMLDOC_OPTIONS = "--book --toclevels 4 --no-numbered --toctitle \"Table of Cont
|
|||
|
||||
all: maketoc check generate
|
||||
|
||||
maketoc: CCache.html
|
||||
maketoc:
|
||||
python maketoc.py
|
||||
|
||||
CCache.html: ../../CCache/ccache.yo
|
||||
yodl2html -o CCache.html ../../CCache/ccache.yo
|
||||
|
||||
# Use htmltidy to warn about some HTML errors. Note that it is not used to clean/tidy the HTML,
|
||||
# it is just used as a primitive HTML checker.
|
||||
# CCache.html is generated by yodl2html and has a few insignificant problems, so we don't put it through tidy
|
||||
check:
|
||||
tidy -errors --gnu-emacs yes -quiet index.html
|
||||
tidy -errors --gnu-emacs yes -quiet Sections.html
|
||||
all=`sed '/^#/d' chapters | grep -v CCache.html`; for a in $$all; do tidy -errors --gnu-emacs yes -quiet $$a; done;
|
||||
all=`sed '/^#/d' chapters`; for a in $$all; do tidy -errors --gnu-emacs yes -quiet $$a; done;
|
||||
|
||||
generate: swightml.book swigpdf.book
|
||||
htmldoc --batch swightml.book || true
|
||||
|
|
@ -49,14 +45,11 @@ swightml.book:
|
|||
echo "Sections.html" >> swightml.book
|
||||
cat chapters >> swightml.book
|
||||
|
||||
clean: clean-baks
|
||||
clean:
|
||||
rm -f swightml.book
|
||||
rm -f swigpdf.book
|
||||
rm -f CCache.html
|
||||
rm -f SWIGDocumentation.html
|
||||
rm -f SWIGDocumentation.pdf
|
||||
|
||||
clean-baks:
|
||||
rm -f *.bak
|
||||
|
||||
test:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<H1><a name="Modula3"></a>24 SWIG and Modula-3</H1>
|
||||
<H1><a name="Modula3"></a>23 SWIG and Modula-3</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -57,7 +57,7 @@ especially
|
|||
<a href="Typemaps.html">typemaps</a>.
|
||||
</p>
|
||||
|
||||
<H2><a name="modula3_overview"></a>24.1 Overview</H2>
|
||||
<H2><a name="modula3_overview"></a>23.1 Overview</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -90,7 +90,7 @@ So the introduction got a bit longer than it should ... ;-)
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="whyscripting"></a>24.1.1 Why not scripting ?</H3>
|
||||
<H3><a name="whyscripting"></a>23.1.1 Why not scripting ?</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -126,7 +126,7 @@ are not advantages of the language itself
|
|||
but can be provided by function libraries.
|
||||
</p>
|
||||
|
||||
<H3><a name="whymodula3"></a>24.1.2 Why Modula-3 ?</H3>
|
||||
<H3><a name="whymodula3"></a>23.1.2 Why Modula-3 ?</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -166,7 +166,7 @@ it's statically typed, too.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="whycpp"></a>24.1.3 Why C / C++ ?</H3>
|
||||
<H3><a name="whycpp"></a>23.1.3 Why C / C++ ?</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -179,7 +179,7 @@ Even more fortunately even non-C libraries may provide C header files.
|
|||
This is where SWIG becomes helpful.
|
||||
</p>
|
||||
|
||||
<H3><a name="whyswig"></a>24.1.4 Why SWIG ?</H3>
|
||||
<H3><a name="whyswig"></a>23.1.4 Why SWIG ?</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -252,10 +252,10 @@ integrate Modula-3 code into a C / C++ project.
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="conception"></a>24.2 Conception</H2>
|
||||
<H2><a name="conception"></a>23.2 Conception</H2>
|
||||
|
||||
|
||||
<H3><a name="cinterface"></a>24.2.1 Interfaces to C libraries</H3>
|
||||
<H3><a name="cinterface"></a>23.2.1 Interfaces to C libraries</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -404,7 +404,7 @@ and the principal type must be renamed (<tt>%typemap</tt>).
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="cppinterface"></a>24.2.2 Interfaces to C++ libraries</H3>
|
||||
<H3><a name="cppinterface"></a>23.2.2 Interfaces to C++ libraries</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -505,10 +505,10 @@ There is no C++ library I wrote a SWIG interface for,
|
|||
so I'm not sure if this is possible or sensible, yet.
|
||||
</p>
|
||||
|
||||
<H2><a name="preliminaries"></a>24.3 Preliminaries</H2>
|
||||
<H2><a name="preliminaries"></a>23.3 Preliminaries</H2>
|
||||
|
||||
|
||||
<H3><a name="compilers"></a>24.3.1 Compilers</H3>
|
||||
<H3><a name="compilers"></a>23.3.1 Compilers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -522,7 +522,7 @@ For testing examples I use Critical Mass cm3.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="commandline"></a>24.3.2 Additional Commandline Options</H3>
|
||||
<H3><a name="commandline"></a>23.3.2 Additional Commandline Options</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -599,10 +599,10 @@ Instead generate templates for some basic typemaps.
|
|||
</tr>
|
||||
</table>
|
||||
|
||||
<H2><a name="modula3_typemaps"></a>24.4 Modula-3 typemaps</H2>
|
||||
<H2><a name="modula3_typemaps"></a>23.4 Modula-3 typemaps</H2>
|
||||
|
||||
|
||||
<H3><a name="inoutparam"></a>24.4.1 Inputs and outputs</H3>
|
||||
<H3><a name="inoutparam"></a>23.4.1 Inputs and outputs</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -818,7 +818,7 @@ consist of the following parts:
|
|||
</table>
|
||||
|
||||
|
||||
<H3><a name="ordinals"></a>24.4.2 Subranges, Enumerations, Sets</H3>
|
||||
<H3><a name="ordinals"></a>23.4.2 Subranges, Enumerations, Sets</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -860,8 +860,8 @@ that split the task up into converting
|
|||
the C bit patterns (integer or bit set)
|
||||
into Modula-3 bit patterns (integer or bit set)
|
||||
and change the type as requested.
|
||||
See the corresponding example in the
|
||||
Examples/modula3/enum/example.i file.
|
||||
See the corresponding
|
||||
<a href="../../Examples/modula3/enum/example.i">example</a>.
|
||||
This is quite messy and not satisfying.
|
||||
So the best what you can currently do is
|
||||
to rewrite constant definitions manually.
|
||||
|
|
@ -870,20 +870,20 @@ that I'd like to automate.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="class"></a>24.4.3 Objects</H3>
|
||||
<H3><a name="class"></a>23.4.3 Objects</H3>
|
||||
|
||||
|
||||
<p>
|
||||
Declarations of C++ classes are mapped to <tt>OBJECT</tt> types
|
||||
while it is tried to retain the access hierarchy
|
||||
"public - protected - private" using partial revelation.
|
||||
Though the example in
|
||||
Examples/modula3/class/example.i
|
||||
Though the
|
||||
<a href="../../Examples/modula3/class/example.i">implementation</a>
|
||||
is not really useful, yet.
|
||||
</p>
|
||||
|
||||
|
||||
<H3><a name="imports"></a>24.4.4 Imports</H3>
|
||||
<H3><a name="imports"></a>23.4.4 Imports</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -918,7 +918,7 @@ IMPORT M3toC;
|
|||
</pre></div>
|
||||
|
||||
|
||||
<H3><a name="exceptions"></a>24.4.5 Exceptions</H3>
|
||||
<H3><a name="exceptions"></a>23.4.5 Exceptions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -942,7 +942,7 @@ you should declare
|
|||
<tt>%typemap("m3wrapinconv:throws") blah * %{OSError.E%}</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="typemap_example"></a>24.4.6 Example</H3>
|
||||
<H3><a name="typemap_example"></a>23.4.6 Example</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -989,10 +989,10 @@ where almost everything is generated by a typemap:
|
|||
</pre></div>
|
||||
|
||||
|
||||
<H2><a name="hints"></a>24.5 More hints to the generator</H2>
|
||||
<H2><a name="hints"></a>23.5 More hints to the generator</H2>
|
||||
|
||||
|
||||
<H3><a name="features"></a>24.5.1 Features</H3>
|
||||
<H3><a name="features"></a>23.5.1 Features</H3>
|
||||
|
||||
|
||||
<table border summary="Modula-3 features">
|
||||
|
|
@ -1029,7 +1029,7 @@ where almost everything is generated by a typemap:
|
|||
</tr>
|
||||
</table>
|
||||
|
||||
<H3><a name="pragmas"></a>24.5.2 Pragmas</H3>
|
||||
<H3><a name="pragmas"></a>23.5.2 Pragmas</H3>
|
||||
|
||||
|
||||
<table border summary="Modula-3 pragmas">
|
||||
|
|
@ -1052,7 +1052,7 @@ where almost everything is generated by a typemap:
|
|||
</tr>
|
||||
</table>
|
||||
|
||||
<H2><a name="remarks"></a>24.6 Remarks</H2>
|
||||
<H2><a name="remarks"></a>23.6 Remarks</H2>
|
||||
|
||||
|
||||
<ul>
|
||||
|
|
|
|||
|
|
@ -50,90 +50,41 @@ scripting language runtime as you would do for the single module case.
|
|||
|
||||
<p>
|
||||
A bit more complex is the case in which modules need to share information.
|
||||
For example, when one module extends the class of another by deriving from
|
||||
For example, when one module extends the class of the another by deriving from
|
||||
it:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
// File: base.h
|
||||
%module base
|
||||
|
||||
%inline %{
|
||||
class base {
|
||||
public:
|
||||
int foo();
|
||||
int foo(void);
|
||||
};
|
||||
</pre></div>
|
||||
|
||||
|
||||
<div class="code"><pre>
|
||||
// File: base_module.i
|
||||
%module base_module
|
||||
|
||||
%{
|
||||
#include "base.h"
|
||||
%}
|
||||
%include "base.h"
|
||||
</pre></div>
|
||||
|
||||
|
||||
<div class="code"><pre>
|
||||
// File: derived_module.i
|
||||
%module derived_module
|
||||
%module derived
|
||||
|
||||
%import "base_module.i"
|
||||
%import "base.i"
|
||||
|
||||
%inline %{
|
||||
class derived : public base {
|
||||
public:
|
||||
int bar();
|
||||
int bar(void);
|
||||
};
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p>To create the wrapper properly, module <tt>derived_module</tt> needs to know about the
|
||||
<tt>base</tt> class and that its interface is covered in another module. The
|
||||
line <tt>%import "base_module.i"</tt> lets SWIG know exactly that. Oftentimes
|
||||
the <tt>.h</tt> file is passed to <tt>%import</tt> instead of the <tt>.i</tt>,
|
||||
which unfortunately doesn't work for all language modules. For example, Python requires the
|
||||
name of module that the base class exists in so that the proxy classes can fully inherit the
|
||||
base class's methods. Typically you will get a warning when the module name is missing, eg:
|
||||
</p>
|
||||
|
||||
<div class="shell"> <pre>
|
||||
derived_module.i:8: Warning(401): Base class 'base' ignored - unknown module name for base. Either import
|
||||
the appropriate module interface file or specify the name of the module in the %import directive.
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
It is sometimes desirable to import the header file rather than the interface file and overcome
|
||||
the above warning.
|
||||
For example in the case of the imported interface being quite large, it may be desirable to
|
||||
simplify matters and just import a small header file of dependent types.
|
||||
This can be done by specifying the optional <tt>module</tt> attribute in the <tt>%import</tt> directive.
|
||||
The <tt>derived_module.i</tt> file shown above could be replaced with the following:
|
||||
|
||||
<div class="code"><pre>
|
||||
// File: derived_module.i
|
||||
%module derived_module
|
||||
|
||||
%import(module="base_module") "base.h"
|
||||
|
||||
%inline %{
|
||||
class derived : public base {
|
||||
public:
|
||||
int bar();
|
||||
};
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
Note that "base_module" is the module name and is the same as that specified in <tt>%module</tt>
|
||||
in <tt>base_module.i</tt> as well as the <tt>%import</tt> in <tt>derived_module.i</tt>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Another issue
|
||||
to beware of is that multiple dependent wrappers should not be linked/loaded
|
||||
<p>To create the wrapper properly, module <tt>derived</tt> needs to know the
|
||||
<tt>base</tt> class and that it's interface is covered in another module. The
|
||||
line <tt>%import "base.i"</tt> lets SWIG know exactly that. The common mistake here is
|
||||
to <tt>%import</tt> the <tt>.h</tt> file instead of the <tt>.i</tt>, which sadly won't do the trick. Another issue
|
||||
to take care of is that multiple dependent wrappers should not be linked/loaded
|
||||
in parallel from multiple threads as SWIG provides no locking - for more on that
|
||||
issue, read on.
|
||||
</p>
|
||||
issue, read on.</p>
|
||||
|
||||
<H2><a name="Modules_nn2"></a>15.2 The SWIG runtime code</H2>
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<H1><a name="MzScheme"></a>25 SWIG and MzScheme</H1>
|
||||
<H1><a name="MzScheme"></a>24 SWIG and MzScheme</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
<p>
|
||||
This section contains information on SWIG's support of MzScheme.
|
||||
|
||||
<H2><a name="MzScheme_nn2"></a>25.1 Creating native MzScheme structures</H2>
|
||||
<H2><a name="MzScheme_nn2"></a>24.1 Creating native MzScheme structures</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
<body bgcolor="#ffffff">
|
||||
<a name="n1"></a>
|
||||
<H1><a name="Ocaml"></a>26 SWIG and Ocaml</H1>
|
||||
<H1><a name="Ocaml"></a>25 SWIG and Ocaml</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -80,7 +80,7 @@ If you're not familiar with the Objective Caml language, you can visit
|
|||
<a href="http://www.ocaml.org/">The Ocaml Website</a>.
|
||||
</p>
|
||||
|
||||
<H2><a name="Ocaml_nn2"></a>26.1 Preliminaries</H2>
|
||||
<H2><a name="Ocaml_nn2"></a>25.1 Preliminaries</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -99,7 +99,7 @@ file Examples/Makefile illustrate how to compile and link SWIG modules that
|
|||
will be loaded dynamically. This has only been tested on Linux so far.
|
||||
</p>
|
||||
|
||||
<H3><a name="Ocaml_nn3"></a>26.1.1 Running SWIG</H3>
|
||||
<H3><a name="Ocaml_nn3"></a>25.1.1 Running SWIG</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -122,7 +122,7 @@ you will compile the file <tt>example_wrap.c</tt> with <tt>ocamlc</tt> or
|
|||
the resulting .ml and .mli files as well, and do the final link with -custom
|
||||
(not needed for native link). </p>
|
||||
|
||||
<H3><a name="Ocaml_nn4"></a>26.1.2 Compiling the code</H3>
|
||||
<H3><a name="Ocaml_nn4"></a>25.1.2 Compiling the code</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -158,7 +158,7 @@ the user more freedom with respect to custom typing.
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Ocaml_nn5"></a>26.1.3 The camlp4 module</H3>
|
||||
<H3><a name="Ocaml_nn5"></a>25.1.3 The camlp4 module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -234,7 +234,7 @@ let b = C_string (getenv "PATH")
|
|||
</td></tr>
|
||||
</table>
|
||||
|
||||
<H3><a name="Ocaml_nn6"></a>26.1.4 Using your module</H3>
|
||||
<H3><a name="Ocaml_nn6"></a>25.1.4 Using your module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -248,7 +248,7 @@ When linking any ocaml bytecode with your module, use the -custom
|
|||
option is not needed when you build native code.
|
||||
</p>
|
||||
|
||||
<H3><a name="Ocaml_nn7"></a>26.1.5 Compilation problems and compiling with C++</H3>
|
||||
<H3><a name="Ocaml_nn7"></a>25.1.5 Compilation problems and compiling with C++</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -259,7 +259,7 @@ liberal with pointer types may not compile under the C++ compiler.
|
|||
Most code meant to be compiled as C++ will not have problems.
|
||||
</p>
|
||||
|
||||
<H2><a name="Ocaml_nn8"></a>26.2 The low-level Ocaml/C interface</H2>
|
||||
<H2><a name="Ocaml_nn8"></a>25.2 The low-level Ocaml/C interface</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -360,7 +360,7 @@ is that you must append them to the return list with swig_result = caml_list_a
|
|||
signature for a function that uses value in this way.
|
||||
</p>
|
||||
|
||||
<H3><a name="Ocaml_nn9"></a>26.2.1 The generated module</H3>
|
||||
<H3><a name="Ocaml_nn9"></a>25.2.1 The generated module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -394,7 +394,7 @@ it describes the output SWIG will generate for class definitions.
|
|||
</td></tr>
|
||||
</table>
|
||||
|
||||
<H3><a name="Ocaml_nn10"></a>26.2.2 Enums</H3>
|
||||
<H3><a name="Ocaml_nn10"></a>25.2.2 Enums</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -457,7 +457,7 @@ val x : Enum_test.c_obj = C_enum `a
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H4><a name="Ocaml_nn11"></a>26.2.2.1 Enum typing in Ocaml</H4>
|
||||
<H4><a name="Ocaml_nn11"></a>25.2.2.1 Enum typing in Ocaml</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -470,10 +470,10 @@ functions imported from different modules. You must convert values to master
|
|||
values using the swig_val function before sharing them with another module.
|
||||
</p>
|
||||
|
||||
<H3><a name="Ocaml_nn12"></a>26.2.3 Arrays</H3>
|
||||
<H3><a name="Ocaml_nn12"></a>25.2.3 Arrays</H3>
|
||||
|
||||
|
||||
<H4><a name="Ocaml_nn13"></a>26.2.3.1 Simple types of bounded arrays</H4>
|
||||
<H4><a name="Ocaml_nn13"></a>25.2.3.1 Simple types of bounded arrays</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -494,7 +494,7 @@ arrays of simple types with known bounds in your code, but this only works
|
|||
for arrays whose bounds are completely specified.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn14"></a>26.2.3.2 Complex and unbounded arrays</H4>
|
||||
<H4><a name="Ocaml_nn14"></a>25.2.3.2 Complex and unbounded arrays</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -507,7 +507,7 @@ SWIG can't predict which of these methods will be used in the array,
|
|||
so you have to specify it for yourself in the form of a typemap.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn15"></a>26.2.3.3 Using an object</H4>
|
||||
<H4><a name="Ocaml_nn15"></a>25.2.3.3 Using an object</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -521,7 +521,7 @@ Consider writing an object when the ending condition of your array is complex,
|
|||
such as using a required sentinel, etc.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn16"></a>26.2.3.4 Example typemap for a function taking float * and int</H4>
|
||||
<H4><a name="Ocaml_nn16"></a>25.2.3.4 Example typemap for a function taking float * and int</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -572,7 +572,7 @@ void printfloats( float *tab, int len );
|
|||
</pre></td></tr></table>
|
||||
|
||||
|
||||
<H3><a name="Ocaml_nn17"></a>26.2.4 C++ Classes</H3>
|
||||
<H3><a name="Ocaml_nn17"></a>25.2.4 C++ Classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -615,7 +615,7 @@ the underlying pointer, so using create_[x]_from_ptr alters the
|
|||
returned value for the same object.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn18"></a>26.2.4.1 STL vector and string Example</H4>
|
||||
<H4><a name="Ocaml_nn18"></a>25.2.4.1 STL vector and string Example</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -695,7 +695,7 @@ baz
|
|||
#
|
||||
</pre></div>
|
||||
|
||||
<H4><a name="Ocaml_nn19"></a>26.2.4.2 C++ Class Example</H4>
|
||||
<H4><a name="Ocaml_nn19"></a>25.2.4.2 C++ Class Example</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -725,7 +725,7 @@ public:
|
|||
};
|
||||
</pre></td></tr></table>
|
||||
|
||||
<H4><a name="Ocaml_nn20"></a>26.2.4.3 Compiling the example</H4>
|
||||
<H4><a name="Ocaml_nn20"></a>25.2.4.3 Compiling the example</H4>
|
||||
|
||||
|
||||
<div class="code"><pre>
|
||||
|
|
@ -743,7 +743,7 @@ bash-2.05a$ ocamlmktop -custom swig.cmo -I `camlp4 -where` \
|
|||
-L$QTPATH/lib -cclib -lqt
|
||||
</pre></div>
|
||||
|
||||
<H4><a name="Ocaml_nn21"></a>26.2.4.4 Sample Session</H4>
|
||||
<H4><a name="Ocaml_nn21"></a>25.2.4.4 Sample Session</H4>
|
||||
|
||||
|
||||
<div class="code"><pre>
|
||||
|
|
@ -770,10 +770,10 @@ Assuming you have a working installation of QT, you will see a window
|
|||
containing the string "hi" in a button.
|
||||
</p>
|
||||
|
||||
<H3><a name="Ocaml_nn22"></a>26.2.5 Director Classes</H3>
|
||||
<H3><a name="Ocaml_nn22"></a>25.2.5 Director Classes</H3>
|
||||
|
||||
|
||||
<H4><a name="Ocaml_nn23"></a>26.2.5.1 Director Introduction</H4>
|
||||
<H4><a name="Ocaml_nn23"></a>25.2.5.1 Director Introduction</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -800,7 +800,7 @@ class foo {
|
|||
};
|
||||
</pre></div>
|
||||
|
||||
<H4><a name="Ocaml_nn24"></a>26.2.5.2 Overriding Methods in Ocaml</H4>
|
||||
<H4><a name="Ocaml_nn24"></a>25.2.5.2 Overriding Methods in Ocaml</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -828,7 +828,7 @@ In this example, I'll examine the objective caml code involved in providing
|
|||
an overloaded class. This example is contained in Examples/ocaml/shapes.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn25"></a>26.2.5.3 Director Usage Example</H4>
|
||||
<H4><a name="Ocaml_nn25"></a>25.2.5.3 Director Usage Example</H4>
|
||||
|
||||
|
||||
<table border="1" bgcolor="#dddddd" summary="Director usage example">
|
||||
|
|
@ -887,7 +887,7 @@ in a more effortless style in ocaml, while leaving the "engine" part of the
|
|||
program in C++.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn26"></a>26.2.5.4 Creating director objects</H4>
|
||||
<H4><a name="Ocaml_nn26"></a>25.2.5.4 Creating director objects</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -928,7 +928,7 @@ object from causing a core dump, as long as the object is destroyed
|
|||
properly.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn27"></a>26.2.5.5 Typemaps for directors, <tt>directorin, directorout, directorargout</tt></H4>
|
||||
<H4><a name="Ocaml_nn27"></a>25.2.5.5 Typemaps for directors, <tt>directorin, directorout, directorargout</tt></H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -939,7 +939,7 @@ well as a function return value in the same way you provide function arguments,
|
|||
and to receive arguments the same way you normally receive function returns.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn28"></a>26.2.5.6 <tt>directorin</tt> typemap</H4>
|
||||
<H4><a name="Ocaml_nn28"></a>25.2.5.6 <tt>directorin</tt> typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -950,7 +950,7 @@ code receives when you are called. In general, a simple <tt>directorin</tt> typ
|
|||
can use the same body as a simple <tt>out</tt> typemap.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn29"></a>26.2.5.7 <tt>directorout</tt> typemap</H4>
|
||||
<H4><a name="Ocaml_nn29"></a>25.2.5.7 <tt>directorout</tt> typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -961,7 +961,7 @@ for the same type, except when there are special requirements for object
|
|||
ownership, etc.
|
||||
</p>
|
||||
|
||||
<H4><a name="Ocaml_nn30"></a>26.2.5.8 <tt>directorargout</tt> typemap</H4>
|
||||
<H4><a name="Ocaml_nn30"></a>25.2.5.8 <tt>directorargout</tt> typemap</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -978,7 +978,7 @@ In the event that you don't specify all of the necessary values, integral
|
|||
values will read zero, and struct or object returns have undefined results.
|
||||
</p>
|
||||
|
||||
<H3><a name="Ocaml_nn31"></a>26.2.6 Exceptions</H3>
|
||||
<H3><a name="Ocaml_nn31"></a>25.2.6 Exceptions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<H1><a name="Octave"></a>27 SWIG and Octave</H1>
|
||||
<H1><a name="Octave"></a>26 SWIG and Octave</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -54,14 +54,14 @@ More information can be found at <a href="http://www.octave.org">www.octave.org<
|
|||
Also, there are a dozen or so examples in the Examples/octave directory, and hundreds in the test suite (Examples/test-suite and Examples/test-suite/octave).
|
||||
</p>
|
||||
|
||||
<H2><a name="Octave_nn2"></a>27.1 Preliminaries</H2>
|
||||
<H2><a name="Octave_nn2"></a>26.1 Preliminaries</H2>
|
||||
|
||||
|
||||
<p>
|
||||
The current SWIG implemention is based on Octave 2.9.12. Support for other versions (in particular the recent 3.0) has not been tested, nor has support for any OS other than Linux.
|
||||
</p>
|
||||
|
||||
<H2><a name="Octave_nn3"></a>27.2 Running SWIG</H2>
|
||||
<H2><a name="Octave_nn3"></a>26.2 Running SWIG</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -89,7 +89,7 @@ This creates a C/C++ source file <tt>example_wrap.cxx</tt>. The generated C++ so
|
|||
The swig command line has a number of options you can use, like to redirect it's output. Use <tt>swig --help</tt> to learn about these.
|
||||
</p>
|
||||
|
||||
<H3><a name="Octave_nn5"></a>27.2.1 Compiling a dynamic module</H3>
|
||||
<H3><a name="Octave_nn5"></a>26.2.1 Compiling a dynamic module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -116,7 +116,7 @@ $ mkoctfile example_wrap.cxx example.c
|
|||
|
||||
<div class="targetlang"><pre>octave:1> example</pre></div>
|
||||
|
||||
<H3><a name="Octave_nn6"></a>27.2.2 Using your module</H3>
|
||||
<H3><a name="Octave_nn6"></a>26.2.2 Using your module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -134,10 +134,10 @@ octave:4> example.cvar.Foo=4;
|
|||
octave:5> example.cvar.Foo
|
||||
ans = 4 </pre></div>
|
||||
|
||||
<H2><a name="Octave_nn7"></a>27.3 A tour of basic C/C++ wrapping</H2>
|
||||
<H2><a name="Octave_nn7"></a>26.3 A tour of basic C/C++ wrapping</H2>
|
||||
|
||||
|
||||
<H3><a name="Octave_nn8"></a>27.3.1 Modules</H3>
|
||||
<H3><a name="Octave_nn8"></a>26.3.1 Modules</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -179,7 +179,7 @@ One can also rename it by simple assignment, e.g.,
|
|||
octave:1> some_vars = cvar;
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Octave_nn9"></a>27.3.2 Functions</H3>
|
||||
<H3><a name="Octave_nn9"></a>26.3.2 Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -196,7 +196,7 @@ int fact(int n); </pre></div>
|
|||
<div class="targetlang"><pre>octave:1> example.fact(4)
|
||||
24 </pre></div>
|
||||
|
||||
<H3><a name="Octave_nn10"></a>27.3.3 Global variables</H3>
|
||||
<H3><a name="Octave_nn10"></a>26.3.3 Global variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -249,7 +249,7 @@ octave:2> example.PI=3.142;
|
|||
octave:3> example.PI
|
||||
ans = 3.1420 </pre></div>
|
||||
|
||||
<H3><a name="Octave_nn11"></a>27.3.4 Constants and enums</H3>
|
||||
<H3><a name="Octave_nn11"></a>26.3.4 Constants and enums</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -271,7 +271,7 @@ example.SCONST="Hello World"
|
|||
example.SUNDAY=0
|
||||
.... </pre></div>
|
||||
|
||||
<H3><a name="Octave_nn12"></a>27.3.5 Pointers</H3>
|
||||
<H3><a name="Octave_nn12"></a>26.3.5 Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -318,7 +318,7 @@ octave:2> f=example.fopen("not there","r");
|
|||
error: value on right hand side of assignment is undefined
|
||||
error: evaluating assignment expression near line 2, column 2 </pre></div>
|
||||
|
||||
<H3><a name="Octave_nn13"></a>27.3.6 Structures and C++ classes</H3>
|
||||
<H3><a name="Octave_nn13"></a>26.3.6 Structures and C++ classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -453,7 +453,7 @@ ans = 1
|
|||
Depending on the ownership setting of a <tt>swig_ref</tt>, it may call C++ destructors when its reference count goes to zero. See the section on memory management below for details.
|
||||
</p>
|
||||
|
||||
<H3><a name="Octave_nn15"></a>27.3.7 C++ inheritance</H3>
|
||||
<H3><a name="Octave_nn15"></a>26.3.7 C++ inheritance</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -462,7 +462,7 @@ This information contains the full class hierarchy. When an indexing operation (
|
|||
the tree is walked to find a match in the current class as well as any of its bases. The lookup is then cached in the <tt>swig_ref</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="Octave_nn17"></a>27.3.8 C++ overloaded functions</H3>
|
||||
<H3><a name="Octave_nn17"></a>26.3.8 C++ overloaded functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -472,7 +472,7 @@ The dispatch function selects which overload to call (if any) based on the passe
|
|||
<tt>typecheck</tt> typemaps are used to analyze each argument, as well as assign precedence. See the chapter on typemaps for details.
|
||||
</p>
|
||||
|
||||
<H3><a name="Octave_nn18"></a>27.3.9 C++ operators</H3>
|
||||
<H3><a name="Octave_nn18"></a>26.3.9 C++ operators</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -572,7 +572,7 @@ On the C++ side, the default mappings are as follows:
|
|||
%rename(__brace) *::operator[];
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Octave_nn19"></a>27.3.10 Class extension with %extend</H3>
|
||||
<H3><a name="Octave_nn19"></a>26.3.10 Class extension with %extend</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -602,7 +602,7 @@ octave:3> printf("%s\n",a);
|
|||
octave:4> a.__str()
|
||||
4
|
||||
</pre></div>
|
||||
<H3><a name="Octave_nn20"></a>27.3.11 C++ templates</H3>
|
||||
<H3><a name="Octave_nn20"></a>26.3.11 C++ templates</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -679,14 +679,14 @@ ans =
|
|||
</pre></div>
|
||||
|
||||
|
||||
<H3><a name="Octave_nn21"></a>27.3.12 C++ Smart Pointers</H3>
|
||||
<H3><a name="Octave_nn21"></a>26.3.12 C++ Smart Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
C++ smart pointers are fully supported as in other modules.
|
||||
</p>
|
||||
|
||||
<H3><a name="Octave_nn22"></a>27.3.13 Directors (calling Octave from C++ code)</H3>
|
||||
<H3><a name="Octave_nn22"></a>26.3.13 Directors (calling Octave from C++ code)</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -766,14 +766,14 @@ c-side routine called
|
|||
octave-side routine called
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Octave_nn23"></a>27.3.14 Threads</H3>
|
||||
<H3><a name="Octave_nn23"></a>26.3.14 Threads</H3>
|
||||
|
||||
|
||||
<p>
|
||||
The use of threads in wrapped Director code is not supported; i.e., an Octave-side implementation of a C++ class must be called from the Octave interpreter's thread. Anything fancier (apartment/queue model, whatever) is left to the user. Without anything fancier, this amounts to the limitation that Octave must drive the module... like, for example, an optimization package that calls Octave to evaluate an objective function.
|
||||
</p>
|
||||
|
||||
<H3><a name="Octave_nn24"></a>27.3.15 Memory management</H3>
|
||||
<H3><a name="Octave_nn24"></a>26.3.15 Memory management</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -807,14 +807,14 @@ The %newobject directive may be used to control this behavior for pointers retur
|
|||
In the case where one wishes for the C++ side to own an object that was created in Octave (especially a Director object), one can use the __disown() method to invert this logic. Then letting the Octave reference count go to zero will not destroy the object, but destroying the object will invalidate the Octave-side object if it still exists (and call destructors of other C++ bases in the case of multiple inheritance/<tt>subclass()</tt>'ing).
|
||||
</p>
|
||||
|
||||
<H3><a name="Octave_nn25"></a>27.3.16 STL support</H3>
|
||||
<H3><a name="Octave_nn25"></a>26.3.16 STL support</H3>
|
||||
|
||||
|
||||
<p>
|
||||
This is some skeleton support for various STL containers.
|
||||
</p>
|
||||
|
||||
<H3><a name="Octave_nn26"></a>27.3.17 Matrix typemaps</H3>
|
||||
<H3><a name="Octave_nn26"></a>26.3.17 Matrix typemaps</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Perl5"></a>28 SWIG and Perl5</H1>
|
||||
<H1><a name="Perl5"></a>27 SWIG and Perl5</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -87,7 +87,7 @@ later. Earlier versions are problematic and SWIG generated extensions
|
|||
may not compile or run correctly.
|
||||
</p>
|
||||
|
||||
<H2><a name="Perl5_nn2"></a>28.1 Overview</H2>
|
||||
<H2><a name="Perl5_nn2"></a>27.1 Overview</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -108,7 +108,7 @@ described. Advanced customization features, typemaps, and other
|
|||
options are found near the end of the chapter.
|
||||
</p>
|
||||
|
||||
<H2><a name="Perl5_nn3"></a>28.2 Preliminaries</H2>
|
||||
<H2><a name="Perl5_nn3"></a>27.2 Preliminaries</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -133,7 +133,7 @@ To build the module, you will need to compile the file
|
|||
<tt>example_wrap.c</tt> and link it with the rest of your program.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn4"></a>28.2.1 Getting the right header files</H3>
|
||||
<H3><a name="Perl5_nn4"></a>27.2.1 Getting the right header files</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -165,7 +165,7 @@ loaded, an easy way to find out is to run Perl itself.
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Perl5_nn5"></a>28.2.2 Compiling a dynamic module</H3>
|
||||
<H3><a name="Perl5_nn5"></a>27.2.2 Compiling a dynamic module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -198,7 +198,7 @@ the target should be named `<tt>example.so</tt>',
|
|||
`<tt>example.sl</tt>', or the appropriate dynamic module name on your system.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn6"></a>28.2.3 Building a dynamic module with MakeMaker</H3>
|
||||
<H3><a name="Perl5_nn6"></a>27.2.3 Building a dynamic module with MakeMaker</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -232,7 +232,7 @@ the preferred approach to compilation. More information about MakeMaker can be
|
|||
found in "Programming Perl, 2nd ed." by Larry Wall, Tom Christiansen,
|
||||
and Randal Schwartz.</p>
|
||||
|
||||
<H3><a name="Perl5_nn7"></a>28.2.4 Building a static version of Perl</H3>
|
||||
<H3><a name="Perl5_nn7"></a>27.2.4 Building a static version of Perl</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -301,7 +301,7 @@ added to it. Depending on your machine, you may need to link with
|
|||
additional libraries such as <tt>-lsocket, -lnsl, -ldl</tt>, etc.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn8"></a>28.2.5 Using the module</H3>
|
||||
<H3><a name="Perl5_nn8"></a>27.2.5 Using the module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -456,7 +456,7 @@ system configuration (this requires root access and you will need to
|
|||
read the man pages).
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn9"></a>28.2.6 Compilation problems and compiling with C++</H3>
|
||||
<H3><a name="Perl5_nn9"></a>27.2.6 Compilation problems and compiling with C++</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -599,7 +599,7 @@ have to find the macro that conflicts and add an #undef into the .i file. Pleas
|
|||
any conflicting macros you find to <a href="http://www.swig.org/mail.html">swig-user mailing list</a>.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn10"></a>28.2.7 Compiling for 64-bit platforms</H3>
|
||||
<H3><a name="Perl5_nn10"></a>27.2.7 Compiling for 64-bit platforms</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -626,7 +626,7 @@ also introduce problems on platforms that support more than one
|
|||
linking standard (e.g., -o32 and -n32 on Irix).
|
||||
</p>
|
||||
|
||||
<H2><a name="Perl5_nn11"></a>28.3 Building Perl Extensions under Windows</H2>
|
||||
<H2><a name="Perl5_nn11"></a>27.3 Building Perl Extensions under Windows</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -637,7 +637,7 @@ section assumes you are using SWIG with Microsoft Visual C++
|
|||
although the procedure may be similar with other compilers.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn12"></a>28.3.1 Running SWIG from Developer Studio</H3>
|
||||
<H3><a name="Perl5_nn12"></a>27.3.1 Running SWIG from Developer Studio</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -700,7 +700,7 @@ print "$a\n";
|
|||
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Perl5_nn13"></a>28.3.2 Using other compilers</H3>
|
||||
<H3><a name="Perl5_nn13"></a>27.3.2 Using other compilers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -708,7 +708,7 @@ SWIG is known to work with Cygwin and may work with other compilers on Windows.
|
|||
For general hints and suggestions refer to the <a href="Windows.html#Windows">Windows</a> chapter.
|
||||
</p>
|
||||
|
||||
<H2><a name="Perl5_nn14"></a>28.4 The low-level interface</H2>
|
||||
<H2><a name="Perl5_nn14"></a>27.4 The low-level interface</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -718,7 +718,7 @@ can be used to control your application. However, it is also used to
|
|||
construct more user-friendly proxy classes as described in the next section.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn15"></a>28.4.1 Functions</H3>
|
||||
<H3><a name="Perl5_nn15"></a>27.4.1 Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -741,7 +741,7 @@ use example;
|
|||
$a = &example::fact(2);
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Perl5_nn16"></a>28.4.2 Global variables</H3>
|
||||
<H3><a name="Perl5_nn16"></a>27.4.2 Global variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -811,7 +811,7 @@ extern char *path; // Declared later in the input
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Perl5_nn17"></a>28.4.3 Constants</H3>
|
||||
<H3><a name="Perl5_nn17"></a>27.4.3 Constants</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -838,7 +838,7 @@ $example::FOO = 2; # Error
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Perl5_nn18"></a>28.4.4 Pointers</H3>
|
||||
<H3><a name="Perl5_nn18"></a>27.4.4 Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -947,7 +947,7 @@ as XS and <tt>xsubpp</tt>. Given the advancement of the SWIG typesystem and the
|
|||
SWIG and XS, this is no longer supported.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn19"></a>28.4.5 Structures</H3>
|
||||
<H3><a name="Perl5_nn19"></a>27.4.5 Structures</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1081,7 +1081,7 @@ void Bar_f_set(Bar *b, Foo *val) {
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="Perl5_nn20"></a>28.4.6 C++ classes</H3>
|
||||
<H3><a name="Perl5_nn20"></a>27.4.6 C++ classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1146,7 +1146,7 @@ provides direct access to C++ objects. A higher level interface using Perl prox
|
|||
can be built using these low-level accessors. This is described shortly.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn21"></a>28.4.7 C++ classes and type-checking</H3>
|
||||
<H3><a name="Perl5_nn21"></a>27.4.7 C++ classes and type-checking</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1182,7 +1182,7 @@ If necessary, the type-checker also adjusts the value of the pointer (as is nece
|
|||
multiple inheritance is used).
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn22"></a>28.4.8 C++ overloaded functions</H3>
|
||||
<H3><a name="Perl5_nn22"></a>27.4.8 C++ overloaded functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1226,7 +1226,7 @@ example::Spam_foo_d($s,3.14);
|
|||
Please refer to the "SWIG Basics" chapter for more information.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn23"></a>28.4.9 Operators</H3>
|
||||
<H3><a name="Perl5_nn23"></a>27.4.9 Operators</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1253,7 +1253,7 @@ The following C++ operators are currently supported by the Perl module:
|
|||
<li>operator or </li>
|
||||
</ul>
|
||||
|
||||
<H3><a name="Perl5_nn24"></a>28.4.10 Modules and packages</H3>
|
||||
<H3><a name="Perl5_nn24"></a>27.4.10 Modules and packages</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1348,7 +1348,7 @@ print Foo::fact(4),"\n"; # Call a function in package FooBar
|
|||
</pre></div>
|
||||
-->
|
||||
|
||||
<H2><a name="Perl5_nn25"></a>28.5 Input and output parameters</H2>
|
||||
<H2><a name="Perl5_nn25"></a>27.5 Input and output parameters</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1567,7 +1567,7 @@ print "$c\n";
|
|||
<b>Note:</b> The <tt>REFERENCE</tt> feature is only currently supported for numeric types (integers and floating point).
|
||||
</p>
|
||||
|
||||
<H2><a name="Perl5_nn26"></a>28.6 Exception handling </H2>
|
||||
<H2><a name="Perl5_nn26"></a>27.6 Exception handling </H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1732,7 +1732,7 @@ This is still supported, but it is deprecated. The newer <tt>%exception</tt> di
|
|||
functionality, but it has additional capabilities that make it more powerful.
|
||||
</p>
|
||||
|
||||
<H2><a name="Perl5_nn27"></a>28.7 Remapping datatypes with typemaps</H2>
|
||||
<H2><a name="Perl5_nn27"></a>27.7 Remapping datatypes with typemaps</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1749,7 +1749,7 @@ Typemaps are only used if you want to change some aspect of the primitive
|
|||
C-Perl interface.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn28"></a>28.7.1 A simple typemap example</H3>
|
||||
<H3><a name="Perl5_nn28"></a>27.7.1 A simple typemap example</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1853,7 +1853,7 @@ example::count("e","Hello World");
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="Perl5_nn29"></a>28.7.2 Perl5 typemaps</H3>
|
||||
<H3><a name="Perl5_nn29"></a>27.7.2 Perl5 typemaps</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1958,7 +1958,7 @@ Return of C++ member data (all languages).
|
|||
Check value of input parameter.
|
||||
</div>
|
||||
|
||||
<H3><a name="Perl5_nn30"></a>28.7.3 Typemap variables</H3>
|
||||
<H3><a name="Perl5_nn30"></a>27.7.3 Typemap variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2029,7 +2029,7 @@ properly assigned.
|
|||
The Perl name of the wrapper function being created.
|
||||
</div>
|
||||
|
||||
<H3><a name="Perl5_nn31"></a>28.7.4 Useful functions</H3>
|
||||
<H3><a name="Perl5_nn31"></a>27.7.4 Useful functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2098,7 +2098,7 @@ int sv_isa(SV *, char *0;
|
|||
</div>
|
||||
|
||||
|
||||
<H2><a name="Perl5_nn32"></a>28.8 Typemap Examples</H2>
|
||||
<H2><a name="Perl5_nn32"></a>27.8 Typemap Examples</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2107,7 +2107,7 @@ might look at the files "<tt>perl5.swg</tt>" and "<tt>typemaps.i</tt>" in
|
|||
the SWIG library.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn33"></a>28.8.1 Converting a Perl5 array to a char ** </H3>
|
||||
<H3><a name="Perl5_nn33"></a>27.8.1 Converting a Perl5 array to a char ** </H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2199,7 +2199,7 @@ print @$b,"\n"; # Print it out
|
|||
</pre></div>
|
||||
|
||||
|
||||
<H3><a name="Perl5_nn34"></a>28.8.2 Return values </H3>
|
||||
<H3><a name="Perl5_nn34"></a>27.8.2 Return values </H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2228,7 +2228,7 @@ can be done using the <tt>EXTEND()</tt> macro as in :
|
|||
}
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Perl5_nn35"></a>28.8.3 Returning values from arguments</H3>
|
||||
<H3><a name="Perl5_nn35"></a>27.8.3 Returning values from arguments</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2282,7 +2282,7 @@ print "multout(7,13) = @r\n";
|
|||
($x,$y) = multout(7,13);
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Perl5_nn36"></a>28.8.4 Accessing array structure members</H3>
|
||||
<H3><a name="Perl5_nn36"></a>27.8.4 Accessing array structure members</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2345,7 +2345,7 @@ the "in" typemap in the previous section would be used to convert an
|
|||
to copy the converted array into a C data structure.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn37"></a>28.8.5 Turning Perl references into C pointers</H3>
|
||||
<H3><a name="Perl5_nn37"></a>27.8.5 Turning Perl references into C pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2410,7 +2410,7 @@ print "$c\n";
|
|||
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Perl5_nn38"></a>28.8.6 Pointer handling</H3>
|
||||
<H3><a name="Perl5_nn38"></a>27.8.6 Pointer handling</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2489,7 +2489,7 @@ For example:
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="Perl5_nn39"></a>28.9 Proxy classes</H2>
|
||||
<H2><a name="Perl5_nn39"></a>27.9 Proxy classes</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2505,7 +2505,7 @@ to the underlying code. This section describes the implementation
|
|||
details of the proxy interface.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn40"></a>28.9.1 Preliminaries</H3>
|
||||
<H3><a name="Perl5_nn40"></a>27.9.1 Preliminaries</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2527,7 +2527,7 @@ SWIG creates a collection of high-level Perl wrappers. In your scripts, you wil
|
|||
high level wrappers. The wrappers, in turn, interact with the low-level procedural module.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn41"></a>28.9.2 Structure and class wrappers</H3>
|
||||
<H3><a name="Perl5_nn41"></a>27.9.2 Structure and class wrappers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2653,7 +2653,7 @@ $v->DESTROY();
|
|||
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Perl5_nn42"></a>28.9.3 Object Ownership</H3>
|
||||
<H3><a name="Perl5_nn42"></a>27.9.3 Object Ownership</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2740,7 +2740,7 @@ counting, garbage collection, or advanced features one might find in
|
|||
sophisticated languages.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn43"></a>28.9.4 Nested Objects</H3>
|
||||
<H3><a name="Perl5_nn43"></a>27.9.4 Nested Objects</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2793,7 +2793,7 @@ $p->{f}->{x} = 0.0;
|
|||
%${$p->{v}} = ( x=>0, y=>0, z=>0);
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Perl5_nn44"></a>28.9.5 Proxy Functions</H3>
|
||||
<H3><a name="Perl5_nn44"></a>27.9.5 Proxy Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2827,7 +2827,7 @@ This function replaces the original function, but operates in an
|
|||
identical manner.
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn45"></a>28.9.6 Inheritance</H3>
|
||||
<H3><a name="Perl5_nn45"></a>27.9.6 Inheritance</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2903,7 +2903,7 @@ particular, inheritance of data members is extremely tricky (and I'm
|
|||
not even sure if it really works).
|
||||
</p>
|
||||
|
||||
<H3><a name="Perl5_nn46"></a>28.9.7 Modifying the proxy methods</H3>
|
||||
<H3><a name="Perl5_nn46"></a>27.9.7 Modifying the proxy methods</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2931,7 +2931,7 @@ public:
|
|||
};
|
||||
</pre></div>
|
||||
|
||||
<H2><a name="Perl5_nn47"></a>28.10 Adding additional Perl code</H2>
|
||||
<H2><a name="Perl5_nn47"></a>27.10 Adding additional Perl code</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -7,13 +7,14 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Php"></a>29 SWIG and PHP</H1>
|
||||
<H1><a name="Php"></a>28 SWIG and PHP</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
<li><a href="#Php_nn1">Generating PHP Extensions</a>
|
||||
<ul>
|
||||
<li><a href="#Php_nn1_1">Building a loadable extension</a>
|
||||
<li><a href="#Php_nn1_2">Building extensions into PHP</a>
|
||||
<li><a href="#Php_nn1_3">Using PHP Extensions</a>
|
||||
</ul>
|
||||
<li><a href="#Php_nn2">Basic PHP interface</a>
|
||||
|
|
@ -42,24 +43,21 @@
|
|||
<b>Caution: This chapter (and module!) is still under construction</b>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
SWIG supports generating wrappers for PHP5. Support for PHP4 has been removed
|
||||
as of SWIG 1.3.37. The PHP developers are no longer making new PHP4 releases,
|
||||
and won't even be patching critical security issues after 2008-08-08, so it
|
||||
doesn't make much sense for SWIG to continue to support PHP4 at this point.
|
||||
If you need to continue to use PHP4, stick with SWIG 1.3.36.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
In this chapter, we discuss SWIG's support of PHP. The PHP module
|
||||
was extensively rewritten in release 1.3.26, and support for generating
|
||||
OO wrappers for PHP5 was added in 1.3.30. The PHP module works fairly
|
||||
well, but currently does not implement all the
|
||||
was extensively rewritten in release 1.3.26, and although it is
|
||||
significantly more functional, it still does not implement all the
|
||||
features available in some of the other languages.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
In order to use this module, you will need to have a copy of the PHP5
|
||||
The examples and test cases have been developed with PHP4. Release
|
||||
1.3.30 added support for generating PHP5 class wrappers for C++
|
||||
libraries.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
In order to use this module, you will need to have a copy of the PHP4 or PHP5
|
||||
include files to compile the SWIG generated files. If you installed
|
||||
PHP from a binary package, you may need to install a "php-dev" or "php-devel"
|
||||
package for these to be installed. You can find out where these files are
|
||||
|
|
@ -69,7 +67,7 @@ your extension into php directly, you will need the complete PHP source tree
|
|||
available.
|
||||
</p>
|
||||
|
||||
<H2><a name="Php_nn1"></a>29.1 Generating PHP Extensions</H2>
|
||||
<H2><a name="Php_nn1"></a>28.1 Generating PHP Extensions</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -90,7 +88,7 @@ you wish to statically link the extension into the php interpreter.
|
|||
The third file,
|
||||
<tt>example.php</tt> can be included by PHP scripts. It attempts to
|
||||
dynamically load the extension and contains extra php code specified
|
||||
in the interface file. If wrapping C++ code with PHP classes, it will
|
||||
in the interface file. If wrapping C++ code for PHP5, it will
|
||||
also contain PHP5 class wrappers.
|
||||
</p>
|
||||
|
||||
|
|
@ -102,8 +100,7 @@ more detail in <a href="#Php_nn2_6">section 27.2.6</a>.
|
|||
|
||||
<p>
|
||||
The usual (and recommended) way is to build the extension as a separate
|
||||
dynamically loaded module (which is supported by all modern operating
|
||||
systems). You can then specify that this be loaded
|
||||
dynamically loaded module. You can then specify that this be loaded
|
||||
automatically in <tt>php.ini</tt> or load it explicitly for any script which
|
||||
needs it.
|
||||
</p>
|
||||
|
|
@ -113,16 +110,17 @@ It is also possible to rebuild PHP from source so that your module is
|
|||
statically linked into the php executable/library. This is a lot more
|
||||
work, and also requires a full rebuild of PHP to update your module,
|
||||
and it doesn't play nicely with package system. We don't recommend
|
||||
this approach, or provide explicit support for it.
|
||||
this approach, but if you really want to do this, the <tt>-phpfull</tt>
|
||||
command line argument to swig may be of use - see below for details.
|
||||
</p>
|
||||
|
||||
<H3><a name="Php_nn1_1"></a>29.1.1 Building a loadable extension</H3>
|
||||
<H3><a name="Php_nn1_1"></a>28.1.1 Building a loadable extension</H3>
|
||||
|
||||
|
||||
<p>
|
||||
To build your module as a dynamically loadable extension, use compilation
|
||||
commands like these (if you aren't using GCC, the commands will be different,
|
||||
and there may be some variation between platforms - these commands should at
|
||||
and there may be so variation between platforms - these commands should at
|
||||
least work for Linux though):
|
||||
</p>
|
||||
|
||||
|
|
@ -131,7 +129,135 @@ least work for Linux though):
|
|||
gcc -shared example_wrap.o -o example.so
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Php_nn1_3"></a>29.1.2 Using PHP Extensions</H3>
|
||||
<p>
|
||||
There is a deprecated <tt>-make</tt> command line argument to swig which will
|
||||
generate an additional file <tt>makefile</tt> which can usually build the
|
||||
extension (at least on some UNIX platforms), but the Makefile generated isn't
|
||||
very flexible, and the commands required are trivial so it is simpler to just
|
||||
add them to your Makefile or other build system directly. We recommend that
|
||||
you don't use <tt>-make</tt> and it's likely to be removed at some point.
|
||||
</p>
|
||||
|
||||
<H3><a name="Php_nn1_2"></a>28.1.2 Building extensions into PHP</H3>
|
||||
|
||||
|
||||
<p>
|
||||
Note that we don't recommend this approach - it's cleaner and simpler to
|
||||
use dynamically loadable modules, which are supported by all modern OSes.
|
||||
Support for this may be discontinued entirely in the future.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
It is possible to rebuild PHP itself with your module statically linked
|
||||
in. To do this, you can use the <tt>-phpfull</tt> command line option to
|
||||
swig. Using this option will generate three additional files. The first
|
||||
extra file, <tt>config.m4</tt> contains the m4 and shell code needed to
|
||||
enable the extension as part of the PHP build process. The second
|
||||
extra file, <tt>Makefile.in</tt> contains the information needed to
|
||||
build the final Makefile after substitutions. The third and final
|
||||
extra file, <tt>CREDITS</tt> should contain the credits for the
|
||||
extension.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To build with phpize, after you have run swig you will need to run the
|
||||
'phpize' command (installed as part of php) in the same
|
||||
directory. This re-creates the php build environment in that
|
||||
directory. It also creates a configure file which includes the shell
|
||||
code from the config.m4 that was generated by SWIG, this configure
|
||||
script will accept a command line argument to enable the extension to
|
||||
be run (by default the command line argument is --enable-modulename,
|
||||
however you can edit the config.m4 file before running phpize to
|
||||
accept --with-modulename. You can also add extra tests in config.m4 to
|
||||
check that a correct library version is installed or correct header
|
||||
files are included, etc, but you must edit this file before running
|
||||
phpize.) You can also get SWIG to generate simple extra tests for
|
||||
libraries and header files for you.
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
swig -php -phpfull
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
If you depend on source files not generated by SWIG, before generating
|
||||
the configure file, you may need to edit the <tt>Makefile.in</tt>
|
||||
file. This contains the names of the source files to compile (just the
|
||||
wrapper file by default) and any additional libraries needed to be
|
||||
linked in. If there are extra C files to compile, you will need to add
|
||||
them to the <tt>Makefile.in</tt>, or add the names of libraries if they are
|
||||
needed. In simple cases SWIG is pretty good at generating a complete
|
||||
<tt>Makefile.in</tt> and <tt>config.m4</tt> which need no further editing.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You then run the configure script with the command line argument needed
|
||||
to enable the extension. Then run make, which builds the extension.
|
||||
The extension object file will be left in the modules sub directory, you can
|
||||
move it to wherever it is convenient to call from your php script.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
When using <tt>-phpfull</tt>, swig also accepts the following
|
||||
additional optional arguments:
|
||||
</p>
|
||||
<ul>
|
||||
<li><tt>-withincs "<incs>"</tt> Adds include files to the config.m4 file.
|
||||
<li><tt>-withlibs "<libs>"</tt> Links with the specified libraries.
|
||||
<li><tt>-withc "<files>"</tt> Compiles and links the additional specified C files.
|
||||
<li><tt>-withcxx "<files>"</tt> Compiles and links the additional specified C++ files.
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
After running swig with the <tt>-phpfull</tt> switch, you will be left with a shockingly
|
||||
similar set of files to the previous build process. However you will then need
|
||||
to move these files to a subdirectory within the php source tree, this subdirectory you will need to create under the ext directory, with the name of the extension (e.g. <tt>mkdir php-4.0.6/ext/modulename</tt>).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
After moving the files into this directory, you will need to run the 'buildall'
|
||||
script in the php source directory. This rebuilds the configure script
|
||||
and includes the extra command line arguments from the module you have added.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Before running the generated configure file, you may need to edit the <tt>
|
||||
Makefile.in</tt>. This contains the names of the source files to compile (
|
||||
just the wrapper file by default) and any additional libraries needed to
|
||||
link in. If there are extra C files to compile you will need to add them
|
||||
to the Makefile, or add the names of libraries if they are needed.
|
||||
In most cases <tt>Makefile.in</tt> will be complete, especially if you
|
||||
make use of <tt>-withlibs</tt> and <tt>-withincs</tt>
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
swig -php -phpfull -withlibs "xapian omquery" --withincs "om.h"
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
Will include in the <tt>config.m4</tt> and <tt>Makefile.in</tt> search for
|
||||
<tt>libxapian.a</tt> or <tt>libxapian.so</tt> and search for
|
||||
<tt>libomquery.a</tt> or <tt>libomquery.so</tt> as well as a
|
||||
search for <tt>om.h</tt>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You then need to run the configure command and pass the necessary command
|
||||
line arguments to enable your module (by default this is --enable-modulename,
|
||||
but this can be changed by editing the config.m4 file in the modules directory
|
||||
before running the buildall script. In addition, extra tests can be added to
|
||||
the config.m4 file to ensure the correct libraries and header files are
|
||||
installed.)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Once configure has completed, you can run make to build php. If this all
|
||||
compiles correctly, you should end up with a php executable/library
|
||||
which contains your new module. You can test it with a php script which
|
||||
does not have the 'dl' command as used above.
|
||||
</p>
|
||||
|
||||
<H3><a name="Php_nn1_3"></a>28.1.3 Using PHP Extensions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -162,7 +288,7 @@ attempts to do the <tt>dl()</tt> call for you:
|
|||
include("example.php");
|
||||
</pre></div>
|
||||
|
||||
<H2><a name="Php_nn2"></a>29.2 Basic PHP interface</H2>
|
||||
<H2><a name="Php_nn2"></a>28.2 Basic PHP interface</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -172,7 +298,7 @@ possible for names of symbols in one extension module to clash with
|
|||
other symbols unless care is taken to <tt>%rename</tt> them.
|
||||
</p>
|
||||
|
||||
<H3><a name="Php_nn2_1"></a>29.2.1 Constants</H3>
|
||||
<H3><a name="Php_nn2_1"></a>28.2.1 Constants</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -297,7 +423,7 @@ both point to the same value, without the case test taking place. (
|
|||
Apologies, this paragraph needs rewriting to make some sense. )
|
||||
</p>
|
||||
|
||||
<H3><a name="Php_nn2_2"></a>29.2.2 Global Variables</H3>
|
||||
<H3><a name="Php_nn2_2"></a>28.2.2 Global Variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -346,7 +472,7 @@ undefined.
|
|||
At this time SWIG does not support custom accessor methods.
|
||||
</p>
|
||||
|
||||
<H3><a name="Php_nn2_3"></a>29.2.3 Functions</H3>
|
||||
<H3><a name="Php_nn2_3"></a>28.2.3 Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -399,7 +525,7 @@ print $s; # The value of $s was not changed.
|
|||
-->
|
||||
|
||||
|
||||
<H3><a name="Php_nn2_4"></a>29.2.4 Overloading</H3>
|
||||
<H3><a name="Php_nn2_4"></a>28.2.4 Overloading</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -413,7 +539,7 @@ Overloaded Functions and Methods</a>.
|
|||
|
||||
<!-- This isn't correct for 1.3.30 and needs rewriting to reflect reality
|
||||
<p>
|
||||
Because PHP is a dynamically typed language, simple values can be
|
||||
Because PHP4 is a dynamically typed language, simple values can be
|
||||
silently converted from one type to another. For example, integers,
|
||||
doubles and strings silently convert to each other depending on
|
||||
context. This situation make overloading slightly problematic because
|
||||
|
|
@ -433,7 +559,7 @@ PHP. The string <tt>"2"</tt> simultaneously represents the integer
|
|||
|
||||
<p>
|
||||
In order to provide the most natural experience to PHP programmers,
|
||||
the default <tt>%typecheck</tt> implemented in <tt>php.swg</tt>
|
||||
the default <tt>%typecheck</tt> implemented in <tt>php4.swg</tt>
|
||||
allows any simple type (integer, double, string) in PHP to be used for
|
||||
any simple C type (int, double, char *). The function selected then
|
||||
depends only on the argument type precedence defined by SWIG.
|
||||
|
|
@ -455,7 +581,7 @@ taking the integer argument.
|
|||
</p>
|
||||
-->
|
||||
|
||||
<H3><a name="Php_nn2_5"></a>29.2.5 Pointers and References</H3>
|
||||
<H3><a name="Php_nn2_5"></a>28.2.5 Pointers and References</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -587,13 +713,24 @@ PHP in a number of ways: by using <tt>unset</tt> on an existing
|
|||
variable, or assigning <tt>NULL</tt> to a variable.
|
||||
</p>
|
||||
|
||||
<H3><a name="Php_nn2_6"></a>29.2.6 Structures and C++ classes</H3>
|
||||
<H3><a name="Php_nn2_6"></a>28.2.6 Structures and C++ classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
SWIG defaults to wrapping C++ structs and classes with PHP classes
|
||||
unless "-noproxy" is specified. For PHP5, a PHP wrapper
|
||||
SWIG defaults to wrapping C++ structs and classes with PHP classes. This
|
||||
requires SWIG to generate different code for PHP4 and PHP5, so you must
|
||||
specify which you want using <tt>-php4</tt> or <tt>-php5</tt> (currently
|
||||
<tt>-php</tt> generates PHP4 class wrappers for compatibility with
|
||||
SWIG 1.3.29 and earlier, but this may change in the future).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
PHP4 classes are implemented entirely using the Zend C API so
|
||||
no additional php code is generated. For PHP5, a PHP wrapper
|
||||
class is generated which calls a set of flat functions wrapping the C++ class.
|
||||
In many cases the PHP4 and PHP5 wrappers will behave the same way,
|
||||
but the PHP5 ones make use of better PHP5's better OO functionality
|
||||
where appropriate.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
|
@ -617,7 +754,7 @@ struct Complex {
|
|||
</pre></div>
|
||||
|
||||
<p>
|
||||
Would be used in the following way from PHP5:
|
||||
Would be used in the following way from either PHP4 or PHP5:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
|
|
@ -646,7 +783,7 @@ Would be used in the following way from PHP5:
|
|||
Member variables and methods are accessed using the <tt>-></tt> operator.
|
||||
</p>
|
||||
|
||||
<H4><a name="Php_nn2_6_1"></a>29.2.6.1 Using <tt>-noproxy</tt></H4>
|
||||
<H4><a name="Php_nn2_6_1"></a>28.2.6.1 Using <tt>-noproxy</tt></H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -672,7 +809,7 @@ Complex_im_set($obj,$d);
|
|||
Complex_im_get($obj);
|
||||
</pre></div>
|
||||
|
||||
<H4><a name="Php_nn2_6_2"></a>29.2.6.2 Constructors and Destructors</H4>
|
||||
<H4><a name="Php_nn2_6_2"></a>28.2.6.2 Constructors and Destructors</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -713,13 +850,13 @@ the programmer can either reassign the variable or call
|
|||
<tt>unset($v)</tt>
|
||||
</p>
|
||||
|
||||
<H4><a name="Php_nn2_6_3"></a>29.2.6.3 Static Member Variables</H4>
|
||||
<H4><a name="Php_nn2_6_3"></a>28.2.6.3 Static Member Variables</H4>
|
||||
|
||||
|
||||
<p>
|
||||
Static member variables in C++ are not wrapped as such in PHP
|
||||
as it does not appear to be possible to intercept accesses to such variables.
|
||||
Therefore, static member variables are
|
||||
Static member variables are not supported in PHP4, and it does not
|
||||
appear to be possible to intercept accesses to static member variables
|
||||
in PHP5. Therefore, static member variables are
|
||||
wrapped using a class function with the same name, which
|
||||
returns the current value of the class variable. For example
|
||||
</p>
|
||||
|
|
@ -756,7 +893,7 @@ Ko::threats(10);
|
|||
echo "There has now been " . Ko::threats() . " threats\n";
|
||||
|
||||
</pre></div>
|
||||
<H4><a name="Php_nn2_6_4"></a>29.2.6.4 Static Member Functions</H4>
|
||||
<H4><a name="Php_nn2_6_4"></a>28.2.6.4 Static Member Functions</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -778,12 +915,12 @@ Ko::threats();
|
|||
</pre></div>
|
||||
|
||||
|
||||
<H3><a name="Php_nn2_7"></a>29.2.7 PHP Pragmas, Startup and Shutdown code</H3>
|
||||
<H3><a name="Php_nn2_7"></a>28.2.7 PHP Pragmas, Startup and Shutdown code</H3>
|
||||
|
||||
|
||||
<p>
|
||||
Note: Currently pragmas for PHP need to be specified using
|
||||
<tt>%pragma(php)</tt> but also apply for PHP5! This is just a historical
|
||||
<tt>%pragma(php4)</tt> but also apply for PHP5! This is just a historical
|
||||
oddity because SWIG's PHP support predates PHP5.
|
||||
</p>
|
||||
|
||||
|
|
@ -795,7 +932,7 @@ object.
|
|||
|
||||
<div class="code"><pre>
|
||||
%module example
|
||||
%pragma(php) code="
|
||||
%pragma(php4) code="
|
||||
# This code is inserted into example.php
|
||||
echo \"example.php execution\\n\";
|
||||
"
|
||||
|
|
@ -817,7 +954,7 @@ the example.php file.
|
|||
|
||||
<div class="code"><pre>
|
||||
%module example
|
||||
%pragma(php) code="
|
||||
%pragma(php4) code="
|
||||
include \"include.php\";
|
||||
"
|
||||
%pragma(php) include="include.php" // equivalent.
|
||||
|
|
@ -831,7 +968,7 @@ phpinfo() function.
|
|||
|
||||
<div class="code"><pre>
|
||||
%module example;
|
||||
%pragma(php) phpinfo="
|
||||
%pragma(php4) phpinfo="
|
||||
zend_printf("An example of PHP support through SWIG\n");
|
||||
php_info_print_table_start();
|
||||
php_info_print_table_header(2, \"Directive\", \"Value\");
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Pike"></a>30 SWIG and Pike</H1>
|
||||
<H1><a name="Pike"></a>29 SWIG and Pike</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -46,10 +46,10 @@ least, make sure you read the "<a href="SWIG.html#SWIG">SWIG Basics</a>"
|
|||
chapter.<br>
|
||||
</p>
|
||||
|
||||
<H2><a name="Pike_nn2"></a>30.1 Preliminaries</H2>
|
||||
<H2><a name="Pike_nn2"></a>29.1 Preliminaries</H2>
|
||||
|
||||
|
||||
<H3><a name="Pike_nn3"></a>30.1.1 Running SWIG</H3>
|
||||
<H3><a name="Pike_nn3"></a>29.1.1 Running SWIG</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -94,7 +94,7 @@ can use the <tt>-o</tt> option:
|
|||
<div class="code">
|
||||
<pre>$ <b>swig -pike -o pseudonym.c example.i</b><br></pre>
|
||||
</div>
|
||||
<H3><a name="Pike_nn4"></a>30.1.2 Getting the right header files</H3>
|
||||
<H3><a name="Pike_nn4"></a>29.1.2 Getting the right header files</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -114,7 +114,7 @@ You're looking for files with the names <tt>global.h</tt>, <tt>program.h</tt>
|
|||
and so on.
|
||||
</p>
|
||||
|
||||
<H3><a name="Pike_nn5"></a>30.1.3 Using your module</H3>
|
||||
<H3><a name="Pike_nn5"></a>29.1.3 Using your module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -129,10 +129,10 @@ Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend)
|
|||
(1) Result: 24
|
||||
</pre></div>
|
||||
|
||||
<H2><a name="Pike_nn6"></a>30.2 Basic C/C++ Mapping</H2>
|
||||
<H2><a name="Pike_nn6"></a>29.2 Basic C/C++ Mapping</H2>
|
||||
|
||||
|
||||
<H3><a name="Pike_nn7"></a>30.2.1 Modules</H3>
|
||||
<H3><a name="Pike_nn7"></a>29.2.1 Modules</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -143,7 +143,7 @@ concerned), SWIG's <tt>%module</tt> directive doesn't really have any
|
|||
significance.
|
||||
</p>
|
||||
|
||||
<H3><a name="Pike_nn8"></a>30.2.2 Functions</H3>
|
||||
<H3><a name="Pike_nn8"></a>29.2.2 Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -168,7 +168,7 @@ exactly as you'd expect it to:
|
|||
(1) Result: 24
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Pike_nn9"></a>30.2.3 Global variables</H3>
|
||||
<H3><a name="Pike_nn9"></a>29.2.3 Global variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -197,7 +197,7 @@ will result in two functions, <tt>Foo_get()</tt> and <tt>Foo_set()</tt>:
|
|||
(3) Result: 3.141590
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Pike_nn10"></a>30.2.4 Constants and enumerated types</H3>
|
||||
<H3><a name="Pike_nn10"></a>29.2.4 Constants and enumerated types</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -205,7 +205,7 @@ Enumerated types in C/C++ declarations are wrapped as Pike constants,
|
|||
not as Pike enums.
|
||||
</p>
|
||||
|
||||
<H3><a name="Pike_nn11"></a>30.2.5 Constructors and Destructors</H3>
|
||||
<H3><a name="Pike_nn11"></a>29.2.5 Constructors and Destructors</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -213,7 +213,7 @@ Constructors are wrapped as <tt>create()</tt> methods, and destructors are
|
|||
wrapped as <tt>destroy()</tt> methods, for Pike classes.
|
||||
</p>
|
||||
|
||||
<H3><a name="Pike_nn12"></a>30.2.6 Static Members</H3>
|
||||
<H3><a name="Pike_nn12"></a>29.2.6 Static Members</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ Such information generally includes type declarations (e.g., <tt>typedef</tt>) a
|
|||
C++ classes that might be used as base-classes for class declarations in the interface.
|
||||
The use of <tt>%import</tt> is also important when SWIG is used to generate
|
||||
extensions as a collection of related modules. This is an advanced topic and is described
|
||||
in later in the <a href="Modules.html">Working with Modules</a> chapter.
|
||||
in a later chapter.
|
||||
</p>
|
||||
|
||||
<P>
|
||||
|
|
@ -107,10 +107,7 @@ SWIGWIN Defined when running SWIG under Windows
|
|||
SWIG_VERSION Hexadecimal number containing SWIG version,
|
||||
such as 0x010311 (corresponding to SWIG-1.3.11).
|
||||
|
||||
SWIGALLEGROCL Defined when using Allegro CL
|
||||
SWIGCFFI Defined when using CFFI
|
||||
SWIGCHICKEN Defined when using CHICKEN
|
||||
SWIGCLISP Defined when using CLISP
|
||||
SWIGCSHARP Defined when using C#
|
||||
SWIGGUILE Defined when using Guile
|
||||
SWIGJAVA Defined when using Java
|
||||
|
|
@ -118,15 +115,17 @@ SWIGLUA Defined when using Lua
|
|||
SWIGMODULA3 Defined when using Modula-3
|
||||
SWIGMZSCHEME Defined when using Mzscheme
|
||||
SWIGOCAML Defined when using Ocaml
|
||||
SWIGOCTAVE Defined when using Octave
|
||||
SWIGPERL Defined when using Perl
|
||||
SWIGPERL5 Defined when using Perl5
|
||||
SWIGPHP Defined when using PHP
|
||||
SWIGPHP4 Defined when using PHP4
|
||||
SWIGPHP5 Defined when using PHP5
|
||||
SWIGPIKE Defined when using Pike
|
||||
SWIGPYTHON Defined when using Python
|
||||
SWIGR Defined when using R
|
||||
SWIGRUBY Defined when using Ruby
|
||||
SWIGSEXP Defined when using S-expressions
|
||||
SWIGTCL Defined when using Tcl
|
||||
SWIGTCL8 Defined when using Tcl8.0
|
||||
SWIGXML Defined when using XML
|
||||
</pre></div>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Python"></a>31 SWIG and Python</H1>
|
||||
<H1><a name="Python"></a>30 SWIG and Python</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
<li><a href="#Python_nn30">Memory management</a>
|
||||
<li><a href="#Python_nn31">Python 2.2 and classic classes</a>
|
||||
</ul>
|
||||
<li><a href="#Python_directors">Cross language polymorphism</a>
|
||||
<li><a href="#directors">Cross language polymorphism</a>
|
||||
<ul>
|
||||
<li><a href="#Python_nn33">Enabling directors</a>
|
||||
<li><a href="#Python_nn34">Director classes</a>
|
||||
|
|
@ -101,12 +101,6 @@
|
|||
<li><a href="#Python_nn71">%feature("docstring")</a>
|
||||
</ul>
|
||||
<li><a href="#Python_nn72">Python Packages</a>
|
||||
<li><a href="#Python_python3support">Python 3 Support</a>
|
||||
<ul>
|
||||
<li><a href="#Python_nn74">Function annotation</a>
|
||||
<li><a href="#Python_nn75">Buffer interface</a>
|
||||
<li><a href="#Python_nn76">Abstract base classes</a>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- INDEX -->
|
||||
|
|
@ -119,9 +113,9 @@
|
|||
|
||||
<p>
|
||||
This chapter describes SWIG's support of Python. SWIG is compatible
|
||||
with most recent Python versions including Python 3.0 and Python 2.6,
|
||||
as well as older versions dating back to Python 2.0. For the best results,
|
||||
consider using Python 2.3 or newer.
|
||||
with most recent Python versions including Python 2.2 as well as older
|
||||
versions dating back to Python 1.5.2. For the best results, consider using Python
|
||||
2.0 or newer.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
|
@ -131,7 +125,7 @@ very least, make sure you read the "<a href="SWIG.html#SWIG">SWIG
|
|||
Basics</a>" chapter.
|
||||
</p>
|
||||
|
||||
<H2><a name="Python_nn2"></a>31.1 Overview</H2>
|
||||
<H2><a name="Python_nn2"></a>30.1 Overview</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -158,10 +152,10 @@ described followed by a discussion of low-level implementation
|
|||
details.
|
||||
</p>
|
||||
|
||||
<H2><a name="Python_nn3"></a>31.2 Preliminaries</H2>
|
||||
<H2><a name="Python_nn3"></a>30.2 Preliminaries</H2>
|
||||
|
||||
|
||||
<H3><a name="Python_nn4"></a>31.2.1 Running SWIG</H3>
|
||||
<H3><a name="Python_nn4"></a>30.2.1 Running SWIG</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -259,7 +253,7 @@ The following sections have further practical examples and details on
|
|||
how you might go about compiling and using the generated files.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn6"></a>31.2.2 Using distutils</H3>
|
||||
<H3><a name="Python_nn6"></a>30.2.2 Using distutils</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -351,7 +345,7 @@ This same approach works on all platforms if the appropriate compiler is install
|
|||
can even build extensions to the standard Windows Python using MingGW)
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn7"></a>31.2.3 Hand compiling a dynamic module</H3>
|
||||
<H3><a name="Python_nn7"></a>30.2.3 Hand compiling a dynamic module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -399,7 +393,7 @@ module actually consists of two files; <tt>socket.py</tt> and
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="Python_nn8"></a>31.2.4 Static linking</H3>
|
||||
<H3><a name="Python_nn8"></a>30.2.4 Static linking</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -478,7 +472,7 @@ If using static linking, you might want to rely on a different approach
|
|||
(perhaps using distutils).
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn9"></a>31.2.5 Using your module</H3>
|
||||
<H3><a name="Python_nn9"></a>30.2.5 Using your module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -635,7 +629,7 @@ system configuration (this requires root access and you will need to
|
|||
read the man pages).
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn10"></a>31.2.6 Compilation of C++ extensions</H3>
|
||||
<H3><a name="Python_nn10"></a>30.2.6 Compilation of C++ extensions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -734,7 +728,7 @@ erratic program behavior. If working with lots of software components, you
|
|||
might want to investigate using a more formal standard such as COM.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn11"></a>31.2.7 Compiling for 64-bit platforms</H3>
|
||||
<H3><a name="Python_nn11"></a>30.2.7 Compiling for 64-bit platforms</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -771,7 +765,7 @@ and -m64 allow you to choose the desired binary format for your python
|
|||
extension.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn12"></a>31.2.8 Building Python Extensions under Windows</H3>
|
||||
<H3><a name="Python_nn12"></a>30.2.8 Building Python Extensions under Windows</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -880,7 +874,7 @@ SWIG Wiki</a>.
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="Python_nn13"></a>31.3 A tour of basic C/C++ wrapping</H2>
|
||||
<H2><a name="Python_nn13"></a>30.3 A tour of basic C/C++ wrapping</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -889,7 +883,7 @@ to your C/C++ code. Functions are wrapped as functions, classes are wrapped as
|
|||
This section briefly covers the essential aspects of this wrapping.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn14"></a>31.3.1 Modules</H3>
|
||||
<H3><a name="Python_nn14"></a>30.3.1 Modules</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -902,7 +896,7 @@ module name, make sure you don't use the same name as a built-in
|
|||
Python command or standard module name.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn15"></a>31.3.2 Functions</H3>
|
||||
<H3><a name="Python_nn15"></a>30.3.2 Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -926,7 +920,7 @@ like you think it does:
|
|||
>>>
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Python_nn16"></a>31.3.3 Global variables</H3>
|
||||
<H3><a name="Python_nn16"></a>30.3.3 Global variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1064,7 +1058,7 @@ that starts with a leading underscore. SWIG does not create <tt>cvar</tt>
|
|||
if there are no global variables in a module.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn17"></a>31.3.4 Constants and enums</H3>
|
||||
<H3><a name="Python_nn17"></a>30.3.4 Constants and enums</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1104,7 +1098,7 @@ other object. Unfortunately, there is no easy way for SWIG to
|
|||
generate code that prevents this. You will just have to be careful.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn18"></a>31.3.5 Pointers</H3>
|
||||
<H3><a name="Python_nn18"></a>30.3.5 Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1245,7 +1239,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return
|
|||
<tt>None</tt> if the conversion can't be performed.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn19"></a>31.3.6 Structures</H3>
|
||||
<H3><a name="Python_nn19"></a>30.3.6 Structures</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1434,7 +1428,7 @@ everything works just like you would expect. For example:
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Python_nn20"></a>31.3.7 C++ classes</H3>
|
||||
<H3><a name="Python_nn20"></a>30.3.7 C++ classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1523,7 +1517,7 @@ they are accessed through <tt>cvar</tt> like this:
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Python_nn21"></a>31.3.8 C++ inheritance</H3>
|
||||
<H3><a name="Python_nn21"></a>30.3.8 C++ inheritance</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1578,7 +1572,7 @@ then the function <tt>spam()</tt> accepts <tt>Foo *</tt> or a pointer to any cla
|
|||
It is safe to use multiple inheritance with SWIG.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn22"></a>31.3.9 Pointers, references, values, and arrays</H3>
|
||||
<H3><a name="Python_nn22"></a>30.3.9 Pointers, references, values, and arrays</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1639,7 +1633,7 @@ treated as a returning value, and it will follow the same
|
|||
allocation/deallocation process.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn23"></a>31.3.10 C++ overloaded functions</H3>
|
||||
<H3><a name="Python_nn23"></a>30.3.10 C++ overloaded functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1762,7 +1756,7 @@ first declaration takes precedence.
|
|||
Please refer to the "SWIG and C++" chapter for more information about overloading.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn24"></a>31.3.11 C++ operators</H3>
|
||||
<H3><a name="Python_nn24"></a>30.3.11 C++ operators</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1851,7 +1845,7 @@ Also, be aware that certain operators don't map cleanly to Python. For instance
|
|||
overloaded assignment operators don't map to Python semantics and will be ignored.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn25"></a>31.3.12 C++ namespaces</H3>
|
||||
<H3><a name="Python_nn25"></a>30.3.12 C++ namespaces</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1918,7 +1912,7 @@ utilizes thousands of small deeply nested namespaces each with
|
|||
identical symbol names, well, then you get what you deserve.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn26"></a>31.3.13 C++ templates</H3>
|
||||
<H3><a name="Python_nn26"></a>30.3.13 C++ templates</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1972,7 +1966,7 @@ Some more complicated
|
|||
examples will appear later.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn27"></a>31.3.14 C++ Smart Pointers</H3>
|
||||
<H3><a name="Python_nn27"></a>30.3.14 C++ Smart Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2057,7 +2051,7 @@ simply use the <tt>__deref__()</tt> method. For example:
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="Python_nn27a"></a>31.3.15 C++ Reference Counted Objects (ref/unref)</H3>
|
||||
<H3><a name="Python_nn27a"></a>30.3.15 C++ Reference Counted Objects (ref/unref)</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2219,7 +2213,7 @@ python releases the proxy instance.
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="Python_nn28"></a>31.4 Further details on the Python class interface</H2>
|
||||
<H2><a name="Python_nn28"></a>30.4 Further details on the Python class interface</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2232,7 +2226,7 @@ of low-level details were omitted. This section provides a brief overview
|
|||
of how the proxy classes work.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn29"></a>31.4.1 Proxy classes</H3>
|
||||
<H3><a name="Python_nn29"></a>30.4.1 Proxy classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2321,7 +2315,7 @@ you can attach new Python methods to the class and you can even inherit from it
|
|||
by Python built-in types until Python 2.2).
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn30"></a>31.4.2 Memory management</H3>
|
||||
<H3><a name="Python_nn30"></a>30.4.2 Memory management</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2513,7 +2507,7 @@ It is also possible to deal with situations like this using
|
|||
typemaps--an advanced topic discussed later.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn31"></a>31.4.3 Python 2.2 and classic classes</H3>
|
||||
<H3><a name="Python_nn31"></a>30.4.3 Python 2.2 and classic classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2550,7 +2544,7 @@ class itself. In Python-2.1 and earlier, they have to be accessed as a global
|
|||
function or through an instance (see the earlier section).
|
||||
</p>
|
||||
|
||||
<H2><a name="Python_directors"></a>31.5 Cross language polymorphism</H2>
|
||||
<H2><a name="directors"></a>30.5 Cross language polymorphism</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2584,7 +2578,7 @@ proxy classes, director classes, and C wrapper functions takes care of
|
|||
all the cross-language method routing transparently.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn33"></a>31.5.1 Enabling directors</H3>
|
||||
<H3><a name="Python_nn33"></a>30.5.1 Enabling directors</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2677,7 +2671,7 @@ class MyFoo(mymodule.Foo):
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="Python_nn34"></a>31.5.2 Director classes</H3>
|
||||
<H3><a name="Python_nn34"></a>30.5.2 Director classes</H3>
|
||||
|
||||
|
||||
|
||||
|
|
@ -2759,7 +2753,7 @@ so there is no need for the extra overhead involved with routing the
|
|||
calls through Python.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn35"></a>31.5.3 Ownership and object destruction</H3>
|
||||
<H3><a name="Python_nn35"></a>30.5.3 Ownership and object destruction</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2826,7 +2820,7 @@ deleting all the Foo pointers it contains at some point. Note that no hard
|
|||
references to the Foo objects remain in Python.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn36"></a>31.5.4 Exception unrolling</H3>
|
||||
<H3><a name="Python_nn36"></a>30.5.4 Exception unrolling</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2885,7 +2879,7 @@ Swig::DirectorMethodException is thrown, Python will register the
|
|||
exception as soon as the C wrapper function returns.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn37"></a>31.5.5 Overhead and code bloat</H3>
|
||||
<H3><a name="Python_nn37"></a>30.5.5 Overhead and code bloat</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2919,7 +2913,7 @@ directive) for only those methods that are likely to be extended in
|
|||
Python.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn38"></a>31.5.6 Typemaps</H3>
|
||||
<H3><a name="Python_nn38"></a>30.5.6 Typemaps</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2933,7 +2927,7 @@ need to be supported.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="Python_nn39"></a>31.5.7 Miscellaneous</H3>
|
||||
<H3><a name="Python_nn39"></a>30.5.7 Miscellaneous</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2980,7 +2974,7 @@ methods that return const references.
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="Python_nn40"></a>31.6 Common customization features</H2>
|
||||
<H2><a name="Python_nn40"></a>30.6 Common customization features</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2993,7 +2987,7 @@ This section describes some common SWIG features that are used to
|
|||
improve your the interface to an extension module.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn41"></a>31.6.1 C/C++ helper functions</H3>
|
||||
<H3><a name="Python_nn41"></a>30.6.1 C/C++ helper functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3074,7 +3068,7 @@ hard to implement. It is possible to clean this up using Python code, typemaps,
|
|||
customization features as covered in later sections.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn42"></a>31.6.2 Adding additional Python code</H3>
|
||||
<H3><a name="Python_nn42"></a>30.6.2 Adding additional Python code</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3223,7 +3217,7 @@ public:
|
|||
|
||||
|
||||
|
||||
<H3><a name="Python_nn43"></a>31.6.3 Class extension with %extend</H3>
|
||||
<H3><a name="Python_nn43"></a>30.6.3 Class extension with %extend</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3312,7 +3306,7 @@ Vector(12,14,16)
|
|||
in any way---the extensions only show up in the Python interface.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn44"></a>31.6.4 Exception handling with %exception</H3>
|
||||
<H3><a name="Python_nn44"></a>30.6.4 Exception handling with %exception</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3438,7 +3432,7 @@ The language-independent <tt>exception.i</tt> library file can also be used
|
|||
to raise exceptions. See the <a href="Library.html#Library">SWIG Library</a> chapter.
|
||||
</p>
|
||||
|
||||
<H2><a name="Python_nn45"></a>31.7 Tips and techniques</H2>
|
||||
<H2><a name="Python_nn45"></a>30.7 Tips and techniques</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3448,7 +3442,7 @@ strings, binary data, and arrays. This chapter discusses the common techniques
|
|||
solving these problems.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn46"></a>31.7.1 Input and output parameters</H3>
|
||||
<H3><a name="Python_nn46"></a>30.7.1 Input and output parameters</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3661,7 +3655,7 @@ void foo(Bar *OUTPUT);
|
|||
may not have the intended effect since <tt>typemaps.i</tt> does not define an OUTPUT rule for <tt>Bar</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn47"></a>31.7.2 Simple pointers</H3>
|
||||
<H3><a name="Python_nn47"></a>30.7.2 Simple pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3730,7 +3724,7 @@ If you replace <tt>%pointer_functions()</tt> by <tt>%pointer_class(type,name)</t
|
|||
See the <a href="Library.html#Library">SWIG Library</a> chapter for further details.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn48"></a>31.7.3 Unbounded C Arrays</H3>
|
||||
<H3><a name="Python_nn48"></a>30.7.3 Unbounded C Arrays</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3792,7 +3786,7 @@ well suited for applications in which you need to create buffers,
|
|||
package binary data, etc.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn49"></a>31.7.4 String handling</H3>
|
||||
<H3><a name="Python_nn49"></a>30.7.4 String handling</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3861,16 +3855,16 @@ If you need to return binary data, you might use the
|
|||
also be used to extra binary data from arbitrary pointers.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn50"></a>31.7.5 Arrays</H3>
|
||||
<H3><a name="Python_nn50"></a>30.7.5 Arrays</H3>
|
||||
|
||||
|
||||
<H3><a name="Python_nn51"></a>31.7.6 String arrays</H3>
|
||||
<H3><a name="Python_nn51"></a>30.7.6 String arrays</H3>
|
||||
|
||||
|
||||
<H3><a name="Python_nn52"></a>31.7.7 STL wrappers</H3>
|
||||
<H3><a name="Python_nn52"></a>30.7.7 STL wrappers</H3>
|
||||
|
||||
|
||||
<H2><a name="Python_nn53"></a>31.8 Typemaps</H2>
|
||||
<H2><a name="Python_nn53"></a>30.8 Typemaps</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3887,7 +3881,7 @@ Typemaps are only used if you want to change some aspect of the primitive
|
|||
C-Python interface or if you want to elevate your guru status.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn54"></a>31.8.1 What is a typemap?</H3>
|
||||
<H3><a name="Python_nn54"></a>30.8.1 What is a typemap?</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4003,7 +3997,7 @@ parameter is omitted):
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Python_nn55"></a>31.8.2 Python typemaps</H3>
|
||||
<H3><a name="Python_nn55"></a>30.8.2 Python typemaps</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4044,7 +4038,7 @@ a look at the SWIG library version 1.3.20 or so.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="Python_nn56"></a>31.8.3 Typemap variables</H3>
|
||||
<H3><a name="Python_nn56"></a>30.8.3 Typemap variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4115,7 +4109,7 @@ properly assigned.
|
|||
The Python name of the wrapper function being created.
|
||||
</div>
|
||||
|
||||
<H3><a name="Python_nn57"></a>31.8.4 Useful Python Functions</H3>
|
||||
<H3><a name="Python_nn57"></a>30.8.4 Useful Python Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4243,7 +4237,7 @@ write me
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="Python_nn58"></a>31.9 Typemap Examples</H2>
|
||||
<H2><a name="Python_nn58"></a>30.9 Typemap Examples</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4252,7 +4246,7 @@ might look at the files "<tt>python.swg</tt>" and "<tt>typemaps.i</tt>" in
|
|||
the SWIG library.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn59"></a>31.9.1 Converting Python list to a char ** </H3>
|
||||
<H3><a name="Python_nn59"></a>30.9.1 Converting Python list to a char ** </H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4332,7 +4326,7 @@ memory allocation is used to allocate memory for the array, the
|
|||
the C function.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn60"></a>31.9.2 Expanding a Python object into multiple arguments</H3>
|
||||
<H3><a name="Python_nn60"></a>30.9.2 Expanding a Python object into multiple arguments</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4411,7 +4405,7 @@ to supply the argument count. This is automatically set by the typemap code. F
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Python_nn61"></a>31.9.3 Using typemaps to return arguments</H3>
|
||||
<H3><a name="Python_nn61"></a>30.9.3 Using typemaps to return arguments</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4500,7 +4494,7 @@ function can now be used as follows:
|
|||
>>>
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Python_nn62"></a>31.9.4 Mapping Python tuples into small arrays</H3>
|
||||
<H3><a name="Python_nn62"></a>30.9.4 Mapping Python tuples into small arrays</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4549,7 +4543,7 @@ array, such an approach would not be recommended for huge arrays, but
|
|||
for small structures, this approach works fine.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn63"></a>31.9.5 Mapping sequences to C arrays</H3>
|
||||
<H3><a name="Python_nn63"></a>30.9.5 Mapping sequences to C arrays</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4638,7 +4632,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Python_nn64"></a>31.9.6 Pointer handling</H3>
|
||||
<H3><a name="Python_nn64"></a>30.9.6 Pointer handling</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4735,7 +4729,7 @@ class object (if applicable).
|
|||
|
||||
|
||||
|
||||
<H2><a name="Python_nn65"></a>31.10 Docstring Features</H2>
|
||||
<H2><a name="Python_nn65"></a>30.10 Docstring Features</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4763,7 +4757,7 @@ of your users much simpler.
|
|||
</p>
|
||||
|
||||
|
||||
<H3><a name="Python_nn66"></a>31.10.1 Module docstring</H3>
|
||||
<H3><a name="Python_nn66"></a>30.10.1 Module docstring</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4797,7 +4791,7 @@ layout of controls on a panel, etc. to be loaded from an XML file."
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="Python_nn67"></a>31.10.2 %feature("autodoc")</H3>
|
||||
<H3><a name="Python_nn67"></a>30.10.2 %feature("autodoc")</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4824,7 +4818,7 @@ names, default values if any, and return type if any. There are also
|
|||
three options for autodoc controlled by the value given to the
|
||||
feature, described below.
|
||||
|
||||
<H4><a name="Python_nn68"></a>31.10.2.1 %feature("autodoc", "0")</H4>
|
||||
<H4><a name="Python_nn68"></a>30.10.2.1 %feature("autodoc", "0")</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4853,7 +4847,7 @@ def function_name(*args, **kwargs):
|
|||
</div>
|
||||
|
||||
|
||||
<H4><a name="Python_nn69"></a>31.10.2.2 %feature("autodoc", "1")</H4>
|
||||
<H4><a name="Python_nn69"></a>30.10.2.2 %feature("autodoc", "1")</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4878,7 +4872,7 @@ def function_name(*args, **kwargs):
|
|||
|
||||
|
||||
|
||||
<H4><a name="Python_nn70"></a>31.10.2.3 %feature("autodoc", "docstring")</H4>
|
||||
<H4><a name="Python_nn70"></a>30.10.2.3 %feature("autodoc", "docstring")</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4897,7 +4891,7 @@ void GetPosition(int* OUTPUT, int* OUTPUT);
|
|||
</div>
|
||||
|
||||
|
||||
<H3><a name="Python_nn71"></a>31.10.3 %feature("docstring")</H3>
|
||||
<H3><a name="Python_nn71"></a>30.10.3 %feature("docstring")</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -4929,13 +4923,13 @@ with more than one line.
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="Python_nn72"></a>31.11 Python Packages</H2>
|
||||
<H2><a name="Python_nn72"></a>30.11 Python Packages</H2>
|
||||
|
||||
|
||||
<p>
|
||||
Using the <tt>package</tt> option of the <tt>%module</tt> directive
|
||||
allows you to specify what Python package that the module will be
|
||||
living in when installed.
|
||||
living in when installed.
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
|
|
@ -4956,256 +4950,6 @@ and also in base class declarations, etc. if the package name is
|
|||
different than its own.
|
||||
</p>
|
||||
|
||||
<H2><a name="Python_python3support"></a>31.12 Python 3 Support</H2>
|
||||
|
||||
|
||||
<p>
|
||||
SWIG is able to support Python 3.0. The wrapper code generated by
|
||||
SWIG can be compiled with both Python 2.x or 3.0. Further more, by
|
||||
passing the <tt>-py3</tt> command line option to SWIG, wrapper code
|
||||
with some Python 3 specific features can be generated (see below
|
||||
subsections for details of these features). The <tt>-py3</tt> option also
|
||||
disables some incompatible features for Python 3, such as
|
||||
<tt>-classic</tt>.
|
||||
|
||||
<p>
|
||||
There is a list of known-to-be-broken features in Python 3:
|
||||
</p>
|
||||
<ul>
|
||||
<li>No more support for FILE* typemaps, because PyFile_AsFile has been dropped
|
||||
in Python 3.</li>
|
||||
<li>The <tt>-apply</tt> command line option is removed and generating
|
||||
code using apply() is no longer supported.</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
The following are Python 3.0 new features that are currently supported by
|
||||
SWIG.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn74"></a>31.12.1 Function annotation</H3>
|
||||
|
||||
|
||||
<p>
|
||||
The <tt>-py3</tt> option will enable function annotation support. When used
|
||||
SWIG is able to generate proxy method definitions like this:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
def foo(self, bar : "int" = 0) -> "void" : ...
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
Also, even if without passing SWIG the <tt>-py3</tt> option, the parameter list
|
||||
still could be generated:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
def foo(self, bar = 0): ...
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
But for overloaded function or method, the parameter list would fallback to
|
||||
<tt>*args</tt> or <tt>self, *args</tt>, and <tt>**kwargs</tt> may be append
|
||||
depend on whether you enabled the keyword argument. This fallback is due to
|
||||
all overloaded functions share the same function in SWIG generated proxy class.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For detailed usage of function annotation, see PEP 3107.
|
||||
</p>
|
||||
|
||||
<H3><a name="Python_nn75"></a>31.12.2 Buffer interface</H3>
|
||||
|
||||
|
||||
<p>
|
||||
Buffer protocols were revised in Python 3. SWIG also gains a series of
|
||||
new typemaps to support buffer interfaces. These typemap macros are
|
||||
defined in <tt>pybuffer.i</tt>, which must be included in order to use them.
|
||||
By using these typemaps, your wrapped function will be able to
|
||||
accept any Python object that exposes a suitable buffer interface.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For example, the <tt>get_path()</tt> function puts the path string
|
||||
into the memory pointed to by its argument:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
void get_path(char *s);
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
Then you can write a typemap like this: (the following example is
|
||||
applied to both Python 3.0 and 2.6, since the <tt>bytearray</tt> type
|
||||
is backported to 2.6.
|
||||
</p>
|
||||
|
||||
|
||||
<div class="code"><pre>
|
||||
%include <pybuffer.i>
|
||||
%pybuffer_mutable_string(char *str);
|
||||
void get_path(char *s);
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
And then on the Python side the wrapped <tt>get_path</tt> could be used in this
|
||||
way:
|
||||
</p>
|
||||
|
||||
<div class="targetlang"><pre>
|
||||
>>> p = bytearray(10)
|
||||
>>> get_path(p)
|
||||
>>> print(p)
|
||||
bytearray(b'/Foo/Bar/\x00')
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
The macros defined in <tt>pybuffer.i</tt> are similar to those in
|
||||
<tt>cstring.i</tt>:
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>%pybuffer_mutable_binary(parm, size_parm)</b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
||||
<p>
|
||||
The macro can be used to generate a typemap which maps a buffer of an
|
||||
object to a pointer provided by <tt>parm</tt> and a size argument
|
||||
provided by <tt>size_parm</tt>. For example:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%pybuffer_mutable_binary(char *str, size_t size);
|
||||
...
|
||||
int snprintf(char *str, size_t size, const char *format, ...);
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
In Python:
|
||||
</p>
|
||||
|
||||
<div class="targetlang"><pre>
|
||||
>>> buf = bytearray(6)
|
||||
>>> snprintf(buf, "Hello world!")
|
||||
>>> print(buf)
|
||||
bytearray(b'Hello\x00')
|
||||
>>>
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<b>%pybuffer_mutable_string(parm)</b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
||||
<p>
|
||||
This typemap macro requires the buffer to be a zero terminated string,
|
||||
and maps the pointer of the buffer to <tt>parm</tt>. For example:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%pybuffer_mutable_string(char *str);
|
||||
...
|
||||
size_t make_upper(char *str);
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
In Python:
|
||||
</p>
|
||||
|
||||
<div class="targetlang"><pre>
|
||||
>>> buf = bytearray(b'foo\x00')
|
||||
>>> make_upper(buf)
|
||||
>>> print(buf)
|
||||
bytearray(b'FOO\x00')
|
||||
>>>
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
Both <tt>%pybuffer_mutable_binary</tt> and <tt>%pybuffer_mutable_string</tt>
|
||||
require the provided buffer to be mutable, eg. they can accept a
|
||||
<tt>bytearray</tt> type but can't accept an immutable <tt>byte</tt>
|
||||
type.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<b>%pybuffer_binary(parm, size_parm)</b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
||||
<p>
|
||||
This macro maps an object's buffer to a pointer <tt>parm</tt> and a
|
||||
size <tt>size_parm</tt>. It is similar to
|
||||
<tt>%pybuffer_mutable_binary</tt>, except the
|
||||
<tt>%pybuffer_binary</tt> an accept both mutable and immutable
|
||||
buffers. As a result, the wrapped function should not modify the buffer.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<b>%pybuffer_string(parm)</b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
|
||||
<p>
|
||||
This macro maps an object's buffer as a string pointer <tt>parm</tt>.
|
||||
It is similar to <tt>%pybuffer_mutable_string</tt> but the buffer
|
||||
could be both mutable and immutable. And your function should not
|
||||
modify the buffer.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<H3><a name="Python_nn76"></a>31.12.3 Abstract base classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
By including <tt>pyabc.i</tt> and using the <tt>-py3</tt> command
|
||||
line option when calling SWIG, the proxy classes of the STL containers
|
||||
will automatically gain an appropriate abstract base class. For
|
||||
example, the following SWIG interface:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%include <pyabc.i>
|
||||
%include <std_map.i>
|
||||
%include <std_list.i>
|
||||
|
||||
namespace std {
|
||||
%template(Mapii) map<int, int>;
|
||||
%template(IntList) list<int>;
|
||||
}
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
will generate a Python proxy class <tt>Mapii</tt> inheriting from
|
||||
<tt>collections.MutableMap</tt> and a proxy class <tt>IntList</tt>
|
||||
inheriting from <tt>collections.MutableSequence</tt>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<tt>pyabc.i</tt> also provides a macro <tt>%pythonabc</tt> that could be
|
||||
used to define an abstract base class for your own C++ class:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%pythonabc(MySet, collections.MutableSet);
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
For details of abstract base class, please see PEP 3119.
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="R"></a>34 SWIG and R</H1>
|
||||
<H1><a name="R"></a>33 SWIG and R</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -33,7 +33,7 @@ compile and run an R interface to QuantLib running on Mandriva Linux
|
|||
with gcc. The R bindings also work on Microsoft Windows using Visual C++.
|
||||
</p>
|
||||
|
||||
<H2><a name="R_nn2"></a>34.1 Bugs</H2>
|
||||
<H2><a name="R_nn2"></a>33.1 Bugs</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -45,7 +45,7 @@ Currently the following features are not implemented or broken:
|
|||
<li>C Array wrappings
|
||||
</ul>
|
||||
|
||||
<H2><a name="R_nn3"></a>34.2 Using R and SWIG</H2>
|
||||
<H2><a name="R_nn3"></a>33.2 Using R and SWIG</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -99,7 +99,7 @@ Without it, inheritance of wrapped objects may fail.
|
|||
These two files can be loaded in any order
|
||||
</p>
|
||||
|
||||
<H2><a name="R_nn4"></a>34.3 Precompiling large R files</H2>
|
||||
<H2><a name="R_nn4"></a>33.3 Precompiling large R files</H2>
|
||||
|
||||
|
||||
In cases where the R file is large, one make save a lot of loading
|
||||
|
|
@ -117,7 +117,7 @@ will save a large amount of loading time.
|
|||
|
||||
|
||||
|
||||
<H2><a name="R_nn5"></a>34.4 General policy</H2>
|
||||
<H2><a name="R_nn5"></a>33.4 General policy</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -126,7 +126,7 @@ wrapping over the underlying functions and rely on the R type system
|
|||
to provide R syntax.
|
||||
</p>
|
||||
|
||||
<H2><a name="R_language_conventions"></a>34.5 Language conventions</H2>
|
||||
<H2><a name="R_language_conventions"></a>33.5 Language conventions</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -135,7 +135,7 @@ and [ are overloaded to allow for R syntax (one based indices and
|
|||
slices)
|
||||
</p>
|
||||
|
||||
<H2><a name="R_nn6"></a>34.6 C++ classes</H2>
|
||||
<H2><a name="R_nn6"></a>33.6 C++ classes</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -147,7 +147,7 @@ keep track of the pointer object which removes the necessity for a lot
|
|||
of the proxy class baggage you see in other languages.
|
||||
</p>
|
||||
|
||||
<H2><a name="R_nn7"></a>34.7 Enumerations</H2>
|
||||
<H2><a name="R_nn7"></a>33.7 Enumerations</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
|
||||
|
||||
<H1><a name="Ruby"></a>32 SWIG and Ruby</H1>
|
||||
<H1><a name="Ruby"></a>31 SWIG and Ruby</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -167,7 +167,7 @@
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn2"></a>32.1 Preliminaries</H2>
|
||||
<H2><a name="Ruby_nn2"></a>31.1 Preliminaries</H2>
|
||||
|
||||
|
||||
<p> SWIG 1.3 is known to work with Ruby versions 1.6 and later.
|
||||
|
|
@ -190,7 +190,7 @@ of Ruby. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn3"></a>32.1.1 Running SWIG</H3>
|
||||
<H3><a name="Ruby_nn3"></a>31.1.1 Running SWIG</H3>
|
||||
|
||||
|
||||
<p> To build a Ruby module, run SWIG using the <tt>-ruby</tt>
|
||||
|
|
@ -244,7 +244,7 @@ to compile this file and link it with the rest of your program. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn4"></a>32.1.2 Getting the right header files</H3>
|
||||
<H3><a name="Ruby_nn4"></a>31.1.2 Getting the right header files</H3>
|
||||
|
||||
|
||||
<p> In order to compile the wrapper code, the compiler needs the <tt>ruby.h</tt>
|
||||
|
|
@ -288,7 +288,7 @@ installed, you can run Ruby to find out. For example: </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn5"></a>32.1.3 Compiling a dynamic module</H3>
|
||||
<H3><a name="Ruby_nn5"></a>31.1.3 Compiling a dynamic module</H3>
|
||||
|
||||
|
||||
<p> Ruby extension modules are typically compiled into shared
|
||||
|
|
@ -443,7 +443,7 @@ manual pages for your compiler and linker to determine the correct set
|
|||
of options. You might also check the <a href="http://www.dabeaz.com/cgi-bin/wiki.pl">SWIG Wiki</a>
|
||||
for additional information. </p>
|
||||
|
||||
<H3><a name="Ruby_nn6"></a>32.1.4 Using your module</H3>
|
||||
<H3><a name="Ruby_nn6"></a>31.1.4 Using your module</H3>
|
||||
|
||||
|
||||
<p> Ruby <i>module</i> names must be capitalized,
|
||||
|
|
@ -498,7 +498,7 @@ begins with: </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn7"></a>32.1.5 Static linking</H3>
|
||||
<H3><a name="Ruby_nn7"></a>31.1.5 Static linking</H3>
|
||||
|
||||
|
||||
<p> An alternative approach to dynamic linking is to rebuild the
|
||||
|
|
@ -519,7 +519,7 @@ finally rebuilding Ruby. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn8"></a>32.1.6 Compilation of C++ extensions</H3>
|
||||
<H3><a name="Ruby_nn8"></a>31.1.6 Compilation of C++ extensions</H3>
|
||||
|
||||
|
||||
<p> On most machines, C++ extension modules should be linked
|
||||
|
|
@ -571,7 +571,7 @@ extension, e.g. </p>
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn9"></a>32.2 Building Ruby Extensions under Windows 95/NT</H2>
|
||||
<H2><a name="Ruby_nn9"></a>31.2 Building Ruby Extensions under Windows 95/NT</H2>
|
||||
|
||||
|
||||
<p> Building a SWIG extension to Ruby under Windows 95/NT is
|
||||
|
|
@ -610,7 +610,7 @@ files. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn10"></a>32.2.1 Running SWIG from Developer Studio</H3>
|
||||
<H3><a name="Ruby_nn10"></a>31.2.1 Running SWIG from Developer Studio</H3>
|
||||
|
||||
|
||||
<p> If you are developing your application within Microsoft
|
||||
|
|
@ -752,7 +752,7 @@ directory, then run the Ruby script from the DOS/Command prompt: </p>
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn11"></a>32.3 The Ruby-to-C/C++ Mapping</H2>
|
||||
<H2><a name="Ruby_nn11"></a>31.3 The Ruby-to-C/C++ Mapping</H2>
|
||||
|
||||
|
||||
<p> This section describes the basics of how SWIG maps C or C++
|
||||
|
|
@ -762,7 +762,7 @@ declarations in your SWIG interface files to Ruby constructs. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn12"></a>32.3.1 Modules</H3>
|
||||
<H3><a name="Ruby_nn12"></a>31.3.1 Modules</H3>
|
||||
|
||||
|
||||
<p> The SWIG <tt>%module</tt> directive specifies
|
||||
|
|
@ -931,7 +931,7 @@ Ruby's built-in names. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn13"></a>32.3.2 Functions</H3>
|
||||
<H3><a name="Ruby_nn13"></a>31.3.2 Functions</H3>
|
||||
|
||||
|
||||
<p> Global functions are wrapped as Ruby module methods. For
|
||||
|
|
@ -994,7 +994,7 @@ module that can be used like so: </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn14"></a>32.3.3 Variable Linking</H3>
|
||||
<H3><a name="Ruby_nn14"></a>31.3.3 Variable Linking</H3>
|
||||
|
||||
|
||||
<p> C/C++ global variables are wrapped as a pair of singleton
|
||||
|
|
@ -1094,7 +1094,7 @@ effect until it is explicitly disabled using <tt>%mutable</tt>.
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn15"></a>32.3.4 Constants</H3>
|
||||
<H3><a name="Ruby_nn15"></a>31.3.4 Constants</H3>
|
||||
|
||||
|
||||
<p> C/C++ constants are wrapped as module constants initialized
|
||||
|
|
@ -1138,7 +1138,7 @@ constant values, e.g. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn16"></a>32.3.5 Pointers</H3>
|
||||
<H3><a name="Ruby_nn16"></a>31.3.5 Pointers</H3>
|
||||
|
||||
|
||||
<p> "Opaque" pointers to arbitrary C/C++ types (i.e. types that
|
||||
|
|
@ -1190,7 +1190,7 @@ the Ruby <tt>nil</tt> object. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn17"></a>32.3.6 Structures</H3>
|
||||
<H3><a name="Ruby_nn17"></a>31.3.6 Structures</H3>
|
||||
|
||||
|
||||
<p> C/C++ structs are wrapped as Ruby classes, with accessor
|
||||
|
|
@ -1365,7 +1365,7 @@ pointers. For example, </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn18"></a>32.3.7 C++ classes</H3>
|
||||
<H3><a name="Ruby_nn18"></a>31.3.7 C++ classes</H3>
|
||||
|
||||
|
||||
<p> Like structs, C++ classes are wrapped by creating a new Ruby
|
||||
|
|
@ -1451,7 +1451,7 @@ class. </li>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn19"></a>32.3.8 C++ Inheritance</H3>
|
||||
<H3><a name="Ruby_nn19"></a>31.3.8 C++ Inheritance</H3>
|
||||
|
||||
|
||||
<p> The SWIG type-checker is fully aware of C++ inheritance.
|
||||
|
|
@ -1682,7 +1682,7 @@ Typing"</a>). </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn20"></a>32.3.9 C++ Overloaded Functions</H3>
|
||||
<H3><a name="Ruby_nn20"></a>31.3.9 C++ Overloaded Functions</H3>
|
||||
|
||||
|
||||
<p> C++ overloaded functions, methods, and constructors are
|
||||
|
|
@ -1878,7 +1878,7 @@ and C++"</a> chapter for more information about overloading. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn21"></a>32.3.10 C++ Operators</H3>
|
||||
<H3><a name="Ruby_nn21"></a>31.3.10 C++ Operators</H3>
|
||||
|
||||
|
||||
<p> For the most part, overloaded operators are handled
|
||||
|
|
@ -1959,7 +1959,7 @@ on operator overloading</a>. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn22"></a>32.3.11 C++ namespaces</H3>
|
||||
<H3><a name="Ruby_nn22"></a>31.3.11 C++ namespaces</H3>
|
||||
|
||||
|
||||
<p> SWIG is aware of C++ namespaces, but namespace names do not
|
||||
|
|
@ -2035,7 +2035,7 @@ identical symbol names, well, then you get what you deserve. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn23"></a>32.3.12 C++ templates</H3>
|
||||
<H3><a name="Ruby_nn23"></a>31.3.12 C++ templates</H3>
|
||||
|
||||
|
||||
<p> C++ templates don't present a huge problem for SWIG. However,
|
||||
|
|
@ -2079,7 +2079,7 @@ directive. For example: </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn23_1"></a>32.3.13 C++ Standard Template Library (STL)</H3>
|
||||
<H3><a name="Ruby_nn23_1"></a>31.3.13 C++ Standard Template Library (STL)</H3>
|
||||
|
||||
|
||||
<p> On a related note, the standard SWIG library contains a
|
||||
|
|
@ -2332,7 +2332,7 @@ chapter.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="C_STL_Functors"></a>32.3.14 C++ STL Functors</H3>
|
||||
<H3><a name="C_STL_Functors"></a>31.3.14 C++ STL Functors</H3>
|
||||
|
||||
|
||||
<p>Some containers in the STL allow you to modify their default
|
||||
|
|
@ -2532,7 +2532,7 @@ b<br style="font-weight: bold;">
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_C_Iterators"></a>32.3.15 C++ STL Iterators</H3>
|
||||
<H3><a name="Ruby_C_Iterators"></a>31.3.15 C++ STL Iterators</H3>
|
||||
|
||||
|
||||
<p>The STL is well known for the use of iterators. There
|
||||
|
|
@ -2743,7 +2743,7 @@ i<br>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn24"></a>32.3.16 C++ Smart Pointers</H3>
|
||||
<H3><a name="Ruby_nn24"></a>31.3.16 C++ Smart Pointers</H3>
|
||||
|
||||
|
||||
<p> In certain C++ programs, it is common to use classes that
|
||||
|
|
@ -2868,7 +2868,7 @@ method. For example: </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn25"></a>32.3.17 Cross-Language Polymorphism</H3>
|
||||
<H3><a name="Ruby_nn25"></a>31.3.17 Cross-Language Polymorphism</H3>
|
||||
|
||||
|
||||
<p> SWIG's Ruby module supports cross-language polymorphism
|
||||
|
|
@ -2881,7 +2881,7 @@ using this feature with Ruby. </p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_nn26"></a>32.3.17.1 Exception Unrolling</H4>
|
||||
<H4><a name="Ruby_nn26"></a>31.3.17.1 Exception Unrolling</H4>
|
||||
|
||||
|
||||
<p> Whenever a C++ director class routes one of its virtual
|
||||
|
|
@ -2919,7 +2919,7 @@ caught here and a C++ exception is raised in its place. </p>
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn27"></a>32.4 Naming</H2>
|
||||
<H2><a name="Ruby_nn27"></a>31.4 Naming</H2>
|
||||
|
||||
|
||||
<p>Ruby has several common naming conventions. Constants are
|
||||
|
|
@ -3015,7 +3015,7 @@ planned to become the default option in future releases.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn28"></a>32.4.1 Defining Aliases</H3>
|
||||
<H3><a name="Ruby_nn28"></a>31.4.1 Defining Aliases</H3>
|
||||
|
||||
|
||||
<p> It's a fairly common practice in the Ruby built-ins and
|
||||
|
|
@ -3107,7 +3107,7 @@ Features"</a>) for more details).</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn29"></a>32.4.2 Predicate Methods</H3>
|
||||
<H3><a name="Ruby_nn29"></a>31.4.2 Predicate Methods</H3>
|
||||
|
||||
|
||||
<p> Ruby methods that return a boolean value and end in a
|
||||
|
|
@ -3196,7 +3196,7 @@ Features"</a>) for more details). </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn30"></a>32.4.3 Bang Methods</H3>
|
||||
<H3><a name="Ruby_nn30"></a>31.4.3 Bang Methods</H3>
|
||||
|
||||
|
||||
<p> Ruby methods that modify an object in-place and end in an
|
||||
|
|
@ -3260,7 +3260,7 @@ Features"</a>) for more details). </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn31"></a>32.4.4 Getters and Setters</H3>
|
||||
<H3><a name="Ruby_nn31"></a>31.4.4 Getters and Setters</H3>
|
||||
|
||||
|
||||
<p> Often times a C++ library will expose properties through
|
||||
|
|
@ -3330,7 +3330,7 @@ methods to be exposed in Ruby as <tt>value</tt> and <tt>value=.
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn32"></a>32.5 Input and output parameters</H2>
|
||||
<H2><a name="Ruby_nn32"></a>31.5 Input and output parameters</H2>
|
||||
|
||||
|
||||
<p> A common problem in some C programs is handling parameters
|
||||
|
|
@ -3581,10 +3581,10 @@ of <tt>%apply</tt> </p>
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn33"></a>32.6 Exception handling </H2>
|
||||
<H2><a name="Ruby_nn33"></a>31.6 Exception handling </H2>
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn34"></a>32.6.1 Using the %exception directive </H3>
|
||||
<H3><a name="Ruby_nn34"></a>31.6.1 Using the %exception directive </H3>
|
||||
|
||||
|
||||
<p>The SWIG <tt>%exception</tt> directive can be
|
||||
|
|
@ -3679,7 +3679,7 @@ Features</a> for more examples.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn34_2"></a>32.6.2 Handling Ruby Blocks </H3>
|
||||
<H3><a name="Ruby_nn34_2"></a>31.6.2 Handling Ruby Blocks </H3>
|
||||
|
||||
|
||||
<p>One of the highlights of Ruby and most of its standard library
|
||||
|
|
@ -3860,7 +3860,7 @@ RUBY_YIELD_SELF );<br>
|
|||
<p>For more information on typemaps, see <a href="#Ruby_nn37">Typemaps</a>.</p>
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn35"></a>32.6.3 Raising exceptions </H3>
|
||||
<H3><a name="Ruby_nn35"></a>31.6.3 Raising exceptions </H3>
|
||||
|
||||
|
||||
<p>There are three ways to raise exceptions from C++ code to
|
||||
|
|
@ -4621,7 +4621,7 @@ the built-in Ruby exception types.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn36"></a>32.6.4 Exception classes </H3>
|
||||
<H3><a name="Ruby_nn36"></a>31.6.4 Exception classes </H3>
|
||||
|
||||
|
||||
<p>Starting with SWIG 1.3.28, the Ruby module supports the <tt>%exceptionclass</tt>
|
||||
|
|
@ -4679,7 +4679,7 @@ providing for a more natural integration between C++ code and Ruby code.</p>
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn37"></a>32.7 Typemaps</H2>
|
||||
<H2><a name="Ruby_nn37"></a>31.7 Typemaps</H2>
|
||||
|
||||
|
||||
<p> This section describes how you can modify SWIG's default
|
||||
|
|
@ -4702,7 +4702,7 @@ of the primitive C-Ruby interface.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn38"></a>32.7.1 What is a typemap?</H3>
|
||||
<H3><a name="Ruby_nn38"></a>31.7.1 What is a typemap?</H3>
|
||||
|
||||
|
||||
<p> A typemap is nothing more than a code generation rule that is
|
||||
|
|
@ -4964,7 +4964,7 @@ to be used as follows (notice how the length parameter is omitted): </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_Typemap_scope"></a>32.7.2 Typemap scope</H3>
|
||||
<H3><a name="Ruby_Typemap_scope"></a>31.7.2 Typemap scope</H3>
|
||||
|
||||
|
||||
<p> Once defined, a typemap remains in effect for all of the
|
||||
|
|
@ -5012,7 +5012,7 @@ where the class itself is defined. For example:</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_Copying_a_typemap"></a>32.7.3 Copying a typemap</H3>
|
||||
<H3><a name="Ruby_Copying_a_typemap"></a>31.7.3 Copying a typemap</H3>
|
||||
|
||||
|
||||
<p> A typemap is copied by using assignment. For example:</p>
|
||||
|
|
@ -5114,7 +5114,7 @@ rules as for <tt>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_Deleting_a_typemap"></a>32.7.4 Deleting a typemap</H3>
|
||||
<H3><a name="Ruby_Deleting_a_typemap"></a>31.7.4 Deleting a typemap</H3>
|
||||
|
||||
|
||||
<p> A typemap can be deleted by simply defining no code. For
|
||||
|
|
@ -5166,7 +5166,7 @@ typemaps immediately after the clear operation.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_Placement_of_typemaps"></a>32.7.5 Placement of typemaps</H3>
|
||||
<H3><a name="Ruby_Placement_of_typemaps"></a>31.7.5 Placement of typemaps</H3>
|
||||
|
||||
|
||||
<p> Typemap declarations can be declared in the global scope,
|
||||
|
|
@ -5250,7 +5250,7 @@ string</tt>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn39"></a>32.7.6 Ruby typemaps</H3>
|
||||
<H3><a name="Ruby_nn39"></a>31.7.6 Ruby typemaps</H3>
|
||||
|
||||
|
||||
<p>The following list details all of the typemap methods that
|
||||
|
|
@ -5260,7 +5260,7 @@ can be used by the Ruby module: </p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_in_typemap"></a>32.7.6.1 "in" typemap</H4>
|
||||
<H4><a name="Ruby_in_typemap"></a>31.7.6.1 "in" typemap</H4>
|
||||
|
||||
|
||||
<p>Converts Ruby objects to input
|
||||
|
|
@ -5503,7 +5503,7 @@ arguments to be specified. For example:</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_typecheck_typemap"></a>32.7.6.2 "typecheck" typemap</H4>
|
||||
<H4><a name="Ruby_typecheck_typemap"></a>31.7.6.2 "typecheck" typemap</H4>
|
||||
|
||||
|
||||
<p> The "typecheck" typemap is used to support overloaded
|
||||
|
|
@ -5544,7 +5544,7 @@ on "Typemaps and Overloading."</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_out_typemap"></a>32.7.6.3 "out" typemap</H4>
|
||||
<H4><a name="Ruby_out_typemap"></a>31.7.6.3 "out" typemap</H4>
|
||||
|
||||
|
||||
<p>Converts return value of a C function
|
||||
|
|
@ -5776,7 +5776,7 @@ version of the C datatype matched by the typemap.</td>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_arginit_typemap"></a>32.7.6.4 "arginit" typemap</H4>
|
||||
<H4><a name="Ruby_arginit_typemap"></a>31.7.6.4 "arginit" typemap</H4>
|
||||
|
||||
|
||||
<p> The "arginit" typemap is used to set the initial value of a
|
||||
|
|
@ -5801,7 +5801,7 @@ applications. For example:</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_default_typemap"></a>32.7.6.5 "default" typemap</H4>
|
||||
<H4><a name="Ruby_default_typemap"></a>31.7.6.5 "default" typemap</H4>
|
||||
|
||||
|
||||
<p> The "default" typemap is used to turn an argument into a
|
||||
|
|
@ -5843,7 +5843,7 @@ default argument wrapping.</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_check_typemap"></a>32.7.6.6 "check" typemap</H4>
|
||||
<H4><a name="Ruby_check_typemap"></a>31.7.6.6 "check" typemap</H4>
|
||||
|
||||
|
||||
<p> The "check" typemap is used to supply value checking code
|
||||
|
|
@ -5867,7 +5867,7 @@ arguments have been converted. For example:</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_argout_typemap_"></a>32.7.6.7 "argout" typemap</H4>
|
||||
<H4><a name="Ruby_argout_typemap_"></a>31.7.6.7 "argout" typemap</H4>
|
||||
|
||||
|
||||
<p> The "argout" typemap is used to return values from arguments.
|
||||
|
|
@ -6025,7 +6025,7 @@ some function like SWIG_Ruby_AppendOutput.</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_freearg_typemap_"></a>32.7.6.8 "freearg" typemap</H4>
|
||||
<H4><a name="Ruby_freearg_typemap_"></a>31.7.6.8 "freearg" typemap</H4>
|
||||
|
||||
|
||||
<p> The "freearg" typemap is used to cleanup argument data. It is
|
||||
|
|
@ -6061,7 +6061,7 @@ abort prematurely.</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_newfree_typemap"></a>32.7.6.9 "newfree" typemap</H4>
|
||||
<H4><a name="Ruby_newfree_typemap"></a>31.7.6.9 "newfree" typemap</H4>
|
||||
|
||||
|
||||
<p> The "newfree" typemap is used in conjunction with the <tt>%newobject</tt>
|
||||
|
|
@ -6092,7 +6092,7 @@ ownership and %newobject</a> for further details.</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_memberin_typemap"></a>32.7.6.10 "memberin" typemap</H4>
|
||||
<H4><a name="Ruby_memberin_typemap"></a>31.7.6.10 "memberin" typemap</H4>
|
||||
|
||||
|
||||
<p> The "memberin" typemap is used to copy data from<em> an
|
||||
|
|
@ -6125,7 +6125,7 @@ other objects.</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_varin_typemap"></a>32.7.6.11 "varin" typemap</H4>
|
||||
<H4><a name="Ruby_varin_typemap"></a>31.7.6.11 "varin" typemap</H4>
|
||||
|
||||
|
||||
<p> The "varin" typemap is used to convert objects in the target
|
||||
|
|
@ -6136,7 +6136,7 @@ This is implementation specific.</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_varout_typemap_"></a>32.7.6.12 "varout" typemap</H4>
|
||||
<H4><a name="Ruby_varout_typemap_"></a>31.7.6.12 "varout" typemap</H4>
|
||||
|
||||
|
||||
<p> The "varout" typemap is used to convert a C/C++ object to an
|
||||
|
|
@ -6147,7 +6147,7 @@ This is implementation specific.</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_throws_typemap"></a>32.7.6.13 "throws" typemap</H4>
|
||||
<H4><a name="Ruby_throws_typemap"></a>31.7.6.13 "throws" typemap</H4>
|
||||
|
||||
|
||||
<p> The "throws" typemap is only used when SWIG parses a C++
|
||||
|
|
@ -6206,7 +6206,7 @@ handling with %exception</a> section.</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_directorin_typemap"></a>32.7.6.14 directorin typemap</H4>
|
||||
<H4><a name="Ruby_directorin_typemap"></a>31.7.6.14 directorin typemap</H4>
|
||||
|
||||
|
||||
<p>Converts C++ objects in director
|
||||
|
|
@ -6460,7 +6460,7 @@ referring to the class itself.</td>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_directorout_typemap"></a>32.7.6.15 directorout typemap</H4>
|
||||
<H4><a name="Ruby_directorout_typemap"></a>31.7.6.15 directorout typemap</H4>
|
||||
|
||||
|
||||
<p>Converts Ruby objects in director
|
||||
|
|
@ -6720,7 +6720,7 @@ exception.<br>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_directorargout_typemap"></a>32.7.6.16 directorargout typemap</H4>
|
||||
<H4><a name="Ruby_directorargout_typemap"></a>31.7.6.16 directorargout typemap</H4>
|
||||
|
||||
|
||||
<p>Output argument processing in director
|
||||
|
|
@ -6960,7 +6960,7 @@ referring to the instance of the class itself</td>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_ret_typemap"></a>32.7.6.17 ret typemap</H4>
|
||||
<H4><a name="Ruby_ret_typemap"></a>31.7.6.17 ret typemap</H4>
|
||||
|
||||
|
||||
<p>Cleanup of function return values
|
||||
|
|
@ -6970,7 +6970,7 @@ referring to the instance of the class itself</td>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_globalin_typemap"></a>32.7.6.18 globalin typemap</H4>
|
||||
<H4><a name="Ruby_globalin_typemap"></a>31.7.6.18 globalin typemap</H4>
|
||||
|
||||
|
||||
<p>Setting of C global variables
|
||||
|
|
@ -6980,7 +6980,7 @@ referring to the instance of the class itself</td>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn40"></a>32.7.7 Typemap variables</H3>
|
||||
<H3><a name="Ruby_nn40"></a>31.7.7 Typemap variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -7090,7 +7090,7 @@ being created. </div>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn41"></a>32.7.8 Useful Functions</H3>
|
||||
<H3><a name="Ruby_nn41"></a>31.7.8 Useful Functions</H3>
|
||||
|
||||
|
||||
<p> When you write a typemap, you usually have to work directly
|
||||
|
|
@ -7114,7 +7114,7 @@ across multiple languages.</p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_nn42"></a>32.7.8.1 C Datatypes to Ruby Objects</H4>
|
||||
<H4><a name="Ruby_nn42"></a>31.7.8.1 C Datatypes to Ruby Objects</H4>
|
||||
|
||||
|
||||
<div class="diagram">
|
||||
|
|
@ -7170,7 +7170,7 @@ SWIG_From_float(float)</td>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_nn43"></a>32.7.8.2 Ruby Objects to C Datatypes</H4>
|
||||
<H4><a name="Ruby_nn43"></a>31.7.8.2 Ruby Objects to C Datatypes</H4>
|
||||
|
||||
|
||||
<p>Here, while the Ruby versions return the value directly, the SWIG
|
||||
|
|
@ -7259,7 +7259,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_nn44"></a>32.7.8.3 Macros for VALUE</H4>
|
||||
<H4><a name="Ruby_nn44"></a>31.7.8.3 Macros for VALUE</H4>
|
||||
|
||||
|
||||
<p> <tt>RSTRING_LEN(str)</tt> </p>
|
||||
|
|
@ -7322,7 +7322,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_nn45"></a>32.7.8.4 Exceptions</H4>
|
||||
<H4><a name="Ruby_nn45"></a>31.7.8.4 Exceptions</H4>
|
||||
|
||||
|
||||
<p> <tt>void rb_raise(VALUE exception, const char *fmt,
|
||||
|
|
@ -7489,7 +7489,7 @@ arguments are interpreted as with <tt>printf()</tt>. </div>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_nn46"></a>32.7.8.5 Iterators</H4>
|
||||
<H4><a name="Ruby_nn46"></a>31.7.8.5 Iterators</H4>
|
||||
|
||||
|
||||
<p> <tt>void rb_iter_break()</tt> </p>
|
||||
|
|
@ -7591,7 +7591,7 @@ VALUE), VALUE value)</tt></p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn47"></a>32.7.9 Typemap Examples</H3>
|
||||
<H3><a name="Ruby_nn47"></a>31.7.9 Typemap Examples</H3>
|
||||
|
||||
|
||||
<p> This section includes a few examples of typemaps. For more
|
||||
|
|
@ -7602,7 +7602,7 @@ directory. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn48"></a>32.7.10 Converting a Ruby array to a char **</H3>
|
||||
<H3><a name="Ruby_nn48"></a>31.7.10 Converting a Ruby array to a char **</H3>
|
||||
|
||||
|
||||
<p> A common problem in many C programs is the processing of
|
||||
|
|
@ -7657,7 +7657,7 @@ after the execution of the C function. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn49"></a>32.7.11 Collecting arguments in a hash</H3>
|
||||
<H3><a name="Ruby_nn49"></a>31.7.11 Collecting arguments in a hash</H3>
|
||||
|
||||
|
||||
<p> Ruby's solution to the "keyword arguments" capability of some
|
||||
|
|
@ -7936,7 +7936,7 @@ directory of the SWIG distribution. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn50"></a>32.7.12 Pointer handling</H3>
|
||||
<H3><a name="Ruby_nn50"></a>31.7.12 Pointer handling</H3>
|
||||
|
||||
|
||||
<p> Occasionally, it might be necessary to convert pointer values
|
||||
|
|
@ -8035,7 +8035,7 @@ For example: </p>
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_nn51"></a>32.7.12.1 Ruby Datatype Wrapping</H4>
|
||||
<H4><a name="Ruby_nn51"></a>31.7.12.1 Ruby Datatype Wrapping</H4>
|
||||
|
||||
|
||||
<p> <tt>VALUE Data_Wrap_Struct(VALUE class, void
|
||||
|
|
@ -8086,7 +8086,7 @@ and assigns that pointer to <i>ptr</i>. </div>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn52"></a>32.7.13 Example: STL Vector to Ruby Array</H3>
|
||||
<H3><a name="Ruby_nn52"></a>31.7.13 Example: STL Vector to Ruby Array</H3>
|
||||
|
||||
|
||||
<p>Another use for macros and type maps is to create a Ruby array
|
||||
|
|
@ -8195,7 +8195,7 @@ the<a href="#Ruby_nn23_1"> C++ Standard Template Library</a>.<br>
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn65"></a>32.8 Docstring Features</H2>
|
||||
<H2><a name="Ruby_nn65"></a>31.8 Docstring Features</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -8256,7 +8256,7 @@ generate ri documentation from a c wrap file, you could do:</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn66"></a>32.8.1 Module docstring</H3>
|
||||
<H3><a name="Ruby_nn66"></a>31.8.1 Module docstring</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -8307,7 +8307,7 @@ macro. For example:
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn67"></a>32.8.2 %feature("autodoc")</H3>
|
||||
<H3><a name="Ruby_nn67"></a>31.8.2 %feature("autodoc")</H3>
|
||||
|
||||
|
||||
<p>Since SWIG does know everything about the function it wraps,
|
||||
|
|
@ -8336,7 +8336,7 @@ feature, described below.
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_nn68"></a>32.8.2.1 %feature("autodoc", "0")</H4>
|
||||
<H4><a name="Ruby_nn68"></a>31.8.2.1 %feature("autodoc", "0")</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -8384,7 +8384,7 @@ Then Ruby code like this will be generated:
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_autodoc1"></a>32.8.2.2 %feature("autodoc", "1")</H4>
|
||||
<H4><a name="Ruby_autodoc1"></a>31.8.2.2 %feature("autodoc", "1")</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -8416,7 +8416,7 @@ this:
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_autodoc2"></a>32.8.2.3 %feature("autodoc", "2")</H4>
|
||||
<H4><a name="Ruby_autodoc2"></a>31.8.2.3 %feature("autodoc", "2")</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -8432,7 +8432,7 @@ this:
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_feature_autodoc3"></a>32.8.2.4 %feature("autodoc", "3")</H4>
|
||||
<H4><a name="Ruby_feature_autodoc3"></a>31.8.2.4 %feature("autodoc", "3")</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -8460,7 +8460,7 @@ this:
|
|||
|
||||
|
||||
|
||||
<H4><a name="Ruby_nn70"></a>32.8.2.5 %feature("autodoc", "docstring")</H4>
|
||||
<H4><a name="Ruby_nn70"></a>31.8.2.5 %feature("autodoc", "docstring")</H4>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -8488,7 +8488,7 @@ generated string. For example:
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn71"></a>32.8.3 %feature("docstring")</H3>
|
||||
<H3><a name="Ruby_nn71"></a>31.8.3 %feature("docstring")</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -8503,10 +8503,10 @@ docstring and they are output together. </p>
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn53"></a>32.9 Advanced Topics</H2>
|
||||
<H2><a name="Ruby_nn53"></a>31.9 Advanced Topics</H2>
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn54"></a>32.9.1 Operator overloading</H3>
|
||||
<H3><a name="Ruby_nn54"></a>31.9.1 Operator overloading</H3>
|
||||
|
||||
|
||||
<p> SWIG allows operator overloading with, by using the <tt>%extend</tt>
|
||||
|
|
@ -9523,7 +9523,7 @@ parses the expression <i>a != b</i> as <i>!(a == b)</i>.
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn55"></a>32.9.2 Creating Multi-Module Packages</H3>
|
||||
<H3><a name="Ruby_nn55"></a>31.9.2 Creating Multi-Module Packages</H3>
|
||||
|
||||
|
||||
<p> The chapter on <a href="Modules.html">Working
|
||||
|
|
@ -9704,7 +9704,7 @@ initialized: </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn56"></a>32.9.3 Specifying Mixin Modules</H3>
|
||||
<H3><a name="Ruby_nn56"></a>31.9.3 Specifying Mixin Modules</H3>
|
||||
|
||||
|
||||
<p> The Ruby language doesn't support multiple inheritance, but
|
||||
|
|
@ -9802,7 +9802,7 @@ Features"</a>) for more details). </p>
|
|||
|
||||
|
||||
|
||||
<H2><a name="Ruby_nn57"></a>32.10 Memory Management</H2>
|
||||
<H2><a name="Ruby_nn57"></a>31.10 Memory Management</H2>
|
||||
|
||||
|
||||
<p>One of the most common issues in generating SWIG bindings for
|
||||
|
|
@ -9849,7 +9849,7 @@ understanding of how the underlying library manages memory.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn58"></a>32.10.1 Mark and Sweep Garbage Collector </H3>
|
||||
<H3><a name="Ruby_nn58"></a>31.10.1 Mark and Sweep Garbage Collector </H3>
|
||||
|
||||
|
||||
<p>Ruby uses a mark and sweep garbage collector. When the garbage
|
||||
|
|
@ -9897,7 +9897,7 @@ this memory. </p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn59"></a>32.10.2 Object Ownership</H3>
|
||||
<H3><a name="Ruby_nn59"></a>31.10.2 Object Ownership</H3>
|
||||
|
||||
|
||||
<p>As described above, memory management depends on clearly
|
||||
|
|
@ -10124,7 +10124,7 @@ classes is:</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn60"></a>32.10.3 Object Tracking</H3>
|
||||
<H3><a name="Ruby_nn60"></a>31.10.3 Object Tracking</H3>
|
||||
|
||||
|
||||
<p>The remaining parts of this section will use the class library
|
||||
|
|
@ -10338,7 +10338,7 @@ methods.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn61"></a>32.10.4 Mark Functions</H3>
|
||||
<H3><a name="Ruby_nn61"></a>31.10.4 Mark Functions</H3>
|
||||
|
||||
|
||||
<p>With a bit more testing, we see that our class library still
|
||||
|
|
@ -10456,7 +10456,7 @@ test suite.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn62"></a>32.10.5 Free Functions</H3>
|
||||
<H3><a name="Ruby_nn62"></a>31.10.5 Free Functions</H3>
|
||||
|
||||
|
||||
<p>By default, SWIG creates a "free" function that is called when
|
||||
|
|
@ -10567,7 +10567,7 @@ existing Ruby object to the destroyed C++ object and raise an exception.<br>
|
|||
|
||||
|
||||
<div class="code">
|
||||
<pre>%module example<br><br>%{<br>#include "example.h"<br>%}<br><br>/* Specify that ownership is transferred to the zoo<br> when calling add_animal */<br>%apply SWIGTYPE *DISOWN { Animal* animal };<br><br>/* Track objects */<br>%trackobjects;<br><br>/* Specify the mark function */<br>%freefunc Zoo "free_Zoo";<br><br>%include "example.h"<br><br>%header %{<br> static void free_Zoo(void* ptr) {<br> Zoo* zoo = (Zoo*) ptr;<br><br> /* Loop over each animal */<br> int count = zoo->get_num_animals();<br><br> for(int i = 0; i < count; ++i) {<br> /* Get an animal */<br> Animal* animal = zoo->get_animal(i);<br><br> /* Unlink the Ruby object from the C++ object */<br> SWIG_RubyUnlinkObjects(animal);<br><br> /* Now remove the tracking for this animal */<br> SWIG_RubyRemoveTracking(animal);<br> }<br><br> /* Now call SWIG_RubyRemoveTracking for the zoo */<br> SWIG_RubyRemoveTracking(ptr);<br> <br> /* Now free the zoo which will free the animals it contains */<br> delete zoo;<br> }<br>%} </pre>
|
||||
<pre>%module example<br><br>%{<br>#include "example.h"<br>%}<br><br>/* Specify that ownership is transferred to the zoo<br> when calling add_animal */<br>%apply SWIGTYPE *DISOWN { Animal* animal };<br><br>/* Track objects */<br>%trackobjects;<br><br>/* Specify the mark function */<br>%freefunc Zoo "free_Zoo";<br><br>%include "example.h"<br><br>%header %{<br> static void free_Zoo(void* ptr) {<br> Zoo* zoo = (Zoo*) ptr;<br><br> /* Loop over each animal */<br> int count = zoo->get_num_animals();<br><br> for(int i = 0; i < count; ++i) {<br> /* Get an animal */<br> Animal* animal = zoo->get_animal(i);<br><br> /* Unlink the Ruby object from the C++ object */<br> SWIG_RubyUnlinkObjects(animal);<br><br> /* Now remove the tracking for this animal */<br> SWIG_RubyRemoveTracking(animal);<br> }<br><br> /* Now call SWIG_RemoveMapping for the zoo */<br> SWIG_RemoveMapping(ptr);<br> <br> /* Now free the zoo which will free the animals it contains */<br> delete zoo;<br> }<br>%} </pre>
|
||||
|
||||
|
||||
|
||||
|
|
@ -10611,7 +10611,7 @@ been freed, and thus raises a runtime exception.</p>
|
|||
|
||||
|
||||
|
||||
<H3><a name="Ruby_nn63"></a>32.10.6 Embedded Ruby and the C++ Stack</H3>
|
||||
<H3><a name="Ruby_nn63"></a>31.10.6 Embedded Ruby and the C++ Stack</H3>
|
||||
|
||||
|
||||
<p>As has been said, the Ruby GC runs and marks objects before
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
<li><a href="#SWIG_nn33">Character strings and structures</a>
|
||||
<li><a href="#SWIG_nn34">Array members</a>
|
||||
<li><a href="#SWIG_structure_data_members">Structure data members</a>
|
||||
<li><a href="#SWIG_nn36">C constructors and destructors</a>
|
||||
<li><a href="#SWIG_nn36">C constructors and destructors </a>
|
||||
<li><a href="#SWIG_adding_member_functions">Adding member functions to C structures</a>
|
||||
<li><a href="#SWIG_nested_structs">Nested structures</a>
|
||||
<li><a href="#SWIG_nn39">Other things to note about structure wrapping</a>
|
||||
|
|
@ -120,7 +120,8 @@ can be obtained by typing <tt>swig -help</tt> or <tt>swig
|
|||
-mzscheme Generate Mzscheme wrappers
|
||||
-ocaml Generate Ocaml wrappers
|
||||
-perl Generate Perl wrappers
|
||||
-php Generate PHP wrappers
|
||||
-php4 Generate PHP4 wrappers
|
||||
-php5 Generate PHP5 wrappers
|
||||
-pike Generate Pike wrappers
|
||||
-python Generate Python wrappers
|
||||
-r Generate R (aka GNU S) wrappers
|
||||
|
|
@ -139,7 +140,6 @@ can be obtained by typing <tt>swig -help</tt> or <tt>swig
|
|||
-l<em>file</em> Include a SWIG library file.
|
||||
-module <em>name</em> Set the name of the SWIG module
|
||||
-o <em>outfile</em> Name of output file
|
||||
-outcurrentdir Set default output dir to current dir instead of input file's path
|
||||
-outdir <em>dir</em> Set language specific files output directory
|
||||
-swiglib Show location of SWIG library
|
||||
-version Show SWIG version number
|
||||
|
|
@ -224,7 +224,7 @@ The C/C++ output file created by SWIG often
|
|||
contains everything that is needed to construct a extension module
|
||||
for the target scripting language. SWIG is not a stub compiler nor is it
|
||||
usually necessary to edit the output file (and if you look at the output,
|
||||
you probably won't want to). To build the final extension module, the
|
||||
you probably won't want to). To build the final extension module, the
|
||||
SWIG output file is compiled and linked with the rest of your C/C++
|
||||
program to create a shared library.
|
||||
</p>
|
||||
|
|
@ -232,7 +232,7 @@ program to create a shared library.
|
|||
<p>
|
||||
Many target languages will also generate proxy class files in the
|
||||
target language. The default output directory for these language
|
||||
specific files is the same directory as the generated C/C++ file. This
|
||||
specific files is the same directory as the generated C/C++ file. This can
|
||||
can be modified using the <tt>-outdir</tt> option. For example:
|
||||
</p>
|
||||
|
||||
|
|
@ -247,17 +247,6 @@ cppfiles/example_wrap.cpp
|
|||
pyfiles/example.py
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
If the <tt>-outcurrentdir</tt> option is used (without <tt>-o</tt>)
|
||||
then SWIG behaves like a typical C/C++
|
||||
compiler and the default output directory is then the current directory. Without
|
||||
this option the default output directory is the path to the input file.
|
||||
If <tt>-o</tt> and
|
||||
<tt>-outcurrentdir</tt> are used together, <tt>-outcurrentdir</tt> is effectively ignored
|
||||
as the output directory for the language files is the same directory as the
|
||||
generated C/C++ file if not overidden with <tt>-outdir</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="SWIG_nn5"></a>5.1.3 Comments</H3>
|
||||
|
||||
|
||||
|
|
@ -2230,13 +2219,13 @@ void Foo_w_set(FOO *f, WORD value) {
|
|||
|
||||
|
||||
<p>
|
||||
<b>Compatibility Note:</b> SWIG-1.3.11 and earlier releases transformed all non-primitive member datatypes
|
||||
to pointers. Starting in SWIG-1.3.12, this transformation <em>only</em> occurs if a datatype is known to be a structure,
|
||||
class, or union. This is unlikely to break existing code. However, if you need to tell SWIG that an undeclared
|
||||
<b>Compatibility Note: </b> SWIG-1.3.11 and earlier releases transformed all non-primitive member datatypes
|
||||
to pointers. Starting in SWIG-1.3.12, this transformation <em>only</em> occurs if a datatype is known to be a structure,
|
||||
class, or union. This is unlikely to break existing code. However, if you need to tell SWIG that an undeclared
|
||||
datatype is really a struct, simply use a forward struct declaration such as <tt>"struct Foo;"</tt>.
|
||||
</p>
|
||||
|
||||
<H3><a name="SWIG_nn36"></a>5.5.5 C constructors and destructors</H3>
|
||||
<H3><a name="SWIG_nn36"></a>5.5.5 C constructors and destructors </H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2293,7 +2282,7 @@ struct Bar { // Default constructor generated.
|
|||
Since ignoring the implicit or default destructors most of the times
|
||||
produce memory leaks, SWIG will always try to generate them. If
|
||||
needed, however, you can selectively disable the generation of the
|
||||
default/implicit destructor by using <tt>%nodefaultdtor</tt>
|
||||
default/implicit destructor by using <tt>%nodefaultdtor </tt>
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
|
|
@ -2737,16 +2726,11 @@ the module upon loading.
|
|||
|
||||
<p>
|
||||
Code is inserted into the appropriate code section by using one
|
||||
of the code insertion directives listed below. The order of the sections in
|
||||
the wrapper file is as shown:
|
||||
of the following code insertion directives:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%begin %{
|
||||
... code in begin section ...
|
||||
%}
|
||||
|
||||
%runtime %{
|
||||
... code in runtime section ...
|
||||
%}
|
||||
|
|
@ -2767,12 +2751,10 @@ the wrapper file is as shown:
|
|||
|
||||
<p>
|
||||
The bare <tt>%{ ... %}</tt> directive is a shortcut that is the same as
|
||||
<tt>%header %{ ... %}</tt>.
|
||||
<tt>%header %{ ... %}</tt>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The <tt>%begin</tt> section is effectively empty as it just contains the SWIG banner by default.
|
||||
This section is provided as a way for users to insert code at the top of the wrapper file before any other code is generated.
|
||||
Everything in a code insertion block is copied verbatim into the output file and is
|
||||
not parsed by SWIG. Most SWIG input files have at least one such block to include header
|
||||
files and support C code. Additional code blocks may be placed anywhere in a
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Sections"></a>SWIG-1.3 Development Documentation</H1>
|
||||
|
||||
Last update : SWIG-1.3.40 (in progress)
|
||||
Last update : SWIG-1.3.37 (in progress)
|
||||
|
||||
<H2>Sections</H2>
|
||||
|
||||
|
|
@ -35,7 +35,6 @@ to help!).
|
|||
<li><a href="Varargs.html#Varargs">Variable length arguments</a></li>
|
||||
<li><a href="Warnings.html#Warnings">Warning messages</a></li>
|
||||
<li><a href="Modules.html#Modules">Working with Modules</a></li>
|
||||
<li><a href="CCache.html#CCache">Using SWIG with ccache</a></li>
|
||||
</ul>
|
||||
|
||||
<H3>Language Module Documentation</H3>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Tcl"></a>33 SWIG and Tcl</H1>
|
||||
<H1><a name="Tcl"></a>32 SWIG and Tcl</H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
|
|
@ -82,7 +82,7 @@ Tcl 8.0 or a later release. Earlier releases of SWIG supported Tcl 7.x, but
|
|||
this is no longer supported.
|
||||
</p>
|
||||
|
||||
<H2><a name="Tcl_nn2"></a>33.1 Preliminaries</H2>
|
||||
<H2><a name="Tcl_nn2"></a>32.1 Preliminaries</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -108,7 +108,7 @@ build a Tcl extension module. To finish building the module, you
|
|||
need to compile this file and link it with the rest of your program.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn3"></a>33.1.1 Getting the right header files</H3>
|
||||
<H3><a name="Tcl_nn3"></a>32.1.1 Getting the right header files</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -126,7 +126,7 @@ this is the case, you should probably make a symbolic link so that <tt>tcl.h</tt
|
|||
header file.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn4"></a>33.1.2 Compiling a dynamic module</H3>
|
||||
<H3><a name="Tcl_nn4"></a>32.1.2 Compiling a dynamic module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -161,7 +161,7 @@ The name of the module is specified using the <tt>%module</tt> directive or the
|
|||
<tt> -module</tt> command line option.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn5"></a>33.1.3 Static linking</H3>
|
||||
<H3><a name="Tcl_nn5"></a>32.1.3 Static linking</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -227,7 +227,7 @@ minimal in most situations (and quite frankly not worth the extra
|
|||
hassle in the opinion of this author).
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn6"></a>33.1.4 Using your module</H3>
|
||||
<H3><a name="Tcl_nn6"></a>32.1.4 Using your module</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -355,7 +355,7 @@ to the default system configuration (this requires root access and you will need
|
|||
the man pages).
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn7"></a>33.1.5 Compilation of C++ extensions</H3>
|
||||
<H3><a name="Tcl_nn7"></a>32.1.5 Compilation of C++ extensions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -438,7 +438,7 @@ erratic program behavior. If working with lots of software components, you
|
|||
might want to investigate using a more formal standard such as COM.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn8"></a>33.1.6 Compiling for 64-bit platforms</H3>
|
||||
<H3><a name="Tcl_nn8"></a>32.1.6 Compiling for 64-bit platforms</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -465,7 +465,7 @@ also introduce problems on platforms that support more than one
|
|||
linking standard (e.g., -o32 and -n32 on Irix).
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn9"></a>33.1.7 Setting a package prefix</H3>
|
||||
<H3><a name="Tcl_nn9"></a>32.1.7 Setting a package prefix</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -484,7 +484,7 @@ option will append the prefix to the name when creating a command and
|
|||
call it "<tt>Foo_bar</tt>".
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn10"></a>33.1.8 Using namespaces</H3>
|
||||
<H3><a name="Tcl_nn10"></a>32.1.8 Using namespaces</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -506,7 +506,7 @@ When the<tt> -namespace</tt> option is used, objects in the module
|
|||
are always accessed with the namespace name such as <tt>Foo::bar</tt>.
|
||||
</p>
|
||||
|
||||
<H2><a name="Tcl_nn11"></a>33.2 Building Tcl/Tk Extensions under Windows 95/NT</H2>
|
||||
<H2><a name="Tcl_nn11"></a>32.2 Building Tcl/Tk Extensions under Windows 95/NT</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -517,7 +517,7 @@ covers the process of using SWIG with Microsoft Visual C++.
|
|||
although the procedure may be similar with other compilers.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn12"></a>33.2.1 Running SWIG from Developer Studio</H3>
|
||||
<H3><a name="Tcl_nn12"></a>32.2.1 Running SWIG from Developer Studio</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -575,7 +575,7 @@ MSDOS > tclsh80
|
|||
%
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Tcl_nn13"></a>33.2.2 Using NMAKE</H3>
|
||||
<H3><a name="Tcl_nn13"></a>32.2.2 Using NMAKE</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -638,7 +638,7 @@ to get you started. With a little practice, you'll be making lots of
|
|||
Tcl extensions.
|
||||
</p>
|
||||
|
||||
<H2><a name="Tcl_nn14"></a>33.3 A tour of basic C/C++ wrapping</H2>
|
||||
<H2><a name="Tcl_nn14"></a>32.3 A tour of basic C/C++ wrapping</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -649,7 +649,7 @@ classes. This section briefly covers the essential aspects of this
|
|||
wrapping.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn15"></a>33.3.1 Modules</H3>
|
||||
<H3><a name="Tcl_nn15"></a>32.3.1 Modules</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -683,7 +683,7 @@ To fix this, supply an extra argument to <tt>load</tt> like this:
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Tcl_nn16"></a>33.3.2 Functions</H3>
|
||||
<H3><a name="Tcl_nn16"></a>32.3.2 Functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -708,7 +708,7 @@ like you think it does:
|
|||
%
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Tcl_nn17"></a>33.3.3 Global variables</H3>
|
||||
<H3><a name="Tcl_nn17"></a>32.3.3 Global variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -788,7 +788,7 @@ extern char *path; // Read-only (due to %immutable)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Tcl_nn18"></a>33.3.4 Constants and enums</H3>
|
||||
<H3><a name="Tcl_nn18"></a>32.3.4 Constants and enums</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -872,7 +872,7 @@ When an identifier name is given, it is used to perform an implicit hash-table l
|
|||
conversion. This allows the <tt>global</tt> statement to be omitted.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn19"></a>33.3.5 Pointers</H3>
|
||||
<H3><a name="Tcl_nn19"></a>32.3.5 Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -968,7 +968,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return
|
|||
<tt>None</tt> if the conversion can't be performed.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn20"></a>33.3.6 Structures</H3>
|
||||
<H3><a name="Tcl_nn20"></a>32.3.6 Structures</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1250,7 +1250,7 @@ Note: Tcl only destroys the underlying object if it has ownership. See the
|
|||
memory management section that appears shortly.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn21"></a>33.3.7 C++ classes</H3>
|
||||
<H3><a name="Tcl_nn21"></a>32.3.7 C++ classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1317,7 +1317,7 @@ In Tcl, the static member is accessed as follows:
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Tcl_nn22"></a>33.3.8 C++ inheritance</H3>
|
||||
<H3><a name="Tcl_nn22"></a>32.3.8 C++ inheritance</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1366,7 +1366,7 @@ For instance:
|
|||
It is safe to use multiple inheritance with SWIG.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn23"></a>33.3.9 Pointers, references, values, and arrays</H3>
|
||||
<H3><a name="Tcl_nn23"></a>32.3.9 Pointers, references, values, and arrays</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1420,7 +1420,7 @@ to hold the result and a pointer is returned (Tcl will release this memory
|
|||
when the return value is garbage collected).
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn24"></a>33.3.10 C++ overloaded functions</H3>
|
||||
<H3><a name="Tcl_nn24"></a>32.3.10 C++ overloaded functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1543,7 +1543,7 @@ first declaration takes precedence.
|
|||
Please refer to the "SWIG and C++" chapter for more information about overloading.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn25"></a>33.3.11 C++ operators</H3>
|
||||
<H3><a name="Tcl_nn25"></a>32.3.11 C++ operators</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1645,7 +1645,7 @@ There are ways to make this operator appear as part of the class using the <tt>%
|
|||
Keep reading.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn26"></a>33.3.12 C++ namespaces</H3>
|
||||
<H3><a name="Tcl_nn26"></a>32.3.12 C++ namespaces</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1709,7 +1709,7 @@ utilizes thousands of small deeply nested namespaces each with
|
|||
identical symbol names, well, then you get what you deserve.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn27"></a>33.3.13 C++ templates</H3>
|
||||
<H3><a name="Tcl_nn27"></a>32.3.13 C++ templates</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1761,7 +1761,7 @@ More details can be found in the <a href="SWIGPlus.html#SWIGPlus">SWIG and C++</
|
|||
examples will appear later.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn28"></a>33.3.14 C++ Smart Pointers</H3>
|
||||
<H3><a name="Tcl_nn28"></a>32.3.14 C++ Smart Pointers</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1845,7 +1845,7 @@ simply use the <tt>__deref__()</tt> method. For example:
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="Tcl_nn29"></a>33.4 Further details on the Tcl class interface</H2>
|
||||
<H2><a name="Tcl_nn29"></a>32.4 Further details on the Tcl class interface</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1858,7 +1858,7 @@ of low-level details were omitted. This section provides a brief overview
|
|||
of how the proxy classes work.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn30"></a>33.4.1 Proxy classes</H3>
|
||||
<H3><a name="Tcl_nn30"></a>32.4.1 Proxy classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -1923,7 +1923,7 @@ function. This allows objects to be encapsulated objects that look a lot like
|
|||
as shown in the last section.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn31"></a>33.4.2 Memory management</H3>
|
||||
<H3><a name="Tcl_nn31"></a>32.4.2 Memory management</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2111,7 +2111,7 @@ typemaps--an advanced topic discussed later.
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="Tcl_nn32"></a>33.5 Input and output parameters</H2>
|
||||
<H2><a name="Tcl_nn32"></a>32.5 Input and output parameters</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2299,7 +2299,7 @@ set c [lindex $dim 1]
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="Tcl_nn33"></a>33.6 Exception handling </H2>
|
||||
<H2><a name="Tcl_nn33"></a>32.6 Exception handling </H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2433,7 +2433,7 @@ Since SWIG's exception handling is user-definable, you are not limited to C++ ex
|
|||
See the chapter on "<a href="Customization.html#Customization">Customization Features</a>" for more examples.
|
||||
</p>
|
||||
|
||||
<H2><a name="Tcl_nn34"></a>33.7 Typemaps</H2>
|
||||
<H2><a name="Tcl_nn34"></a>32.7 Typemaps</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2450,7 +2450,7 @@ Typemaps are only used if you want to change some aspect of the primitive
|
|||
C-Tcl interface.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn35"></a>33.7.1 What is a typemap?</H3>
|
||||
<H3><a name="Tcl_nn35"></a>32.7.1 What is a typemap?</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2567,7 +2567,7 @@ parameter is omitted):
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Tcl_nn36"></a>33.7.2 Tcl typemaps</H3>
|
||||
<H3><a name="Tcl_nn36"></a>32.7.2 Tcl typemaps</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2705,7 +2705,7 @@ Initialize an argument to a value before any conversions occur.
|
|||
Examples of these methods will appear shortly.
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn37"></a>33.7.3 Typemap variables</H3>
|
||||
<H3><a name="Tcl_nn37"></a>32.7.3 Typemap variables</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2776,7 +2776,7 @@ properly assigned.
|
|||
The Tcl name of the wrapper function being created.
|
||||
</div>
|
||||
|
||||
<H3><a name="Tcl_nn38"></a>33.7.4 Converting a Tcl list to a char ** </H3>
|
||||
<H3><a name="Tcl_nn38"></a>32.7.4 Converting a Tcl list to a char ** </H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2838,7 +2838,7 @@ argv[2] = Larry
|
|||
3
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Tcl_nn39"></a>33.7.5 Returning values in arguments</H3>
|
||||
<H3><a name="Tcl_nn39"></a>32.7.5 Returning values in arguments</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2880,7 +2880,7 @@ result, a Tcl function using these typemaps will work like this :
|
|||
%
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Tcl_nn40"></a>33.7.6 Useful functions</H3>
|
||||
<H3><a name="Tcl_nn40"></a>32.7.6 Useful functions</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -2957,7 +2957,7 @@ int Tcl_IsShared(Tcl_Obj *obj);
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Tcl_nn41"></a>33.7.7 Standard typemaps</H3>
|
||||
<H3><a name="Tcl_nn41"></a>32.7.7 Standard typemaps</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3041,7 +3041,7 @@ work)
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="Tcl_nn42"></a>33.7.8 Pointer handling</H3>
|
||||
<H3><a name="Tcl_nn42"></a>32.7.8 Pointer handling</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3117,7 +3117,7 @@ For example:
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H2><a name="Tcl_nn43"></a>33.8 Turning a SWIG module into a Tcl Package.</H2>
|
||||
<H2><a name="Tcl_nn43"></a>32.8 Turning a SWIG module into a Tcl Package.</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3189,7 +3189,7 @@ As a final note, most SWIG examples do not yet use the
|
|||
to use the <tt>load</tt> command instead.
|
||||
</p>
|
||||
|
||||
<H2><a name="Tcl_nn44"></a>33.9 Building new kinds of Tcl interfaces (in Tcl)</H2>
|
||||
<H2><a name="Tcl_nn44"></a>32.9 Building new kinds of Tcl interfaces (in Tcl)</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
@ -3288,7 +3288,7 @@ danger of blowing something up (although it is easily accomplished
|
|||
with an out of bounds array access).
|
||||
</p>
|
||||
|
||||
<H3><a name="Tcl_nn45"></a>33.9.1 Proxy classes</H3>
|
||||
<H3><a name="Tcl_nn45"></a>32.9.1 Proxy classes</H3>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@
|
|||
<li><a href="#Typemaps_nn48">More about <tt>%apply</tt> and <tt>%clear</tt></a>
|
||||
<li><a href="#Typemaps_nn49">Reducing wrapper code size</a>
|
||||
<li><a href="#Typemaps_nn47">Passing data between typemaps</a>
|
||||
<li><a href="#Typemaps_nn52">C++ "this" pointer</a>
|
||||
<li><a href="#Typemaps_nn51">Where to go for more information?</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -3900,66 +3899,7 @@ sure that the typemaps sharing information have exactly the same types and names
|
|||
</p>
|
||||
|
||||
|
||||
<H2><a name="Typemaps_nn52"></a>10.15 C++ "this" pointer</H2>
|
||||
|
||||
|
||||
<p>
|
||||
All the rules discussed for Typemaps apply to C++ as well as C.
|
||||
However in addition C++ passes an extra parameter into every
|
||||
non-static class method -- the <tt>this</tt> pointer. Occasionally it can be
|
||||
useful to apply a typemap to this pointer (for example to check
|
||||
and make sure <tt>this</tt> is non-null before deferencing).
|
||||
Actually, C also has an the equivalent of the <tt>this</tt> pointer which is used
|
||||
when accessing variables in a C struct.
|
||||
</p>
|
||||
<p>
|
||||
In order to customise the <tt>this</tt> pointer handling, target a variable named <tt>self</tt> in your typemaps.
|
||||
<tt>self</tt> is the name SWIG uses to refer to the extra parameter in wrapped functions.
|
||||
</p>
|
||||
<p>
|
||||
For example, if wrapping for Java generation:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%typemap(check) SWIGTYPE *self %{
|
||||
if (!$1) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "swigCPtr null");
|
||||
return $null;
|
||||
}
|
||||
%}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
In the above case, the <tt>$1</tt> variable is expanded into the argument
|
||||
name that SWIG is using as the <tt>this</tt> pointer.
|
||||
|
||||
SWIG will then insert the check code before the actual C++ class method
|
||||
is called, and will raise an exception rather than crash
|
||||
the Java virtual machine.
|
||||
|
||||
The generated code will look something like:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
if (!arg1) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException,
|
||||
"invalid native object; delete() likely already called");
|
||||
return ;
|
||||
}
|
||||
(arg1)->wrappedFunction(...);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Note that if you have a parameter named <tt>self</tt> then it
|
||||
will also match the typemap. One work around is to create an interface file that wraps
|
||||
the method, but give the argument a name other than <tt>self</tt>.
|
||||
</p>
|
||||
|
||||
<H2><a name="Typemaps_nn51"></a>10.16 Where to go for more information?</H2>
|
||||
<H2><a name="Typemaps_nn51"></a>10.15 Where to go for more information?</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -558,7 +558,7 @@ example.i(4): Syntax error in input.
|
|||
</ul>
|
||||
|
||||
<ul>
|
||||
<li>870. Warning for <em>classname</em>: Base <em>baseclass</em> ignored. Multiple inheritance is not supported in PHP.
|
||||
<li>870. Warning for <em>classname</em>: Base <em>baseclass</em> ignored. Multiple inheritance is not supported in Php4. (Php).
|
||||
<li>871. Unrecognized pragma <em>pragma</em>. (Php).
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -281,7 +281,7 @@ Execute the steps in the order shown and don't use spaces in path names. In fact
|
|||
</li>
|
||||
|
||||
<li>
|
||||
Copy the following to the MSYS install folder (C:\msys\1.0 is default):
|
||||
Copy the followig to the MSYS install folder (C:\msys\1.0 is default):
|
||||
<ul>
|
||||
<li>msys-automake-1.8.2.tar.bz2</li>
|
||||
<li>msys-autoconf-2.59.tar.bz2</li>
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ Contract.html
|
|||
Varargs.html
|
||||
Warnings.html
|
||||
Modules.html
|
||||
CCache.html
|
||||
Allegrocl.html
|
||||
C.html
|
||||
CSharp.html
|
||||
Chicken.html
|
||||
Guile.html
|
||||
|
|
|
|||
0
Doc/Manual/swig16.png
Normal file → Executable file
0
Doc/Manual/swig16.png
Normal file → Executable file
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
|
@ -2,5 +2,4 @@ Doc/Manual - Latest version of the SWIG user manual
|
|||
Doc/Devel - Developer documentation concerning SWIG internals.
|
||||
(not necessarily up to date)
|
||||
|
||||
Open the index.html file in each of these directories with a web browser.
|
||||
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
This example runs the entire gifplot.h header file through SWIG without
|
||||
any changes. The program 'runme.java' does something a little more
|
||||
interesting. After doing a make, run it using 'java runme'. You'll have to go
|
||||
any changes. The program 'main.java' does something a little more
|
||||
interesting. After doing a make, run it using 'java main'. You'll have to go
|
||||
look at the header file to get a complete listing of the functions.
|
||||
|
||||
Note the differences in the runme.java files between this example and the
|
||||
Note the differences in the main.java files between this example and the
|
||||
'full' example. This example does not use shadow classes.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Plot a 3D function
|
||||
import java.lang.Math;
|
||||
|
||||
public class runme {
|
||||
public class main {
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SWIGOPT = -outcurrentdir
|
||||
SWIGOPT = -I../../Interface
|
||||
SRCS =
|
||||
TARGET = gifplot
|
||||
INTERFACEDIR = ../../Interface/
|
||||
INTERFACE = gifplot.i
|
||||
LIBS = -L../.. -lgifplot
|
||||
INCLUDES = -I../../Include
|
||||
|
|
@ -11,7 +10,7 @@ INCLUDES = -I../../Include
|
|||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' java
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java
|
||||
javac *.java
|
||||
|
||||
clean::
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
This example uses the file in ../../Interface/gifplot.i to build
|
||||
an interface with shadow classes. After doing a make, run the program runme, ie: 'java runme'.
|
||||
an interface with shadow classes. After doing a make, run the program main, ie: 'java main'.
|
||||
|
||||
Note the differences in the runme.java files between this example and the
|
||||
Note the differences in the main.java files between this example and the
|
||||
'full' example. This example uses the shadow classes.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import java.lang.Math;
|
||||
|
||||
public class runme {
|
||||
public class main {
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
This is a very minimalistic example in which just a few functions
|
||||
and constants from library are wrapped and used to draw some simple
|
||||
shapes. After doing a make, run the java program, ie 'java runme'.
|
||||
shapes. After doing a make, run the java program, ie 'java main'.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
public class runme {
|
||||
public class main {
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -132,10 +132,7 @@ int ColorMap_write(ColorMap *cm, char *filename) {
|
|||
|
||||
f = fopen(filename,"w");
|
||||
|
||||
if (fwrite(cm->cmap,768,1,f) != 1) {
|
||||
fclose(f);
|
||||
return -1;
|
||||
}
|
||||
fwrite(cm->cmap,768,1,f);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ static int maxmaxcode = 1 << GP_BITS; /* NEVER generate this */
|
|||
|
||||
static count_int *htab;
|
||||
static unsigned short *codetab;
|
||||
static int GIFOutBufSize;
|
||||
static GIFOutBufSize;
|
||||
|
||||
/* static count_int htab [HSIZE];
|
||||
static unsigned short codetab [HSIZE]; */
|
||||
|
|
@ -656,11 +656,7 @@ int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename) {
|
|||
fclose(file);
|
||||
return -1;
|
||||
}
|
||||
if (fwrite(buffer,nbytes,1,file) != 1) {
|
||||
free(buffer);
|
||||
fclose(file);
|
||||
return -1;
|
||||
}
|
||||
fwrite(buffer,nbytes,1,file);
|
||||
fclose(file);
|
||||
free(buffer);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SWIGOPT = -outcurrentdir
|
||||
SWIGOPT = -I../../Interface
|
||||
SRCS =
|
||||
TARGET = gifplot
|
||||
INTERFACEDIR = ../../Interface/
|
||||
INTERFACE = gifplot.i
|
||||
LIBS = -L../.. -lgifplot -lm
|
||||
INCLUDES = -I../../Include
|
||||
|
|
@ -11,12 +10,12 @@ INCLUDES = -I../../Include
|
|||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' perl5
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='myperl' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' perl5_static
|
||||
TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile perl5_clean
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ INCLUDES = -I../../Include
|
|||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php4
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile php_clean
|
||||
$(MAKE) -f $(TOP)/Makefile php4_clean
|
||||
rm -f *.gif
|
||||
rm -f php_gifplot.h
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue