--- rpy-1.0.3.orig/GPL_LICENSE +++ rpy-1.0.3/GPL_LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 + + 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. + + + Copyright (C) + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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) year 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. + + , 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. --- rpy-1.0.3.orig/LGPL_LICENSE +++ rpy-1.0.3/LGPL_LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +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 and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, 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 library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete 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 distribute a copy of this License along with the +Library. + + 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 Library or any portion +of it, thus forming a work based on the Library, 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) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +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 Library, 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 Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you 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. + + If distribution of 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 satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be 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. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library 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. + + 9. 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 Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +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 with +this License. + + 11. 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 Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library 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 Library. + +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. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library 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. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser 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 Library +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 Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +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 + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. 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 LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. 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. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + --- rpy-1.0.3.orig/MPL_LICENSE +++ rpy-1.0.3/MPL_LICENSE @@ -0,0 +1,470 @@ + MOZILLA PUBLIC LICENSE + Version 1.1 + + --------------- + +1. Definitions. + + 1.0.1. "Commercial Use" means distribution or otherwise making the + Covered Code available to a third party. + + 1.1. "Contributor" means each entity that creates or contributes to + the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original + Code, prior Modifications used by a Contributor, and the Modifications + made by that particular Contributor. + + 1.3. "Covered Code" means the Original Code or Modifications or the + combination of the Original Code and Modifications, in each case + including portions thereof. + + 1.4. "Electronic Distribution Mechanism" means a mechanism generally + accepted in the software development community for the electronic + transfer of data. + + 1.5. "Executable" means Covered Code in any form other than Source + Code. + + 1.6. "Initial Developer" means the individual or entity identified + as the Initial Developer in the Source Code notice required by Exhibit + A. + + 1.7. "Larger Work" means a work which combines Covered Code or + portions thereof with code not governed by the terms of this License. + + 1.8. "License" means this document. + + 1.8.1. "Licensable" means having the right to grant, to the maximum + extent possible, whether at the time of the initial grant or + subsequently acquired, any and all of the rights conveyed herein. + + 1.9. "Modifications" means any addition to or deletion from the + substance or structure of either the Original Code or any previous + Modifications. When Covered Code is released as a series of files, a + Modification is: + A. Any addition to or deletion from the contents of a file + containing Original Code or previous Modifications. + + B. Any new file that contains any part of the Original Code or + previous Modifications. + + 1.10. "Original Code" means Source Code of computer software code + which is described in the Source Code notice required by Exhibit A as + Original Code, and which, at the time of its release under this + License is not already Covered Code governed by this License. + + 1.10.1. "Patent Claims" means any patent claim(s), now owned or + hereafter acquired, including without limitation, method, process, + and apparatus claims, in any patent Licensable by grantor. + + 1.11. "Source Code" means the preferred form of the Covered Code for + making modifications to it, including all modules it contains, plus + any associated interface definition files, scripts used to control + compilation and installation of an Executable, or source code + differential comparisons against either the Original Code or another + well known, available Covered Code of the Contributor's choice. The + Source Code can be in a compressed or archival form, provided the + appropriate decompression or de-archiving software is widely available + for no charge. + + 1.12. "You" (or "Your") means an individual or a legal entity + exercising rights under, and complying with all of the terms of, this + License or a future version of this License issued under Section 6.1. + For legal entities, "You" includes any entity which controls, is + controlled by, or is under common control with You. For purposes of + this definition, "control" means (a) the power, direct or indirect, + to cause the direction or management of such entity, whether by + contract or otherwise, or (b) ownership of more than fifty percent + (50%) of the outstanding shares or beneficial ownership of such + entity. + +2. Source Code License. + + 2.1. The Initial Developer Grant. + The Initial Developer hereby grants You a world-wide, royalty-free, + non-exclusive license, subject to third party intellectual property + claims: + (a) under intellectual property rights (other than patent or + trademark) Licensable by Initial Developer to use, reproduce, + modify, display, perform, sublicense and distribute the Original + Code (or portions thereof) with or without Modifications, and/or + as part of a Larger Work; and + + (b) under Patents Claims infringed by the making, using or + selling of Original Code, to make, have made, use, practice, + sell, and offer for sale, and/or otherwise dispose of the + Original Code (or portions thereof). + + (c) the licenses granted in this Section 2.1(a) and (b) are + effective on the date Initial Developer first distributes + Original Code under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is + granted: 1) for code that You delete from the Original Code; 2) + separate from the Original Code; or 3) for infringements caused + by: i) the modification of the Original Code or ii) the + combination of the Original Code with other software or devices. + + 2.2. Contributor Grant. + Subject to third party intellectual property claims, each Contributor + hereby grants You a world-wide, royalty-free, non-exclusive license + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Contributor, to use, reproduce, modify, + display, perform, sublicense and distribute the Modifications + created by such Contributor (or portions thereof) either on an + unmodified basis, with other Modifications, as Covered Code + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or + selling of Modifications made by that Contributor either alone + and/or in combination with its Contributor Version (or portions + of such combination), to make, use, sell, offer for sale, have + made, and/or otherwise dispose of: 1) Modifications made by that + Contributor (or portions thereof); and 2) the combination of + Modifications made by that Contributor with its Contributor + Version (or portions of such combination). + + (c) the licenses granted in Sections 2.2(a) and 2.2(b) are + effective on the date Contributor first makes Commercial Use of + the Covered Code. + + (d) Notwithstanding Section 2.2(b) above, no patent license is + granted: 1) for any code that Contributor has deleted from the + Contributor Version; 2) separate from the Contributor Version; + 3) for infringements caused by: i) third party modifications of + Contributor Version or ii) the combination of Modifications made + by that Contributor with other software (except as part of the + Contributor Version) or other devices; or 4) under Patent Claims + infringed by Covered Code in the absence of Modifications made by + that Contributor. + +3. Distribution Obligations. + + 3.1. Application of License. + The Modifications which You create or to which You contribute are + governed by the terms of this License, including without limitation + Section 2.2. The Source Code version of Covered Code may be + distributed only under the terms of this License or a future version + of this License released under Section 6.1, and You must include a + copy of this License with every copy of the Source Code You + distribute. You may not offer or impose any terms on any Source Code + version that alters or restricts the applicable version of this + License or the recipients' rights hereunder. However, You may include + an additional document offering the additional rights described in + Section 3.5. + + 3.2. Availability of Source Code. + Any Modification which You create or to which You contribute must be + made available in Source Code form under the terms of this License + either on the same media as an Executable version or via an accepted + Electronic Distribution Mechanism to anyone to whom you made an + Executable version available; and if made available via Electronic + Distribution Mechanism, must remain available for at least twelve (12) + months after the date it initially became available, or at least six + (6) months after a subsequent version of that particular Modification + has been made available to such recipients. You are responsible for + ensuring that the Source Code version remains available even if the + Electronic Distribution Mechanism is maintained by a third party. + + 3.3. Description of Modifications. + You must cause all Covered Code to which You contribute to contain a + file documenting the changes You made to create that Covered Code and + the date of any change. You must include a prominent statement that + the Modification is derived, directly or indirectly, from Original + Code provided by the Initial Developer and including the name of the + Initial Developer in (a) the Source Code, and (b) in any notice in an + Executable version or related documentation in which You describe the + origin or ownership of the Covered Code. + + 3.4. Intellectual Property Matters + (a) Third Party Claims. + If Contributor has knowledge that a license under a third party's + intellectual property rights is required to exercise the rights + granted by such Contributor under Sections 2.1 or 2.2, + Contributor must include a text file with the Source Code + distribution titled "LEGAL" which describes the claim and the + party making the claim in sufficient detail that a recipient will + know whom to contact. If Contributor obtains such knowledge after + the Modification is made available as described in Section 3.2, + Contributor shall promptly modify the LEGAL file in all copies + Contributor makes available thereafter and shall take other steps + (such as notifying appropriate mailing lists or newsgroups) + reasonably calculated to inform those who received the Covered + Code that new knowledge has been obtained. + + (b) Contributor APIs. + If Contributor's Modifications include an application programming + interface and Contributor has knowledge of patent licenses which + are reasonably necessary to implement that API, Contributor must + also include this information in the LEGAL file. + + (c) Representations. + Contributor represents that, except as disclosed pursuant to + Section 3.4(a) above, Contributor believes that Contributor's + Modifications are Contributor's original creation(s) and/or + Contributor has sufficient rights to grant the rights conveyed by + this License. + + 3.5. Required Notices. + You must duplicate the notice in Exhibit A in each file of the Source + Code. If it is not possible to put such notice in a particular Source + Code file due to its structure, then You must include such notice in a + location (such as a relevant directory) where a user would be likely + to look for such a notice. If You created one or more Modification(s) + You may add your name as a Contributor to the notice described in + Exhibit A. You must also duplicate this License in any documentation + for the Source Code where You describe recipients' rights or ownership + rights relating to Covered Code. You may choose to offer, and to + charge a fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Code. However, You + may do so only on Your own behalf, and not on behalf of the Initial + Developer or any Contributor. You must make it absolutely clear than + any such warranty, support, indemnity or liability obligation is + offered by You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred by the + Initial Developer or such Contributor as a result of warranty, + support, indemnity or liability terms You offer. + + 3.6. Distribution of Executable Versions. + You may distribute Covered Code in Executable form only if the + requirements of Section 3.1-3.5 have been met for that Covered Code, + and if You include a notice stating that the Source Code version of + the Covered Code is available under the terms of this License, + including a description of how and where You have fulfilled the + obligations of Section 3.2. The notice must be conspicuously included + in any notice in an Executable version, related documentation or + collateral in which You describe recipients' rights relating to the + Covered Code. You may distribute the Executable version of Covered + Code or ownership rights under a license of Your choice, which may + contain terms different from this License, provided that You are in + compliance with the terms of this License and that the license for the + Executable version does not attempt to limit or alter the recipient's + rights in the Source Code version from the rights set forth in this + License. If You distribute the Executable version under a different + license You must make it absolutely clear that any terms which differ + from this License are offered by You alone, not by the Initial + Developer or any Contributor. You hereby agree to indemnify the + Initial Developer and every Contributor for any liability incurred by + the Initial Developer or such Contributor as a result of any such + terms You offer. + + 3.7. Larger Works. + You may create a Larger Work by combining Covered Code with other code + not governed by the terms of this License and distribute the Larger + Work as a single product. In such a case, You must make sure the + requirements of this License are fulfilled for the Covered Code. + +4. Inability to Comply Due to Statute or Regulation. + + If it is impossible for You to comply with any of the terms of this + License with respect to some or all of the Covered Code due to + statute, judicial order, or regulation then You must: (a) comply with + the terms of this License to the maximum extent possible; and (b) + describe the limitations and the code they affect. Such description + must be included in the LEGAL file described in Section 3.4 and must + be included with all distributions of the Source Code. Except to the + extent prohibited by statute or regulation, such description must be + sufficiently detailed for a recipient of ordinary skill to be able to + understand it. + +5. Application of this License. + + This License applies to code to which the Initial Developer has + attached the notice in Exhibit A and to related Covered Code. + +6. Versions of the License. + + 6.1. New Versions. + Netscape Communications Corporation ("Netscape") may publish revised + and/or new versions of the License from time to time. Each version + will be given a distinguishing version number. + + 6.2. Effect of New Versions. + Once Covered Code has been published under a particular version of the + License, You may always continue to use it under the terms of that + version. You may also choose to use such Covered Code under the terms + of any subsequent version of the License published by Netscape. No one + other than Netscape has the right to modify the terms applicable to + Covered Code created under this License. + + 6.3. Derivative Works. + If You create or use a modified version of this License (which you may + only do in order to apply it to code which is not already Covered Code + governed by this License), You must (a) rename Your license so that + the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", + "MPL", "NPL" or any confusingly similar phrase do not appear in your + license (except to note that your license differs from this License) + and (b) otherwise make it clear that Your version of the license + contains terms which differ from the Mozilla Public License and + Netscape Public License. (Filling in the name of the Initial + Developer, Original Code or Contributor in the notice described in + Exhibit A shall not of themselves be deemed to be modifications of + this License.) + +7. DISCLAIMER OF WARRANTY. + + COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF + DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. + THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE + IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, + YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE + COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER + OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +8. TERMINATION. + + 8.1. This License and the rights granted hereunder will terminate + automatically if You fail to comply with terms herein and fail to cure + such breach within 30 days of becoming aware of the breach. All + sublicenses to the Covered Code which are properly granted shall + survive any termination of this License. Provisions which, by their + nature, must remain in effect beyond the termination of this License + shall survive. + + 8.2. If You initiate litigation by asserting a patent infringement + claim (excluding declatory judgment actions) against Initial Developer + or a Contributor (the Initial Developer or Contributor against whom + You file such action is referred to as "Participant") alleging that: + + (a) such Participant's Contributor Version directly or indirectly + infringes any patent, then any and all rights granted by such + Participant to You under Sections 2.1 and/or 2.2 of this License + shall, upon 60 days notice from Participant terminate prospectively, + unless if within 60 days after receipt of notice You either: (i) + agree in writing to pay Participant a mutually agreeable reasonable + royalty for Your past and future use of Modifications made by such + Participant, or (ii) withdraw Your litigation claim with respect to + the Contributor Version against such Participant. If within 60 days + of notice, a reasonable royalty and payment arrangement are not + mutually agreed upon in writing by the parties or the litigation claim + is not withdrawn, the rights granted by Participant to You under + Sections 2.1 and/or 2.2 automatically terminate at the expiration of + the 60 day notice period specified above. + + (b) any software, hardware, or device, other than such Participant's + Contributor Version, directly or indirectly infringes any patent, then + any rights granted to You by such Participant under Sections 2.1(b) + and 2.2(b) are revoked effective as of the date You first made, used, + sold, distributed, or had made, Modifications made by that + Participant. + + 8.3. If You assert a patent infringement claim against Participant + alleging that such Participant's Contributor Version directly or + indirectly infringes any patent where such claim is resolved (such as + by license or settlement) prior to the initiation of patent + infringement litigation, then the reasonable value of the licenses + granted by such Participant under Sections 2.1 or 2.2 shall be taken + into account in determining the amount or value of any payment or + license. + + 8.4. In the event of termination under Sections 8.1 or 8.2 above, + all end user license agreements (excluding distributors and resellers) + which have been validly granted by You or any distributor hereunder + prior to termination shall survive termination. + +9. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL + DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, + OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR + ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY + CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, + WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY + RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW + PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE + EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO + THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + + The Covered Code is a "commercial item," as that term is defined in + 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer + software" and "commercial computer software documentation," as such + terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 + C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), + all U.S. Government End Users acquire Covered Code with only those + rights set forth herein. + +11. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. This License shall be governed by + California law provisions (except to the extent applicable law, if + any, provides otherwise), excluding its conflict-of-law provisions. + With respect to disputes in which at least one party is a citizen of, + or an entity chartered or registered to do business in the United + States of America, any litigation relating to this License shall be + subject to the jurisdiction of the Federal Courts of the Northern + District of California, with venue lying in Santa Clara County, + California, with the losing party responsible for costs, including + without limitation, court costs and reasonable attorneys' fees and + expenses. The application of the United Nations Convention on + Contracts for the International Sale of Goods is expressly excluded. + Any law or regulation which provides that the language of a contract + shall be construed against the drafter shall not apply to this + License. + +12. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or indirectly, + out of its utilization of rights under this License and You agree to + work with Initial Developer and Contributors to distribute such + responsibility on an equitable basis. Nothing herein is intended or + shall be deemed to constitute any admission of liability. + +13. MULTIPLE-LICENSED CODE. + + Initial Developer may designate portions of the Covered Code as + "Multiple-Licensed". "Multiple-Licensed" means that the Initial + Developer permits you to utilize portions of the Covered Code under + Your choice of the NPL or the alternative licenses, if any, specified + by the Initial Developer in the file described in Exhibit A. + +EXHIBIT A -Mozilla Public License. + + ``The contents of this file are subject to the Mozilla Public License + Version 1.1 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + License for the specific language governing rights and limitations + under the License. + + The Original Code is ______________________________________. + + The Initial Developer of the Original Code is ________________________. + Portions created by ______________________ are Copyright (C) ______ + _______________________. All Rights Reserved. + + Contributor(s): ______________________________________. + + Alternatively, the contents of this file may be used under the terms + of the _____ license (the "[___] License"), in which case the + provisions of [______] License are applicable instead of those + above. If you wish to allow use of your version of this file only + under the terms of the [____] License and not to allow others to use + your version of this file under the MPL, indicate your decision by + deleting the provisions above and replace them with the notice and + other provisions required by the [___] License. If you do not delete + the provisions above, a recipient may use your version of this file + under either the MPL or the [___] License." + + [NOTE: The text of this Exhibit A may differ slightly from the text of + the notices in the Source Code files of the Original Code. You should + use the text of this Exhibit A rather than the text found in the + Original Code Source Code for Your Modifications.] + --- rpy-1.0.3.orig/debian/changelog +++ rpy-1.0.3/debian/changelog @@ -1,3 +1,277 @@ +rpy (1.0.3-27) unstable; urgency=low + + * Rebuilt under R 3.0.2 + + * debian/control: Set (Build-)Depends: to current R version + + -- Dirk Eddelbuettel Sun, 29 Sep 2013 21:41:34 -0500 + +rpy (1.0.3-26) unstable; urgency=low + + * Rebuilt under R 3.0.1 + + * debian/control: Set (Build-)Depends: to current R version + * debian/control: Add 'texlive-latex-recommended' to Build-Depends + + -- Dirk Eddelbuettel Tue, 04 Jun 2013 15:16:44 -0500 + +rpy (1.0.3-25) unstable; urgency=low + + * src/RPy.h: Comment-out (Rf_)PrintWarnings() which is no longer + available under R 3.0.0; change committed to upstream SVN too + * src/rpymodule.c: Idem (Closes: #705847) + + -- Dirk Eddelbuettel Mon, 22 Apr 2013 19:22:49 -0500 + +rpy (1.0.3-24) unstable; urgency=low + + * Rebuilt under R 3.0.0 + + * debian/control: Updated for current version (Closes: #704658) + + -- Dirk Eddelbuettel Thu, 04 Apr 2013 06:49:30 -0500 + +rpy (1.0.3-23) unstable; urgency=low + + * (A week late) rebuilding under R 2.15.2 + + * debian/control: Set (Build-)Depends: to current R version + + -- Dirk Eddelbuettel Sat, 03 Nov 2012 13:10:49 -0500 + +rpy (1.0.3-22) unstable; urgency=low + + * (Belated) rebuilding under R 2.15.1 + + * debian/control: Set (Build-)Depends: to current R version + + * debian/rules: Also call dh_numpy (with thanks to lintian) + + -- Dirk Eddelbuettel Tue, 17 Jul 2012 08:17:07 -0500 + +rpy (1.0.3-21) unstable; urgency=low + + * Rebuilt under R 2.15.0 + + * debian/control: Set (Build-)Depends: to current R version + * debian/control: Set Standards-Version: to current version + * debian/control: Set Breaks: to next R version (expected March 2013) + + -- Dirk Eddelbuettel Sat, 31 Mar 2012 06:55:03 -0500 + +rpy (1.0.3-20) unstable; urgency=low + + * Rebuilt under R 2.14.1 + + * debian/control: Set (Build-)Depends: to current R version + * debian/control: Set Standards-Version: to current version + + -- Dirk Eddelbuettel Sat, 24 Dec 2011 08:22:25 -0600 + +rpy (1.0.3-19) unstable; urgency=low + + * Rebuilt under R 2.14.0 (prereleases -- release coming October 31) + + * debian/control: Set (Build-)Depends: to current R version + * debian/control: Set Standards-Version: to current version + + * debian/control: Added 'Breaks: r-base-core (>= 2.15.0)' + (Closes: #646969) + + -- Dirk Eddelbuettel Fri, 28 Oct 2011 15:58:16 -0500 + +rpy (1.0.3-18) unstable; urgency=low + + * Rebuilt under R 2.13.0 (prereleases -- release coming April 13) + + * debian/*: Updated to use new dh_python2 scheme (Closes: #617056) + * debian/control: Remove Build-Depends: on python-central + * debian/control: Set (Build-)Depends: to current R version + * debian/control: Set Build-Depends: on 'python-all-dev (>= 2.6.6-3)' + * debian/rules: Substitute dh_pycentral with dh_python2 + * debian/rules: Add '--install-layout=deb' to 'python setup.py install' + + -- Dirk Eddelbuettel Sun, 03 Apr 2011 14:21:38 -0500 + +rpy (1.0.3-17) unstable; urgency=low + + * Rebuilt under R 2.12.1 + + * debian/control: Upgraded (Build-)Depends: to current R version + + -- Dirk Eddelbuettel Sat, 25 Dec 2010 09:50:06 -0600 + +rpy (1.0.3-16) unstable; urgency=low + + * Rebuilt under R 2.12.0 + + * debian/control: Upgraded (Build-)Depends: to current R version + + -- Dirk Eddelbuettel Sun, 17 Oct 2010 12:56:14 -0500 + +rpy (1.0.3-15) unstable; urgency=low + + * Rebuilt under R 2.11.0 (Closes: #588790) + + * debian/control: Upgraded (Build-)Depends: to current R version + + * debian/watch: Updated + + -- Dirk Eddelbuettel Mon, 12 Jul 2010 06:06:30 -0500 + +rpy (1.0.3-14) unstable; urgency=low + + * Rebuilt under R 2.11.0 (Closes: #582507) + + * debian/control: Upgraded (Build-)Depends: to current R version + + -- Dirk Eddelbuettel Sat, 22 May 2010 10:14:05 -0500 + +rpy (1.0.3-13) unstable; urgency=low + + * Rebuilt under R 2.10.1 beta + + -- Dirk Eddelbuettel Tue, 08 Dec 2009 21:28:48 -0600 + +rpy (1.0.3-12) unstable; urgency=low + + * Rebuilt under R 2.10.0 beta (Closes: #551232) + + * debian/control: Upgraded (Build-)Depends: to current R version + + -- Dirk Eddelbuettel Fri, 16 Oct 2009 12:53:16 -0500 + +rpy (1.0.3-11) unstable; urgency=low + + * rpy.py: Set __version__ to rpy_version as suggested by Yaroslav Halchenko + (Closes: #544707) + + -- Dirk Eddelbuettel Wed, 02 Sep 2009 21:03:37 -0500 + +rpy (1.0.3-10) unstable; urgency=low + + * debian/control: Added versioned (Build-)Depends: on + python-numpy (>= 1:1.3.0) with Thanks! to Yaroslav Halchenko for + not only finding the bug but also the fix! (Closes: #544564) + + -- Dirk Eddelbuettel Wed, 02 Sep 2009 00:11:20 -0500 + +rpy (1.0.3-9) unstable; urgency=low + + * Rebuilt under R 2.9.2 + + * debian/control: Upgraded (Build-)Depends: to current R version + * debian/control: Upgraded Standards-Version: to current version + + * debian/python-rpy-doc.{postinst,prerm}: Removed install-info + calls as this is now done by dpkg triggers + * debian/control: Changed Build-Depends: on debhelper to '>= 7.2.17' + + * debian/watch: Updated to qa.debian.org redirector for sf.net + + * debian/compat: Increased to level 7 + + -- Dirk Eddelbuettel Thu, 27 Aug 2009 21:33:35 -0500 + +rpy (1.0.3-8) unstable; urgency=low + + * Rebuilt under R 2.9.1 + + * debian/control: Upgraded (Build-)Depends: to new R version + + * debian/control: Upgraded Standards-Version: + + -- Dirk Eddelbuettel Thu, 09 Jul 2009 10:41:45 -0500 + +rpy (1.0.3-7) unstable; urgency=low + + * Rebuilt under R 2.9.0 + + * debian/control: Upgraded (Build-)Depends: to new R version + + * debian/control: Upgraded Standards-Version: + + -- Dirk Eddelbuettel Sun, 26 Apr 2009 13:38:24 -0500 + +rpy (1.0.3-6) unstable; urgency=low + + * Rebuilt again against 1.0.3.orig tarball rather than svn + + -- Dirk Eddelbuettel Wed, 17 Dec 2008 06:44:36 -0600 + +rpy (1.0.3-5) unstable; urgency=low + + * Rebuilt under first beta release for R 2.8.1 (Closes: #508998) + * debian/control: Upgraded Build-Depends: to new R version + + * src/RPy.h: Replace #include with #include + + * debian/watch: Added watch file from dehs.alioth.debian.org + + -- Dirk Eddelbuettel Wed, 17 Dec 2008 06:00:35 -0600 + +rpy (1.0.3-4) unstable; urgency=low + + * Rebuilt under R 2.8.0 (Closes: #503862) + + * src/RPy.h: No longer include Rdevices.h which R 2.8.0 no longer exports + + -- Dirk Eddelbuettel Tue, 28 Oct 2008 22:16:45 -0500 + +rpy (1.0.3-3) unstable; urgency=low + + * Rebuilt under R 2.7.2 + * debian/control: Upgraded Build-Depends: to new R version + * debian/control: Upgraded Standards-Version: + + -- Dirk Eddelbuettel Fri, 29 Aug 2008 17:16:19 -0500 + +rpy (1.0.3-2) unstable; urgency=low + + * Rebuilt under R 2.7.1.rc + * debian/control: Upgraded Build-Depends: to new R version + + * Applied upstream fixes to setup.py and rpy_tools.py committed by Greg + that correctly deal with the Rlapack vs lapack linking change. + + -- Dirk Eddelbuettel Tue, 17 Jun 2008 14:15:55 -0500 + +rpy (1.0.3-1) unstable; urgency=low + + * New upstream release announced today + + * setup.py: Changed linking option from 'Rlapack' to 'lapack' to + correspond to our build using a choice of generic or tuned Lapack. + + -- Dirk Eddelbuettel Tue, 13 May 2008 08:24:12 -0500 + +rpy (1.0.2-1) unstable; urgency=low + + * New upstream release announced today + + * debian/control: Updated (Build-)Depends: on current R version + + * setup.py: Changed unconditional linking option from 'Rlapack' to + 'lapack' to correspond to our build using a choice of generic or tuned + Lapack libraries (Closes: #476003) + + -- Dirk Eddelbuettel Tue, 15 Apr 2008 20:14:06 -0500 + +rpy (1.0.1-4) unstable; urgency=low + + * Rebuilt for R 2.6.2 (Closes: #465559) + + * debian/control: Updated (Build-)Depends accordingly + + -- Dirk Eddelbuettel Wed, 13 Feb 2008 06:13:03 -0600 + +rpy (1.0.1-3) unstable; urgency=low + + * debian/control: Switch Build-Depends: from python-numpy-dev to python-numpy + which is cosmetic as the latter provides the former (Closes: #463210) + + -- Dirk Eddelbuettel Wed, 30 Jan 2008 06:51:12 -0600 + rpy (1.0.1-2) unstable; urgency=low * doc/rpy.texi: Corrected R plot() example, also committed to upstream --- rpy-1.0.3.orig/debian/compat +++ rpy-1.0.3/debian/compat @@ -1 +1 @@ -5 +7 --- rpy-1.0.3.orig/debian/control +++ rpy-1.0.3/debian/control @@ -2,13 +2,13 @@ Section: python Priority: optional Maintainer: Dirk Eddelbuettel -Standards-Version: 3.7.3 +Standards-Version: 3.9.4 XS-Python-Version: all -Build-Depends: debhelper (>= 5.0.37.2), r-base-dev (>= 2.6.1), python-all-dev (>= 2.3.5-10), python-numpy, python-numpy-dev, texinfo, texi2html, texlive-base, texlive-latex-base, python-central (>= 0.5) +Build-Depends: debhelper (>= 7.2.17), r-base-dev (>= 3.0.2), python-all-dev (>= 2.6.6-3), python-numpy (>= 1:1.3.0), python, texinfo, texi2html, texlive-base, texlive-latex-base, texlive-latex-recommended Package: python-rpy Architecture: any -Depends: ${shlibs:Depends}, ${python:Depends}, python-numpy, r-base-core (>= 2.6.1) +Depends: ${misc:Depends}, ${shlibs:Depends}, ${python:Depends}, python-numpy (>= 1:1.3.0), r-base-core (>= 3.0.2) Replaces: python2.2-rpy (<< 0.99.2-4), python2.3-rpy (<< 0.99.2-4), python2.4-rpy (<< 0.99.2-4) Conflicts: python2.2-rpy (<< 0.99.2-4), python2.3-rpy (<< 0.99.2-4), python2.4-rpy (<< 0.99.2-4) XB-Python-Version: ${python:Versions} @@ -25,6 +25,7 @@ Replaces: python-rpy-docs Provides: python-rpy-docs Conflicts: python-rpy-docs +Depends: ${misc:Depends}, dpkg (>= 1.15.4) | install-info Architecture: all Section: doc Description: Python interface to the GNU R language (documentation package) --- rpy-1.0.3.orig/debian/copyright +++ rpy-1.0.3/debian/copyright @@ -7,8 +7,10 @@ The sources where downloaded from a sourceforge mirror website at http://umn.dl.sourceforge.net/sourceforge/rpy/ -RPy is copyright by Walter Moreira and Gregory R. Warnes and was -originally licensed under the GPL as described. +Copyright (C) 2002 - 2003 Walter Moreira +Copyright (C) 2003 - 2008 Gregory R. Warnes + +License: MPL | GPL | LGPL As of version 0.99.1, RPy is now licensed under a choice of MPL, GPL and LGPL. The following code is provided in the upstream sources as --- rpy-1.0.3.orig/debian/python-rpy-doc.doc-base +++ rpy-1.0.3/debian/python-rpy-doc.doc-base @@ -2,8 +2,8 @@ Title: The RPy Reference Manual in html format Author: Walter Moreira and Gregory R. Warnes Abstract: This is the reference manual for RPy, a Python extension module for - using the R programming language. -Section: Apps/Math + using the R programming language. +Section: Science/Data Analysis Format: HTML Index: /usr/share/doc/python-rpy-doc/rpy_html/index.html --- rpy-1.0.3.orig/debian/python-rpy-doc.lintian-overrides +++ rpy-1.0.3/debian/python-rpy-doc.lintian-overrides @@ -0,0 +1,2 @@ +python-rpy-doc: maintainer-script-empty prerm +python-rpy-doc: maintainer-script-empty postinst --- rpy-1.0.3.orig/debian/python-rpy-doc.postinst +++ rpy-1.0.3/debian/python-rpy-doc.postinst @@ -1,6 +1,6 @@ #!/bin/sh # -# postinst script for the Debian GNU/Linux python-roy-doc package +# postinst script for the Debian GNU/Linux python-rpy-doc package # # Dirk Eddelbuettel @@ -10,9 +10,6 @@ case "$1" in configure) - install-info --quiet --section "Math" "RPy" \ - --description="The RPy Reference Manual."\ - /usr/share/info/rpy.info.gz ;; abort-upgrade|abort-remove|abort-deconfigure) ;; --- rpy-1.0.3.orig/debian/python-rpy-doc.prerm +++ rpy-1.0.3/debian/python-rpy-doc.prerm @@ -1,6 +1,6 @@ #!/bin/sh # -# prerm script for the Debian GNU/Linux python-roy-doc package +# prerm script for the Debian GNU/Linux python-rpy-doc package # # Dirk Eddelbuettel @@ -10,7 +10,6 @@ case "$1" in remove|purge) - install-info --quiet --remove rpy ;; upgrade) --- rpy-1.0.3.orig/debian/python-rpy.lintian-overrides +++ rpy-1.0.3/debian/python-rpy.lintian-overrides @@ -0,0 +1,3 @@ +python-rpy: binary-or-shlib-defines-rpath usr/lib/python2.7/dist-packages/_rpy3002.so /usr/lib/R/lib +python-rpy: binary-or-shlib-defines-rpath usr/lib/python2.7/dist-packages/_rpy3002.so /usr/lib/R/bin +python-rpy: binary-or-shlib-defines-rpath usr/lib/python2.7/dist-packages/_rpy3002.so /usr/lib/R/bin:/usr/lib/R/lib --- rpy-1.0.3.orig/debian/rules +++ rpy-1.0.3/debian/rules @@ -1,12 +1,15 @@ #!/usr/bin/make -f # debian/rules file for the Debian GNU/Linux python-rpy package -# Copyright 2004 - 2007 by Dirk Eddelbuettel +# Copyright 2004 - 2012 by Dirk Eddelbuettel -package := python-rpy +project := rpy +package := python-$(project) +docpackage := python-$(project)-doc debbase := $(CURDIR)/debian debtmp := $(debbase)/$(package) debdoc := debian/python-rpy-doc/usr/share/doc/python-rpy-doc lintiandir := $(debtmp)/usr/share/lintian/overrides +doclintiandir := debian/python-rpy-doc/usr/share/lintian/overrides #PYTHON2.1 := python2.1 #PYTHON2.2 := python2.2 @@ -19,6 +22,16 @@ # Uncomment this to turn on verbose mode. # export DH_VERBOSE=1 +version := $(shell head -1 debian/changelog | perl -nle 'm/\((.*)-\d+\)/ && print $$1') + +echoversion: + @echo ${version} + +tarball: + (cd .. && \ + tar czf tarballs/$(project)_${version}.orig.tar.gz ./$(project) \ + --exclude=.svn --exclude=debian/) + get-orig-source: upstream upstream: links http://prdownloads.sourceforge.net/rpy/ @@ -28,7 +41,9 @@ dh_testdir touch configure-stamp -build: configure-stamp build-stamp +build: configure-stamp build-arch build-indep +build-arch: build-stamp +build-indep: build-stamp build-stamp: dh_testdir # CFLAGS="$(compilerflags)" $(PYTHON2.3) setup.py build \ @@ -65,7 +80,7 @@ install: build dh_testdir dh_testroot - dh_clean -k + dh_prep dh_installdirs #$(PYTHON2.1) setup.py install --root=debian/python2.1-rpy @@ -73,12 +88,13 @@ #$(PYTHON2.3) setup.py install --root=debian/python2.3-rpy #$(PYTHON2.4) setup.py install --root=debian/python2.4-rpy for python in $(PYVERS); \ - do $$python setup.py install --root=debian/python-rpy; \ + do $$python setup.py install --root=debian/python-rpy --install-layout=deb; \ done install -d $(lintiandir) - install -m 0644 debian/overrides $(lintiandir)/$(package) - + install -m 0644 debian/$(package).lintian-overrides $(lintiandir)/$(package) + install -d $(doclintiandir) + install -m 0644 debian/$(docpackage).lintian-overrides $(doclintiandir)/$(docpackage) # Build architecture-independent files here. binary-indep: build install @@ -126,7 +142,9 @@ # dh_suidregister -a # dh_makeshlibs -a # dh_perl -a - dh_pycentral -a +# dh_pycentral -a + dh_python2 -a + dh_numpy -a dh_shlibdeps -a dh_installdeb -a dh_gencontrol -a --- rpy-1.0.3.orig/debian/source/format +++ rpy-1.0.3/debian/source/format @@ -0,0 +1 @@ +1.0 --- rpy-1.0.3.orig/debian/watch +++ rpy-1.0.3/debian/watch @@ -1,5 +1,2 @@ -# format version number, currently 2; this line is compulsory! -version=2 - -# This is one format for an HTTP site, which is the same as the FTP format -http://prdownloads.sourceforge.net/rpy/rpy-([-0-9\.]*).tar.gz +version=3 +http://sf.net/rpy/rpy-(.+)\.tar\.gz --- rpy-1.0.3.orig/examples/faithful.dat +++ rpy-1.0.3/examples/faithful.dat @@ -0,0 +1,273 @@ +"eruptions" "waiting" +3.6 79 +1.8 54 +3.333 74 +2.283 62 +4.533 85 +2.883 55 +4.7 88 +3.6 85 +1.95 51 +4.35 85 +1.833 54 +3.917 84 +4.2 78 +1.75 47 +4.7 83 +2.167 52 +1.75 62 +4.8 84 +1.6 52 +4.25 79 +1.8 51 +1.75 47 +3.45 78 +3.067 69 +4.533 74 +3.6 83 +1.967 55 +4.083 76 +3.85 78 +4.433 79 +4.3 73 +4.467 77 +3.367 66 +4.033 80 +3.833 74 +2.017 52 +1.867 48 +4.833 80 +1.833 59 +4.783 90 +4.35 80 +1.883 58 +4.567 84 +1.75 58 +4.533 73 +3.317 83 +3.833 64 +2.1 53 +4.633 82 +2 59 +4.8 75 +4.716 90 +1.833 54 +4.833 80 +1.733 54 +4.883 83 +3.717 71 +1.667 64 +4.567 77 +4.317 81 +2.233 59 +4.5 84 +1.75 48 +4.8 82 +1.817 60 +4.4 92 +4.167 78 +4.7 78 +2.067 65 +4.7 73 +4.033 82 +1.967 56 +4.5 79 +4 71 +1.983 62 +5.067 76 +2.017 60 +4.567 78 +3.883 76 +3.6 83 +4.133 75 +4.333 82 +4.1 70 +2.633 65 +4.067 73 +4.933 88 +3.95 76 +4.517 80 +2.167 48 +4 86 +2.2 60 +4.333 90 +1.867 50 +4.817 78 +1.833 63 +4.3 72 +4.667 84 +3.75 75 +1.867 51 +4.9 82 +2.483 62 +4.367 88 +2.1 49 +4.5 83 +4.05 81 +1.867 47 +4.7 84 +1.783 52 +4.85 86 +3.683 81 +4.733 75 +2.3 59 +4.9 89 +4.417 79 +1.7 59 +4.633 81 +2.317 50 +4.6 85 +1.817 59 +4.417 87 +2.617 53 +4.067 69 +4.25 77 +1.967 56 +4.6 88 +3.767 81 +1.917 45 +4.5 82 +2.267 55 +4.65 90 +1.867 45 +4.167 83 +2.8 56 +4.333 89 +1.833 46 +4.383 82 +1.883 51 +4.933 86 +2.033 53 +3.733 79 +4.233 81 +2.233 60 +4.533 82 +4.817 77 +4.333 76 +1.983 59 +4.633 80 +2.017 49 +5.1 96 +1.8 53 +5.033 77 +4 77 +2.4 65 +4.6 81 +3.567 71 +4 70 +4.5 81 +4.083 93 +1.8 53 +3.967 89 +2.2 45 +4.15 86 +2 58 +3.833 78 +3.5 66 +4.583 76 +2.367 63 +5 88 +1.933 52 +4.617 93 +1.917 49 +2.083 57 +4.583 77 +3.333 68 +4.167 81 +4.333 81 +4.5 73 +2.417 50 +4 85 +4.167 74 +1.883 55 +4.583 77 +4.25 83 +3.767 83 +2.033 51 +4.433 78 +4.083 84 +1.833 46 +4.417 83 +2.183 55 +4.8 81 +1.833 57 +4.8 76 +4.1 84 +3.966 77 +4.233 81 +3.5 87 +4.366 77 +2.25 51 +4.667 78 +2.1 60 +4.35 82 +4.133 91 +1.867 53 +4.6 78 +1.783 46 +4.367 77 +3.85 84 +1.933 49 +4.5 83 +2.383 71 +4.7 80 +1.867 49 +3.833 75 +3.417 64 +4.233 76 +2.4 53 +4.8 94 +2 55 +4.15 76 +1.867 50 +4.267 82 +1.75 54 +4.483 75 +4 78 +4.117 79 +4.083 78 +4.267 78 +3.917 70 +4.55 79 +4.083 70 +2.417 54 +4.183 86 +2.217 50 +4.45 90 +1.883 54 +1.85 54 +4.283 77 +3.95 79 +2.333 64 +4.15 75 +2.35 47 +4.933 86 +2.9 63 +4.583 85 +3.833 82 +2.083 57 +4.367 82 +2.133 67 +4.35 74 +2.2 54 +4.45 83 +3.567 73 +4.5 73 +4.15 88 +3.817 80 +3.917 71 +4.45 83 +2 56 +4.283 79 +4.767 78 +4.533 84 +1.85 58 +4.25 83 +1.983 43 +2.25 60 +4.75 75 +4.117 81 +2.15 46 +4.417 90 +1.817 46 +4.467 74 --- rpy-1.0.3.orig/rpy.py +++ rpy-1.0.3/rpy.py @@ -16,7 +16,7 @@ # # High level module for managing the lookup of R objects. # -# $Id: rpy.py 489 2008-04-16 14:19:47Z warnes $ +# $Id: rpy.py 758 2009-09-03 02:14:55Z eddelbuettel $ # # from __future__ import nested_scopes @@ -139,6 +139,7 @@ # Version from rpy_version import rpy_version +__version__ = rpy_version # Symbolic names for conversion modes TOP_CONVERSION = 4 --- rpy-1.0.3.orig/rpy_tools.py +++ rpy-1.0.3/rpy_tools.py @@ -97,8 +97,7 @@ if stat or len(output)<=0: raise RuntimeError("Couldn't execute the R interpreter" + " `%s'.\n" % rexec ) - # edd 05 Apr 2006 version = re.search("R +([0-9]\.[0-9]\.[0-9])", output) - version = re.search(" +([0-9]\.[0-9]\.[0-9])", output) + version = re.search(" +([0-9]+\.[0-9]+\.[0-9]+)", output) if not version: raise RuntimeError("Couldn't obtain version number from output\n" "of `R --version'.\n") @@ -143,3 +142,20 @@ % PYTHON_DIR ) return PYTHON_DIR + +def get_R_LAPACK_LIB_FLAGS(RHOME=get_R_HOME()): + """ + Determine the necessary link arguments for lapack + """ + rexec = os.path.join(RHOME, 'bin', 'R') + stat, output = getstatusoutput('"%s" CMD config LAPACK_LIBS' % rexec ) + if stat or len(output)<=0: + raise RuntimeError("Couldn't execute the R interpreter" + + " `%s'.\n" % rexec ) + + LAPACK_LIB_FLAGS = output.strip() + if not LAPACK_LIB_FLAGS: + raise RuntimeError("Couldn't obtain LAPACK_LIBS information from output\n" + "of `R CMD config LAPACK_LIBS'.\n") + + return LAPACK_LIB_FLAGS --- rpy-1.0.3.orig/setup.Win32 +++ rpy-1.0.3/setup.Win32 @@ -0,0 +1,52 @@ +# $Id$ +# +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the RPy python module. +# +# The Initial Developer of the Original Code is Walter Moreira. +# Portions created by the Initial Developer are Copyright (C) 2002 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Gregory R. Warnes (Maintainer) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + + +####### +# IMPORTANT DEFINITIONS FOR WINDOWS +####### + +# +# For windows, library-dirs needs to be set to contain (in this order) +# 1) the MingGW/lib directory +# 2) C:\WinNT\System32 +# 3) C:\Windows\System32 +# +[build_ext] +library-dirs=C:\MinGW\lib;C:\WinNT\System32;C:\Windows\System32 + --- rpy-1.0.3.orig/setup.bat +++ rpy-1.0.3/setup.bat @@ -0,0 +1,70 @@ +@ECHO OFF +REM $Id$ +REM +REM ***** BEGIN LICENSE BLOCK ***** +REM Version: MPL 1.1/GPL 2.0/LGPL 2.1 +REM +REM The contents of this file are subject to the Mozilla Public License Version +REM 1.1 (the "License"); you may not use this file except in compliance with +REM the License. You may obtain a copy of the License at +REM http://www.mozilla.org/MPL/ +REM +REM Software distributed under the License is distributed on an "AS IS" basis, +REM WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +REM for the specific language governing rights and limitations under the +REM License. +REM +REM The Original Code is the RPy python module. +REM +REM The Initial Developer of the Original Code is Walter Moreira. +REM Portions created by the Initial Developer are Copyright (C) 2002 +REM the Initial Developer. All Rights Reserved. +REM +REM Contributor(s): +REM Gregory R. Warnes (Maintainer) +REM +REM Alternatively, the contents of this file may be used under the terms of +REM either the GNU General Public License Version 2 or later (the "GPL"), or +REM the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +REM in which case the provisions of the GPL or the LGPL are applicable instead +REM of those above. If you wish to allow use of your version of this file only +REM under the terms of either the GPL or the LGPL, and not to allow others to +REM use your version of this file under the terms of the MPL, indicate your +REM decision by deleting the provisions above and replace them with the notice +REM and other provisions required by the GPL or the LGPL. If you do not delete +REM the provisions above, a recipient may use your version of this file under +REM the terms of any one of the MPL, the GPL or the LGPL. +REM +REM ***** END LICENSE BLOCK ***** + +REM Important Paths +set MINGW=C:\MinGW +set PYTHON=C:\Python25 + +path %MINGW%\bin;%PYTHON%;%PATH% + +echo copying setup.Win32 to setup.cfg +copy setup.Win32 setup.cfg + +REM Uncomment to specify a location for R +REM set RHOMES=C:\Progra~1\R\R-2.2.1 + +REM Uncomment to clean up completely before starting +python setup.py build clean --all + +REM Perform Local Build and Install +python setup.py build_ext --compiler=mingw32 install --force + +REM Create Windows Installer +python setup.py build --compiler=mingw32 bdist_wininst + +echo Removing setup.cfg +del setup.cfg + +REM Start a new command shell. This accomplishes several things: +REM (1) prevents the window from closing, thus allowing the user +REM to see any messages that were generated, it also +REM (2) Leaves the user in a shell with the environment variables +REM as we set them, making it easier for users to perform other +REM actions in an appropriate environment +cmd /F:ON --- rpy-1.0.3.orig/setup.in +++ rpy-1.0.3/setup.in @@ -0,0 +1,948 @@ +# $Id$ +# +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the RPy python module. +# +# The Initial Developer of the Original Code is Walter Moreira. +# Portions created by the Initial Developer are Copyright (C) 2002 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Gregory R. Warnes (Maintainer) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +################# +# This file can be used to customize how rpy is built. Each section +# allows you to provide values for any command option available for +# the corresponding command. Some examples are included, but you +# Can learn all of the available options for a given command by +# running +# $ python setup.py help +################## + +####### +[build] # Build everything needed to install +####### + +## base directory for build library +# +# build-base=/some/path +# + +## build directory for platform-neutral distributions +# +# build-purelib=/some/path +# + +## build directory for platform-specific distributions +# +# build-platlib=/some/path +# + +## build directory for all distribution (defaults to either +## build-purelib or build-platlib +# +# build-lib=/some/path +# + +## build directory for scripts +# +# build-scripts=/some/path +# + +## temporary build directory +# +# build-temp=/some/path +# + +## specify the compiler type +# +# compiler=mingw +# + +## compile extensions and libraries with debugging information +# +# debug=True +# + +## forcibly build everything (ignore file timestamps) +# +# force +# + +## specify final destination interpreter path (build.py) +# +# executable=/some/path + +########## +[build_py] # "build" pure Python modules (copy to build directory) +########## + +## directory to "build" (copy) to +# +# build-lib=/some/path +# + +## compile .py to .pyc +# +# compile=True +# + +## don't compile .py files [default] +# +# no-compile=True +# + +## compile with optimization: -O1 for "python -O", -O2 for "python +## -OO", and -O0 to disable [default: -O0] +# +# optimize=1 +# + + +## forcibly build everything (ignore file timestamps) +# +# force=True +# + +########### +[build_ext] # Build C/C++ extensions (compile/link to build directory) +########### + +## directory for compiled extension modules +# +# build-lib=/some/path +# + +## directory for temporary files (build by-products) +# +# build-temp=/some/path +# + +## ignore build-lib and put compiled extensions into the source +## directory alongside your pure Python modules# +# +# inplace=True +# + + +## list of directories to search for header files (separated by ':') +# +# include-dirs=/some/path:/some/other/path +# + + +## C preprocessor macros to define +# +# define=SOMEFLAG="SomeValue" +# + +## C preprocessor macros to undefine +# +# undef=SOMEFLAG +# + +## external C libraries to link with +# +# libraries=someLib +# + +## directories to search for external C libraries (separated by ':') +## +# +# library-dirs=/some/path:/some/other/path + +## directories to search for shared C libraries at runtime +# +# rpath=/some/path:/some/other/path +# + +## extra explicit link objects to include in the link +# +# link-objects=someFile.o +# + +## compile/link with debugging information +# +# debug=True +# + +## forcibly build everything (ignore file timestamps) +# +# force=True +# + +## specify the compiler type +# +# compiler=mingw +# + +## make SWIG create C++ files (default is C) +# +# swig-cpp=True +# + +## list of SWIG command line options +# +# swig-opts=-s foo -m bar +# + +## path to the SWIG executable +# +# swig=/some/path +# + + +############ +[build_clib] # Build C/C++ libraries used by Python extensions +############ + +## directory to build C/C++ libraries to +# +# build-clib +# + +## directory to put temporary build by-products +# +# build-temp +# + +## compile with debugging information +# +# debug +# + +## forcibly build everything (ignore file timestamps) +# +# force +# + +## specify the compiler type +# +# compiler +# + + + +############### +[build_scripts] # "build" scripts (copy and fixup #! line) +############### + +## directory to "build" (copy) to +# +# build-dir +# + +## forcibly build everything (ignore file timestamps +# +# force +# + +## specify final destination interpreter path +# +# executable +# + + + +####### +[clean] # Clean up output of 'build' command +####### + +## base build directory (default: 'build.build-base') +# +# build-base +# + +## build directory for all modules (default: 'build.build-lib') +# +# build-lib +# + +## temporary build directory (default: 'build.build-temp') +# +# build-temp +# + +## build directory for scripts (default: 'build.build-scripts') +# +# build-scripts +# + +## temporary directory for built distributions +# +# bdist-base +# + +## remove all build output, not just temporary by-products +# +# all +# + + +######### +[install] # Install everything from build directory +######### + +## installation prefix +# +# prefix +# + +## (Unix only) prefix for platform-specific files +# +# exec-prefix +# + +## (Unix only) home directory to install under +# +# home +# + +## base installation directory (instead of prefix or home) +# +# install-base +# + +## base installation directory for platform-specific files (instead +## of exec-prefix or home) +# +# install-platbase +# + + +## install everything relative to this alternate root directory +# +# root +# + +## installation directory for pure Python module distributions +# +# install-purelib +# + +## installation directory for non-pure module distributions +# +# install-platlib +# + +## installation directory for all module distributions (overrides +## install-purelib and install-platlib) +# +# install-lib +# + + +## installation directory for C/C++ headers +# +# install-headers +# + +## installation directory for Python scripts +# +# install-scripts +# + +## installation directory for data files +# +# install-data +# + +## compile .py to .pyc [default] +# +# compile +# + +## don't compile .py files +# +# no-compile +# + +## also compile with optimization: -O1 for "python -O", -O2 for +## "python -OO", and -O0 to disable [default: -O0] +# +# optimize=1 +# + +## force installation (overwrite any existing files) +# +# force +# + +## skip rebuilding everything (for testing/debugging) +# +# skip-build +# + +## filename in which to record list of installed files +# +# record +# + + +############# +[install_lib] # Install all Python modules (extensions and pure Python) +############# + +## directory to install to +# +# install-dir +# + +## build directory (where to install from) +# +# build-dir +# + +## force installation (overwrite existing files) +# +# force +# + +## compile .py to .pyc [default] +# +# compile +# + +## don't compile .py files +# +# no-compile +# + +## compile with optimization: -O1 for "python -O", -O2 +## for "python -OO", and -O0 to disable [default: -O0] +# +# optimize +# + + +## skip the build steps +# +# skip-build +# + + + +################# +[install_headers] # Install C/C++ header files +################# + +## directory to install header files to +# +# install-dir +# + +## force installation (overwrite existing files) +# +# force +# + + +################# +[install_scripts] # Install scripts (Python or otherwise) +################# + +## directory to install scripts to +# +# install-dir +# + +## build directory (where to install from) +# +# build-dir +# + +## force installation (overwrite existing files) +# +# force +# + +## skip the build steps +# +# skip-build +# + + +############## +[install_data] # Install data files +############## + +## base directory for installing data files (default: installation +## base dir) +# +# install-dir +# + +## install everything relative to this alternate root directory +# +# root +# + +## force installation (overwrite existing files) +# +# force +# + + +####### +[sdist] # Create a source distribution (tarball, zip file, etc.) +####### + +## name of manifest template file [default: MANIFEST.in] +# +# template +# + +## name of manifest file [default: MANIFEST] +# +# manifest +# + +## include the default file set in the manifest [default; disable +## with no-defaults] +# +# use-defaults +# + + +## don't include the default file set +# +# no-defaults +# + +## specifically exclude files/directories that should not be +## distributed (build tree, RCS/CVS dirs, etc.) [default; disable +## with no-prune] +# +# prune +# + +## don't automatically exclude anything +# +# no-prune +# + +## just regenerate the manifest and then stop (implies +## force-manifest) +# +# manifest-only +# + +## forcibly regenerate the manifest and carry on as usual +# +# force-manifest +# + +## formats for source distribution (comma-separated list) +# +# formats +# + +## keep the distribution tree around after creating archive file(s) +# +# keep-temp +# + +## directory to put the source distribution archive(s) in [default: +## dist] +# +# dist-dir +# + + +########## +[register] # register the distribution with the Python package index +########## + +## url of repository [default: http://www.python.org/pypi] +# +# repository +# + +## list the valid Trove classifiers +# +# list-classifiers +# + +## display full response text from server +# +# show-response +# + + +####### +[bdist] # Create a built (binary) distribution +####### + +## temporary directory for creating built distributions +# +# bdist-base +# + +## platform name to embed in generated filenames +# +# plat-name +# + +## formats for distribution (comma-separated list) +# +# formats +# + +## directory to put final built distributions in [default:dist] +# +# dist-dir +# + +## skip rebuilding everything (for testing/debugging) +# +# skip-build +# + +## lists available distribution formats +# +# help-formats +# + + + +############ +[bdist_dumb] # Create a "dumb" built distribution +############ + +## temporary directory for creating the distribution +# +# bdist-dir +# + +## platform name to embed in generated filenames +# +# plat-name +# + +## archive format to create (tar, ztar, gztar, zip) +# +# format +# + +## keep the pseudo-installation tree around after creating +## the distribution archive +# +# keep-temp +# + +## directory to put final built distributions in +# +# dist-dir +# + +## skip rebuilding everything (for testing/debugging) +# +# skip-build +# + +## build the archive using relative paths(default: false) +# +# relative +# + + +########### +[bdist_rpm] # Create an RPM distribution +########### + +## base directory for creating built distributions +# +# bdist-base +# + +## base directory for creating RPMs (defaults to "rpm" +## under bdist-base; must be specified for RPM 2) +# +# rpm-base +# + +## directory to put final RPM files in (and .spec files if +## spec-only) +# +# dist-dir +# + +## path to Python interpreter to hard-code in the .spec file +## (default: "python") +# +# python +# + + +## hard-code the exact path to the current Python interpreter in the +#.spec file +# +# fix-python +# + +## only regenerate spec file +# +# spec-only +# + +## only generate source RPM +# +# source-only +# + +## only generate binary RPM +# +# binary-only +# + +## use bzip2 instead of gzip to create source distribution +# +# use-bzip2 +# + +## name of the (Linux) distribution to which this RPM applies (*not* +## the name of the module distribution!) +# +# distribution-name +# + +## package classification [default: "Development/Libraries"] +# +# group +# + +## RPM release number +# +# release +# + +## RPM serial number +# +# serial +# + +## RPM "vendor" (eg. "Joe Blow ") [default: +## maintainer or author from setup script] +# +# vendor +# + +## RPM packager (eg. "Jane Doe ")[default: vendor] +# +# packager +# + +## list of documentation files (space or comma-separated) +# +# doc-files +# + +## RPM changelog +# +# changelog +# + +## name of icon file +# +# icon +# + +## capabilities provided by this package +# +# provides +# + +## capabilities required by this package +# +# requires +# + +## capabilities which conflict with this package +# +# conflicts +# + +## capabilities required to build this package +# +# build-requires +# + +## capabilities made obsolete by this package +# +# obsoletes +# + +## do not automatically calculate dependencies +# +# no-autoreq +# + +## don't clean up RPM build directory +# +# keep-temp +# + +## clean up RPM build directory [default] +# +# no-keep-temp +# + +## compile with RPM_OPT_FLAGS when building from source RPM +# +# use-rpm-opt-flags +# + +## do not pass any RPM CFLAGS to compiler +# +# no-rpm-opt-flags +# + +## RPM 3 compatibility mode (default) +# +# rpm3-mode +# + +## RPM 2 compatibility mode +# +# rpm2-mode +# + +## Specify a script for the PREP phase of RPM building +# +# prep-script +# + +## Specify a script for the BUILD phase of RPM building +# +# build-script +# + +## Specify a script for the pre-INSTALL phase of RPM building +# +# pre-install +# + +## Specify a script for the INSTALL phase of RPM building +# +# install-script +# + +## Specify a script for the post-INSTALL phase of RPM building +# +# post-install +# + +## Specify a script for the pre-UNINSTALL phase of RPM building +# +# pre-uninstall +# + +## Specify a script for the post-UNINSTALL phase of RPM building +# +# post-uninstall +# + +## Specify a script for the CLEAN phase of RPM building +# +# clean-script +# + +## Specify a script for the VERIFY phase of the RPM build +# +# verify-script +# + +## Force an architecture onto the RPM build process +# +# force-arch +# + + +############### +[bdist_wininst] # Create an executable installer for MS Windows +############### + +## temporary directory for creating the distribution +# +# bdist-dir +# + +## keep the pseudo-installation tree around after creating the +## distribution archive +# +# keep-temp +# + +## require a specific python version on the target system +# +# target-version +# + +## do not compile .py to .pyc on the target system +# +# no-target-compile +# + +## do not compile .py to .pyo (optimized)on the target system +# +# no-target-optimize +# + +## directory to put final built distributions in +# +# dist-dir +# + +## bitmap to use for the installer instead of python-powered logo +# +# bitmap +# + +## title to display on the installer background instead of default +# +# title +# + +## skip rebuilding everything (for testing/debugging) +# +# skip-build +# + +## basename of installation script to be run afterinstallation or +## before deinstallation +# +# install-script +# + + +## Fully qualified filename of a script to be run before any files +## are installed. This script need not be in the distribution +# +# pre-install-script +# --- rpy-1.0.3.orig/setup.py +++ rpy-1.0.3/setup.py @@ -30,13 +30,14 @@ See the files INSTALL.UNIX and INSTALL.WINDOWS for more details. """ -DEBUG=True +DEBUG=False import os, os.path, sys, shutil, re from distutils.core import setup, Extension from distutils.sysconfig import * from distutils.errors import * import rpy_tools + if sys.platform=="win32": import rpy_wintools @@ -85,7 +86,7 @@ get_config_vars()['OPT'] = '-g -Wall' else: # to avoid strict prototypes errors from R includes - get_config_vars()['OPT'] = '-DNDEBUG -g -O3 -Wall' + get_config_vars()['OPT'] = '-DNDEBUG -O3 -Wall' # get the Python version if sys.version[:3] >= '2.2': @@ -149,22 +150,21 @@ library_dirs= r_libs runtime_libs = r_libs extra_compile_args=[] - elif sys.platform=='osf1V5': - include_dirs = [ os.path.join(RHOME.strip(), 'include'), - 'src' ] - libraries=['R','Rlapack'] - library_dirs = r_libs - runtime_libs = r_libs - extra_compile_args=["-shared"] - source_files = source_files + ["src/setenv.c"] + else: # unix-like systems, this is known to work for Linux and Solaris include_dirs = [ os.path.join(RHOME.strip(), 'include'), 'src', '/usr/share/R/include' ] - libraries=['R','Rlapack'] + library_dirs = r_libs runtime_libs = r_libs extra_compile_args=["-shared"] source_files = source_files + ["src/setenv.c"] + + libraries=['R'] + + # Ask R to tell us how to properly link against lapack + extra_compile_args += [ rpy_tools.get_R_LAPACK_LIB_FLAGS( RHOME ) ] + # Discover which array packages are present try: --- rpy-1.0.3.orig/src/RPy.h +++ rpy-1.0.3/src/RPy.h @@ -1,5 +1,5 @@ /* - * $Id: RPy.h 384 2007-11-30 00:40:17Z warnes $ + * $Id: RPy.h 797 2013-04-23 00:23:43Z eddelbuettel $ * Public API for calling R. */ @@ -52,6 +52,13 @@ #include #include #include + +#if (R_VERSION >= R_Version(2,4,0)) +#include +#endif + + + #undef _POSIX_C_SOURCE #include #include @@ -74,15 +81,15 @@ # endif #endif /* _WIN32 */ -#include /* must follow Graphics.h */ +#include /* must follow Graphics.h */ /* Missing definitions from Rinterface.h or RStartup.h */ # define CleanEd Rf_CleanEd extern void CleanEd(void); extern int R_CollectWarnings; -# define PrintWarnings Rf_PrintWarnings -extern void PrintWarnings(void); +//# define PrintWarnings Rf_PrintWarnings +//extern void PrintWarnings(void); /****/ #include --- rpy-1.0.3.orig/src/R_eval3001.c +++ rpy-1.0.3/src/R_eval3001.c @@ -0,0 +1,197 @@ +/* + * $Id: R_eval.c 363 2007-11-12 23:27:48Z warnes $ + * Evaluation of R expressions. + */ + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the RPy python module. + * + * The Initial Developer of the Original Code is Walter Moreira. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Gregory R. Warnes (Maintainer) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +/* + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Evaluation of R expressions. + * + * $Id: R_eval.c 363 2007-11-12 23:27:48Z warnes $ + * + */ + +#include + +/* The Python original SIGINT handler */ +PyOS_sighandler_t python_sigint; + +/* Indicates whether the R interpreter was interrupted by a SIGINT */ +int interrupted = 0; + +/* Abort the current R computation due to a SIGINT */ +void interrupt_R(int signum) +{ + interrupted = 1; + error("Interrupted"); +} + + +/* Evaluate a SEXP. It must be constructed by hand. It raises a Python + exception if an error ocurred in the evaluation */ +SEXP do_eval_expr(SEXP e) { + SEXP res; + int error = 0; + PyOS_sighandler_t old_int; + + /* Enable our handler for SIGINT inside the R + interpreter. Otherwise, we cannot stop R calculations, since + SIGINT is only processed between Python bytecodes. Also, save the + Python SIGINT handler because it is necessary to temporally + restore it in user defined I/O Python functions. */ + stop_events(); + + #ifdef _WIN32 + old_int = PyOS_getsig(SIGBREAK); + #else + old_int = PyOS_getsig(SIGINT); + #endif + python_sigint = old_int; + + signal(SIGINT, interrupt_R); + + interrupted = 0; + res = R_tryEval(e, R_GlobalEnv, &error); + + #ifdef _WIN32 + PyOS_setsig(SIGBREAK, old_int); + #else + PyOS_setsig(SIGINT, old_int); + #endif + + start_events(); + + if (error) { + if (interrupted) { + PyErr_SetNone(PyExc_KeyboardInterrupt); + } + else + PyErr_SetString(RPy_RException, get_last_error_msg()); + return NULL; + } + + + return res; +} + +/* Evaluate a function given by a name (without arguments) */ +SEXP do_eval_fun(char *name) { + SEXP exp, fun, res; + + fun = get_fun_from_name(name); + if (!fun) + return NULL; + + PROTECT(fun); + PROTECT(exp = allocVector(LANGSXP, 1)); + SETCAR(exp, fun); + + PROTECT(res = do_eval_expr(exp)); + UNPROTECT(3); + return res; +} + +/* + * Get an R **function** object by its name. When not found, an exception is + * raised. The checking of the length of the identifier is needed to + * avoid R raising an error causing Python to dump core. + */ +SEXP get_fun_from_name(char *ident) { + SEXP obj; + + /* For R not to throw an error, we must check the identifier is + neither null nor greater than MAXIDSIZE */ + if (!*ident) { + PyErr_SetString(RPy_Exception, "attempt to use zero-length variable name"); + return NULL; + } + if (strlen(ident) > MAXIDSIZE) { + PyErr_SetString(RPy_Exception, "symbol print-name too long"); + return NULL; + } + +#if R_VERSION < 0x20000 + obj = Rf_findVar(Rf_install(ident), R_GlobalEnv); +#else + /* + * For R-2.0.0 and later, it is necessary to use findFun to get + * functions. Unfortunately, calling findFun on an undefined name + * causes a segfault! + * + * Solution: + * + * 1) Call findVar on the name + * + * 2) If something has the name, call findFun + * + * 3) Raise an error if either step 1 or 2 fails. + */ + obj = Rf_findVar(Rf_install(ident), R_GlobalEnv); + + if (obj != R_UnboundValue) + obj = Rf_findFun(Rf_install(ident), R_GlobalEnv); +#endif + + if (obj == R_UnboundValue) { + PyErr_Format(RPy_Exception, "R Function \"%s\" not found", ident); + return NULL; + } + return obj; +} + +/* Obtain the text of the last R error message */ +const char *get_last_error_msg() { + SEXP msg; + + msg = do_eval_fun("geterrmessage"); + return CHARACTER_VALUE(msg); +} --- rpy-1.0.3.orig/src/R_eval3002.c +++ rpy-1.0.3/src/R_eval3002.c @@ -0,0 +1,197 @@ +/* + * $Id: R_eval.c 363 2007-11-12 23:27:48Z warnes $ + * Evaluation of R expressions. + */ + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the RPy python module. + * + * The Initial Developer of the Original Code is Walter Moreira. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Gregory R. Warnes (Maintainer) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +/* + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Evaluation of R expressions. + * + * $Id: R_eval.c 363 2007-11-12 23:27:48Z warnes $ + * + */ + +#include + +/* The Python original SIGINT handler */ +PyOS_sighandler_t python_sigint; + +/* Indicates whether the R interpreter was interrupted by a SIGINT */ +int interrupted = 0; + +/* Abort the current R computation due to a SIGINT */ +void interrupt_R(int signum) +{ + interrupted = 1; + error("Interrupted"); +} + + +/* Evaluate a SEXP. It must be constructed by hand. It raises a Python + exception if an error ocurred in the evaluation */ +SEXP do_eval_expr(SEXP e) { + SEXP res; + int error = 0; + PyOS_sighandler_t old_int; + + /* Enable our handler for SIGINT inside the R + interpreter. Otherwise, we cannot stop R calculations, since + SIGINT is only processed between Python bytecodes. Also, save the + Python SIGINT handler because it is necessary to temporally + restore it in user defined I/O Python functions. */ + stop_events(); + + #ifdef _WIN32 + old_int = PyOS_getsig(SIGBREAK); + #else + old_int = PyOS_getsig(SIGINT); + #endif + python_sigint = old_int; + + signal(SIGINT, interrupt_R); + + interrupted = 0; + res = R_tryEval(e, R_GlobalEnv, &error); + + #ifdef _WIN32 + PyOS_setsig(SIGBREAK, old_int); + #else + PyOS_setsig(SIGINT, old_int); + #endif + + start_events(); + + if (error) { + if (interrupted) { + PyErr_SetNone(PyExc_KeyboardInterrupt); + } + else + PyErr_SetString(RPy_RException, get_last_error_msg()); + return NULL; + } + + + return res; +} + +/* Evaluate a function given by a name (without arguments) */ +SEXP do_eval_fun(char *name) { + SEXP exp, fun, res; + + fun = get_fun_from_name(name); + if (!fun) + return NULL; + + PROTECT(fun); + PROTECT(exp = allocVector(LANGSXP, 1)); + SETCAR(exp, fun); + + PROTECT(res = do_eval_expr(exp)); + UNPROTECT(3); + return res; +} + +/* + * Get an R **function** object by its name. When not found, an exception is + * raised. The checking of the length of the identifier is needed to + * avoid R raising an error causing Python to dump core. + */ +SEXP get_fun_from_name(char *ident) { + SEXP obj; + + /* For R not to throw an error, we must check the identifier is + neither null nor greater than MAXIDSIZE */ + if (!*ident) { + PyErr_SetString(RPy_Exception, "attempt to use zero-length variable name"); + return NULL; + } + if (strlen(ident) > MAXIDSIZE) { + PyErr_SetString(RPy_Exception, "symbol print-name too long"); + return NULL; + } + +#if R_VERSION < 0x20000 + obj = Rf_findVar(Rf_install(ident), R_GlobalEnv); +#else + /* + * For R-2.0.0 and later, it is necessary to use findFun to get + * functions. Unfortunately, calling findFun on an undefined name + * causes a segfault! + * + * Solution: + * + * 1) Call findVar on the name + * + * 2) If something has the name, call findFun + * + * 3) Raise an error if either step 1 or 2 fails. + */ + obj = Rf_findVar(Rf_install(ident), R_GlobalEnv); + + if (obj != R_UnboundValue) + obj = Rf_findFun(Rf_install(ident), R_GlobalEnv); +#endif + + if (obj == R_UnboundValue) { + PyErr_Format(RPy_Exception, "R Function \"%s\" not found", ident); + return NULL; + } + return obj; +} + +/* Obtain the text of the last R error message */ +const char *get_last_error_msg() { + SEXP msg; + + msg = do_eval_fun("geterrmessage"); + return CHARACTER_VALUE(msg); +} --- rpy-1.0.3.orig/src/io.c +++ rpy-1.0.3/src/io.c @@ -1,5 +1,5 @@ /* - * $Id: io.c 393 2008-01-02 17:34:28Z warnes $ + * $Id: io.c 515 2008-05-14 13:53:05Z warnes $ * Input/Output routines */ @@ -130,7 +130,7 @@ PyErr_Clear(); return 0; } - snprintf(buf, len, "%s", PyString_AsString(input_data)); + snprintf( (char*) buf, len, "%s", PyString_AsString(input_data)); Py_DECREF(input_data); return 1; } --- rpy-1.0.3.orig/src/io3001.c +++ rpy-1.0.3/src/io3001.c @@ -0,0 +1,273 @@ +/* + * $Id: io.c 515 2008-05-14 13:53:05Z warnes $ + * Input/Output routines + */ + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the RPy python module. + * + * The Initial Developer of the Original Code is Walter Moreira. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Gregory R. Warnes (Maintainer) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#include "RPy.h" + +#define ENTER_PY { PyThreadState* tstate = NULL;\ + if (_PyThreadState_Current == NULL) {\ + tstate = PyThreadState_New(my_interp);\ + PyEval_AcquireThread(tstate);\ + } + +#define LEAVE_PY if (tstate) {\ + PyEval_ReleaseThread(tstate);}\ + } + +PyObject *rpy_output=NULL, *rpy_input=NULL, *rpy_showfiles=NULL; + +/* Show the traceback of an exception which occurred in a I/O process, + except when the error is a KeyboardInterrupt, in which case abort + the R interpreter */ +void +RPy_ShowException() +{ + PyObject *err; + + if ((err = PyErr_Occurred())) { + if (PyErr_GivenExceptionMatches(err, PyExc_KeyboardInterrupt)) { + interrupt_R(0); + } + else { + PyErr_WriteUnraisable(err); + PyErr_Clear(); + } + } +} + + +void +RPy_WriteConsole(char *buf, int len) +{ + PyOS_sighandler_t old_int; + PyObject *dummy; + + /* It is necessary to restore the Python handler when using a Python + function for I/O. */ + old_int = PyOS_getsig(SIGINT); + PyOS_setsig(SIGINT, python_sigint); + if (rpy_output) { + ENTER_PY + dummy = PyObject_CallFunction(rpy_output, "s", buf); + Py_XDECREF(dummy); + LEAVE_PY + } + signal(SIGINT, old_int); + RPy_ShowException(); +} + +#ifdef _WIN32 +int +RPy_ReadConsole(char *prompt, + char *buf, + int len, + int addtohistory) +#else +int +RPy_ReadConsole(char *prompt, + unsigned char *buf, + int len, + int addtohistory) +#endif +{ + PyObject *input_data; + PyOS_sighandler_t old_int; + + if (!rpy_input) + return 0; + + old_int = PyOS_getsig(SIGINT); + PyOS_setsig(SIGINT, python_sigint); + ENTER_PY + start_events(); + input_data = PyObject_CallFunction(rpy_input, "si", prompt, len); + stop_events(); + LEAVE_PY + + signal(SIGINT, old_int); + + RPy_ShowException(); + + if (!input_data) { + PyErr_Clear(); + return 0; + } + snprintf( (char*) buf, len, "%s", PyString_AsString(input_data)); + Py_DECREF(input_data); + return 1; +} + +int +RPy_ShowFiles(int nfile, char **file, char **headers, + char *wtitle, int del, char *pager) +{ + PyObject *pyfiles, *pyheaders, *result, *f, *h; + PyOS_sighandler_t old_int; + int i; + + if (rpy_showfiles==NULL) + return 0; + + old_int = PyOS_getsig(SIGINT); + PyOS_setsig(SIGINT, python_sigint); + + ENTER_PY + + pyfiles = PyList_New(0); + pyheaders = PyList_New(0); + if (!(pyfiles && pyheaders)) { + return 0; + } + + for (i=0; i (Maintainer) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#include "RPy.h" + +#define ENTER_PY { PyThreadState* tstate = NULL;\ + if (_PyThreadState_Current == NULL) {\ + tstate = PyThreadState_New(my_interp);\ + PyEval_AcquireThread(tstate);\ + } + +#define LEAVE_PY if (tstate) {\ + PyEval_ReleaseThread(tstate);}\ + } + +PyObject *rpy_output=NULL, *rpy_input=NULL, *rpy_showfiles=NULL; + +/* Show the traceback of an exception which occurred in a I/O process, + except when the error is a KeyboardInterrupt, in which case abort + the R interpreter */ +void +RPy_ShowException() +{ + PyObject *err; + + if ((err = PyErr_Occurred())) { + if (PyErr_GivenExceptionMatches(err, PyExc_KeyboardInterrupt)) { + interrupt_R(0); + } + else { + PyErr_WriteUnraisable(err); + PyErr_Clear(); + } + } +} + + +void +RPy_WriteConsole(char *buf, int len) +{ + PyOS_sighandler_t old_int; + PyObject *dummy; + + /* It is necessary to restore the Python handler when using a Python + function for I/O. */ + old_int = PyOS_getsig(SIGINT); + PyOS_setsig(SIGINT, python_sigint); + if (rpy_output) { + ENTER_PY + dummy = PyObject_CallFunction(rpy_output, "s", buf); + Py_XDECREF(dummy); + LEAVE_PY + } + signal(SIGINT, old_int); + RPy_ShowException(); +} + +#ifdef _WIN32 +int +RPy_ReadConsole(char *prompt, + char *buf, + int len, + int addtohistory) +#else +int +RPy_ReadConsole(char *prompt, + unsigned char *buf, + int len, + int addtohistory) +#endif +{ + PyObject *input_data; + PyOS_sighandler_t old_int; + + if (!rpy_input) + return 0; + + old_int = PyOS_getsig(SIGINT); + PyOS_setsig(SIGINT, python_sigint); + ENTER_PY + start_events(); + input_data = PyObject_CallFunction(rpy_input, "si", prompt, len); + stop_events(); + LEAVE_PY + + signal(SIGINT, old_int); + + RPy_ShowException(); + + if (!input_data) { + PyErr_Clear(); + return 0; + } + snprintf( (char*) buf, len, "%s", PyString_AsString(input_data)); + Py_DECREF(input_data); + return 1; +} + +int +RPy_ShowFiles(int nfile, char **file, char **headers, + char *wtitle, int del, char *pager) +{ + PyObject *pyfiles, *pyheaders, *result, *f, *h; + PyOS_sighandler_t old_int; + int i; + + if (rpy_showfiles==NULL) + return 0; + + old_int = PyOS_getsig(SIGINT); + PyOS_setsig(SIGINT, python_sigint); + + ENTER_PY + + pyfiles = PyList_New(0); + pyheaders = PyList_New(0); + if (!(pyfiles && pyheaders)) { + return 0; + } + + for (i=0; i (Maintainer) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include +#if (R_VERSION >= R_Version(2,3,0)) + +# ifndef _WIN32 +# define CSTACK_DEFNS // Enable definitions needed for stack checking control +# endif + +#endif + +#include "RPy.h" + +#define NONAMELESSUNION +#include +#include +#include + +/* Flag indicating whether Numpy/Numeric is available in this session + * + * This is necessary since Numpy/Numeric may not available at run time, even if + * it was available at compile time. +*/ +static int use_numeric=0; + + +/* Local function definitions */ +DL_EXPORT(void) INIT_RPY(void); /* Module initializer */ +static PyObject *r_init(PyObject *self, /* Class initializer */ + PyObject *args); +static PyObject *r_cleanup(void); /* Clean up R & release resources */ + +#ifdef _WIN32 +static void init_embedded_win32(int argc, char *argv[]); +#endif + +/* Global objects */ +static SEXP get_item; +static SEXP set_item; +static SEXP length; +static SEXP aperm; +static PyObject *class_table; +static PyObject *proc_table; +static int default_mode; +static PyObject *r_lock; +PyObject *RPy_Exception; +PyObject *RPy_TypeConversionException; +PyObject *RPy_RException; + +static char RHOME[BUFSIZ]; +static char RVERSION[BUFSIZ]; +static char RVER[BUFSIZ]; +static char RUSER[BUFSIZ]; +char *defaultargv[] = {"rpy", "-q", "--vanilla"}; +int defaultargc = sizeof(defaultargv) / sizeof(defaultargv[0]); + +/* Global interpreter */ +PyInterpreterState *my_interp; + +/* Signal whether R is running interactively */ +int R_interact; + +/* RPy namespace */ +PyObject *rpy; +PyObject *rpy_dict; + + +#ifdef WITH_NUMERIC +static PyObject *Py_transpose; +#endif + +/* Global list to protect R objects from garbage collection */ +/* This is inspired in $R_SRC/src/main/memory.c */ +static SEXP R_References; + +static SEXP +RecursiveRelease(SEXP obj, SEXP list) +{ + if (!isNull(list)) { + if (obj == CAR(list)) + return CDR(list); + else + SETCDR(list, RecursiveRelease(obj, CDR(list))); + } + return list; +} + +/* Robj methods. Following xxmodule.c from Python distro. */ + +static void +Robj_dealloc(RobjObject *self) +{ + /* Remove the object from the list of protected objects */ + R_References = RecursiveRelease(self->R_obj, R_References); + SET_SYMVALUE(install("R.References"), R_References); + + PyObject_Del(self); +} + +RobjObject * +Robj_new(SEXP robj, int conversion) +{ + RobjObject *self; + self = PyObject_New(RobjObject, &Robj_Type); + if (!self) + return NULL; + + if (!robj) + return NULL; + + /* Protect the R object */ + R_References = CONS(robj, R_References); + SET_SYMVALUE(install("R.References"), R_References); + + self->R_obj = robj; + self->conversion = conversion; + return self; +} + +#ifndef PRE_2_2 +static PyObject * +Robj_tpnew(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *self; + + self = type->tp_alloc(type, 0); + return self; +} +#endif + +/* Type conversion routines. See documentation for details */ + +/* These are auxiliaries for a state machine for converting Python + list to the coarsest R vector type */ +#define ANY_T 0 +#define BOOL_T 1 +#define INT_T 2 +#define FLOAT_T 3 +#define COMPLEX_T 4 +#define STRING_T 5 +#define ROBJ_T 6 + +static int +type_to_int(PyObject *obj) +{ + if (PyBool_Check(obj)) + return BOOL_T; + else if (PyInt_Check(obj)) + return INT_T; + else if (PyFloat_Check(obj)) + return FLOAT_T; + else if (PyComplex_Check(obj)) + return COMPLEX_T; + else if (PyNumber_Check(obj)) + return ANY_T; + else if (PyString_Check(obj)) + return STRING_T; + else if (PyUnicode_Check(obj)) + return STRING_T; + else if (Robj_Check(obj)) + return ROBJ_T; + else + return ANY_T; +} + +/* Make a R list or vector from a Python sequence */ +static SEXP +seq_to_R(PyObject *obj) +{ + PyObject *it; + SEXP robj, rit; + int i, len, state; + + /* This matrix defines what mode a vector should take given what + it already contains and a new item + + E.g. Row 0 indicates that if we've seen an any, the vector will + always remain an any. Row 3 indicates that if we've seen a + float, then seeing an boolean, integer, or float will preserve + the vector as a float vector, while seeing a string or an Robj will + convert it into an any vector. + */ + int fsm[7][7] = { + {0, 0, 0, 0, 0, 0, 0}, // any + {0, 1, 2, 3, 4, 0, 0}, // bool + {0, 2, 2, 3, 4, 0, 0}, // int + {0, 3, 3, 3, 4, 0, 0}, // float + {0, 4, 4, 4, 4, 0, 0}, // complex + {0, 0, 0, 0, 0, 5, 0}, // string + {0, 0, 0, 0, 0, 0, 6} // RObj + }; + + len = PySequence_Length(obj); + if (len == 0) + return R_NilValue; + + PROTECT(robj = NEW_LIST(len)); + + state = -1; + for (i=0; idimensions; + type = obj->descr->type_num; + size = PyArray_Size( (PyObject*) obj); + + /* Handle a vector without dimensions, just length */ + if(obj->nd==0) + { + PROTECT(Rdims = allocVector(INTSXP, 1)); + PROTECT(tRdims = allocVector(INTSXP, 1)); + INTEGER(Rdims)[0] = size; + INTEGER(tRdims)[0] = size; + } + else + { + PROTECT(Rdims = allocVector(INTSXP, obj->nd)); + PROTECT(tRdims = allocVector(INTSXP, obj->nd)); + + for (i=0; ind; i++) + { + if (dims[i] == 0) + { + UNPROTECT(2); + return R_NilValue; + } + INTEGER(Rdims)[i] = dims[(obj->nd)-i-1]; + INTEGER(tRdims)[i] = (obj->nd)-i; + } + } + + switch(type) + { + + /*******************/ + /* String Variants */ + /*******************/ + /* TODO: Add proper handling of NumPy character arrays. + The following code DOES NOT WORK: + + #if WITH_NUMERIC==3 + case PyArray_UNICODE: + case PyArray_STRING: + case PyArray_CHAR: + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_STRING, 0, 0); + #endif + + The problem is that the PyArray call throws an exception, + presumably because we haven't given a width specifier. + + NumPy strings are fixed-width, and may not be null terminated. R only handles + null terminated (varying width) strings. We need a separate + code path to handle this, as it requires quite different + handling than the numeric arrays dealt with below. + */ + + + /******************************************/ + /* All complex to (double,double) complex */ + /******************************************/ + +#if WITH_NUMERIC==1 /* Numeric */ + case PyArray_CFLOAT: + case PyArray_CDOUBLE: +#else /* NumPy */ + case PyArray_COMPLEX64: + case PyArray_COMPLEX128: +#endif + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_CDOUBLE, 0, 0); + break; + + + /**********************************************************************************/ + /* Convert all integers to platform integer (except 64 bit int on 32 bit platforms) */ + /************************************************************************************/ + +#if WITH_NUMERIC==1 /* Numeric */ + case PyArray_UBYTE: + case PyArray_SBYTE: + case PyArray_SHORT: + case PyArray_INT: + case PyArray_LONG: + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_INT, 0, 0); + break; +#else /* NumPy */ + case PyArray_BOOL: + case PyArray_INT8: + case PyArray_UINT8: + case PyArray_INT16: + case PyArray_UINT16: + case PyArray_INT32: + case PyArray_UINT32: +#if PyArray_INT==PyArray_INT64 /* 64 bit platform */ + case PyArray_INT64: + case PyArray_UINT64: +#else + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_INT, 0, 0); + break; +#endif +#endif + + /**************************************************/ + /* All floats (and over-sized integers) to double */ + /**************************************************/ +#if WITH_NUMERIC==1 /* Numeric */ + case PyArray_FLOAT: + case PyArray_DOUBLE: +#else /* NumPy */ + case PyArray_FLOAT32: + case PyArray_FLOAT64: +#if PyArray_INT!=PyArray_INT64 /* 32 bit platform */ + case PyArray_INT64: + case PyArray_UINT64: +#endif +#endif + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_DOUBLE, 0, 0); + break; + + default: + UNPROTECT(2); + PyErr_Format(RPy_TypeConversionException, + "Numeric/NumPy arrays containing %s are not supported.", + obj->ob_type->tp_name); + return R_NilValue; + break; + } + + + pytl = Py_BuildValue("[i]", size); + nobj = PyArray_Reshape(obj, pytl); + Py_XDECREF(pytl); + Py_XDECREF(obj); + + if (nobj == NULL) + { + UNPROTECT(2); + return R_NilValue; + } + + + PROTECT(Rarray = seq_to_R(nobj)); + if (Rarray == NULL) + { + UNPROTECT(3); + return R_NilValue; + } + + + Py_XDECREF(nobj); + SET_DIM(Rarray, Rdims); + + PROTECT(e = allocVector(LANGSXP, 3)); + SETCAR(e, aperm); + SETCAR(CDR(e), Rarray); + SETCAR(CDR(CDR(e)), tRdims); + PROTECT(Rarray = do_eval_expr(e)); + + UNPROTECT(5); + return Rarray; +} +#endif + +/* Convert a Python object to a R object. An Robj is passed w/o + * modifications, an object which provides a '.as_r()' method, is + * passed as the result of that method */ +SEXP +to_Robj(PyObject *obj) +{ + SEXP robj; + Py_complex c; + PyObject *to_r_meth; + PyObject *tempObj; + int do_decref = 0; + + if (obj==NULL) + return NULL; + + if (obj == Py_None) { + return R_NilValue; + } + + to_r_meth = PyObject_GetAttrString(obj, "as_r"); + if (to_r_meth) { + obj = PyObject_CallObject(to_r_meth, NULL); + Py_DECREF(to_r_meth); + if (obj==NULL) + return NULL; + do_decref = 1; + } + PyErr_Clear(); + + + if (Robj_Check(obj)) + { + PROTECT(robj = ((RobjObject *)obj)->R_obj); + } + else if (PyBool_Check(obj)) + { + PROTECT(robj = NEW_LOGICAL(1)); + LOGICAL_DATA(robj)[0] = (Py_True==obj); + } + else if (PyInt_Check(obj)) + { + PROTECT(robj = NEW_INTEGER(1)); + INTEGER_DATA(robj)[0] = (int) PyInt_AsLong(obj); + } + else if (PyFloat_Check(obj)) + { + PROTECT(robj = NEW_NUMERIC(1)); + NUMERIC_DATA(robj)[0] = PyFloat_AsDouble(obj); + } + else if (PyComplex_Check(obj)) + { + PROTECT(robj = NEW_COMPLEX(1)); + c = PyComplex_AsCComplex(obj); + COMPLEX_DATA(robj)[0].r = c.real; + COMPLEX_DATA(robj)[0].i = c.imag; + } + else if (PyUnicode_Check(obj)) + { + /** Handle Unicode Strings. + * + * Ideally: Python Unicode -> R Unicode, + * + * Unfortunately, the R documentation is not forthcoming on how + * to accomplish this + * + * So, for the moment: + * python Unicode -> Python ASCII -> ordinary string -> R string + * + */ + PROTECT(robj = NEW_STRING(1)); + SET_STRING_ELT(robj, 0, COPY_TO_USER_STRING(PyString_AsString(PyUnicode_AsASCIIString(obj)))); + } + else if (PyString_Check(obj)) + { + PROTECT(robj = NEW_STRING(1)); + SET_STRING_ELT(robj, 0, COPY_TO_USER_STRING(PyString_AsString(obj))); + } +#ifdef WITH_NUMERIC + else if (use_numeric && PyArray_Check(obj)) + { + PROTECT(robj = to_Rarray(obj)); + } +#endif + else if ((PySequence_Check(obj)) && + (PySequence_Size(obj) >= 0)) + { + PROTECT(robj = seq_to_R(obj)); /* No labels */ + } + else if ((PyMapping_Check(obj)) && + (PyMapping_Size(obj) >= 0)) + { + PROTECT(robj = dict_to_R(obj)); + } + else if (PyNumber_Check(obj)) /* generic number interface */ + { + tempObj = PyNumber_Float(obj); + if(!tempObj) goto error; + + PROTECT(robj = NEW_NUMERIC(1)); + NUMERIC_DATA(robj)[0] = PyFloat_AsDouble(tempObj); + Py_DECREF(tempObj); + } + else + { + error: + PyErr_Format(RPy_TypeConversionException, + "cannot convert from type '%s'", + obj->ob_type->tp_name); + PROTECT(robj = NULL); /* Protected to avoid stack inbalance */ + } + + if (do_decref) + { + Py_DECREF(obj); + } + UNPROTECT(1); + return robj; +} + +/* Convert a R named vector or list to a Python dictionary */ +static PyObject * +to_PyDict(PyObject *obj, SEXP names) +{ + int len, i; + PyObject *it, *dict; + const char *name; + + if ((len = PySequence_Length(obj)) < 0) + return NULL; + + dict = PyDict_New(); + for (i=0; i 1) && (res[l-1] == '_') && (res[l-2] != '_')) + res[l-1]=0; + + while ((r=strchr(r, '_'))) + *r = '.'; + + return res; +} + +/* Convert a dict to keywords arguments for a R function */ +int +make_kwds(int lkwds, PyObject *kwds, SEXP *e) +{ + SEXP r; + const char *s; + int i; + PyObject *citems=NULL, *it; + PyObject *kwname; + + if (kwds) { + citems = PyMapping_Items(kwds); + } + + for (i=0; iR_obj); + e = CDR(e); + + if (!make_args(largs, args, &e)) { + UNPROTECT(1); + return NULL; + } + if (!make_kwds(lkwds, kwds, &e)) { + UNPROTECT(1); + return NULL; + } + + PROTECT(res = do_eval_expr(exp)); + if (!res) { + UNPROTECT(2); + return NULL; + } + + if (default_mode < 0) + conv = ((RobjObject *)self)->conversion; + else + conv = default_mode; + + obj = to_Pyobj_with_mode(res, conv); + UNPROTECT(2); + + //PrintWarnings(); /* show any warning messages */ + + return obj; +} + +/* Convert a sequence of (name, value) pairs to arguments to an R + function call */ +int +make_argl(int largl, PyObject *argl, SEXP *e) +{ + SEXP rvalue; + const char *name; + int i; + PyObject *it, *nobj, *value; + + if( !PySequence_Check(argl) ) goto fail_arg; + + for (i=0; i0) + { + SET_TAG(*e, Rf_install(name)); + PyMem_Free((void*) name); + } + + /* Move index to new end of call */ + *e = CDR(*e); + } + return 1; + + fail_arg: + PyErr_SetString(PyExc_ValueError, + "Argument must be a sequence of (\"name\", value) pairs.\n"); + fail: + return 0; +} + +/* Methods for the 'Robj' type */ + +/* Explicitly call an R object with a list containing (name, value) * + * argument pairs. 'name' can be None or '' to provide unnamed + * arguments. This function is necessary when the *order* of named + * arguments needs to be preserved. + */ + +static PyObject * +Robj_lcall(PyObject *self, PyObject *args) +{ + SEXP exp, e, res; + int largs, largl, conv; + PyObject *obj, *argl; + + /* Check arguments, there should be *exactly one* unnamed sequence. */ + largs = 0; + if (args) + largs = PyObject_Length(args); + if (largs<0) + return NULL; + + if(largs != 1 || !PySequence_Check(args) ) + { + PyErr_SetString(PyExc_ValueError, + "Argument must be a sequence of (\"name\", value) pairs.\n"); + return NULL; + } + + // extract our one argument + argl = PySequence_GetItem(args, 0); + Py_DECREF(args); + + largl = 0; + if (argl) + largl = PyObject_Length(argl); + if (largl<0) + return NULL; + + // A SEXP with the function to call and the arguments + PROTECT(exp = allocVector(LANGSXP, largl+1)); + e = exp; + SETCAR(e, ((RobjObject *)self)->R_obj); + e = CDR(e); + + // Add the arguments to the SEXP + if (!make_argl(largl, argl, &e)) { + UNPROTECT(1); + return NULL; + } + + // Evaluate + PROTECT(res = do_eval_expr(exp)); + if (!res) { + UNPROTECT(2); + return NULL; + } + + // Convert + if (default_mode < 0) + conv = ((RobjObject *)self)->conversion; + else + conv = default_mode; + + obj = to_Pyobj_with_mode(res, conv); + UNPROTECT(2); + + // Return + return obj; +} + + +/* Without args return the value of the conversion flag. With an + argument set the conversion flag to the truth value of the argument. */ +static PyObject * +Robj_autoconvert(PyObject *self, PyObject *args, PyObject *kwds) +{ + PyObject *obj; + int conversion=-2; + char *kwlist[] = {"val", 0}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:autoconvert", kwlist, + &conversion)) + return NULL; + + if (conversion > TOP_MODE) { + PyErr_SetString(PyExc_ValueError, "wrong mode"); + return NULL; + } + + if (conversion == -2) { + obj = PyInt_FromLong((long)((RobjObject *)self)->conversion); + } else { + ((RobjObject *)self)->conversion = conversion; + obj = Py_None; + Py_XINCREF(obj); + } + + return obj; +} + +static PyObject * +Robj_as_py(PyObject *self, PyObject *args, PyObject *kwds) +{ + PyObject *obj; + char *kwlist[] = {"mode", 0}; + int conv=default_mode; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:as_py", kwlist, + &conv)) + return NULL; + + if (conv <= -2 || conv > TOP_MODE) { + PyErr_SetString(PyExc_ValueError, "wrong mode"); + return NULL; + } + + if (conv < 0) + conv = TOP_MODE; + + obj = to_Pyobj_with_mode(((RobjObject *)self)->R_obj, conv); + return obj; +} + +static PyMethodDef Robj_methods[] = { + {"autoconvert", (PyCFunction)Robj_autoconvert, METH_VARARGS|METH_KEYWORDS}, + {"local_mode", (PyCFunction)Robj_autoconvert, METH_VARARGS|METH_KEYWORDS}, + {"as_py", (PyCFunction)Robj_as_py, METH_VARARGS|METH_KEYWORDS}, + {"lcall", (PyCFunction)Robj_lcall, METH_VARARGS}, + {NULL, NULL} /* sentinel */ +}; + +/* Sequence protocol implementation */ + +/* len(a) */ +static int +Robj_len(PyObject *a) +{ + SEXP e, robj; + + PROTECT(e = allocVector(LANGSXP, 2)); + SETCAR(e, length); + SETCAR(CDR(e), ((RobjObject *)a)->R_obj); + + if (!(robj = do_eval_expr(e))) { + UNPROTECT(1); + return -1; + } + + UNPROTECT(1); + return INTEGER_DATA(robj)[0]; +} + +/* a[i] = v */ +static int +Robj_ass_item(PyObject *a, int i, PyObject *v) +{ + SEXP e, ri, robj; + + PROTECT(e = allocVector(LANGSXP, 4)); + ri = NEW_INTEGER(1); + INTEGER_DATA(ri)[0] = i+1; + SETCAR(e, set_item); + SETCAR(CDR(e), ((RobjObject *)a)->R_obj); + SETCAR(CDR(CDR(e)), ri); + SETCAR(CDR(CDR(CDR(e))), to_Robj(v)); + + if(PyErr_Occurred()) + return -1; + + if (!(robj = do_eval_expr(e))) { + UNPROTECT(1); + return -1; + } + + ((RobjObject *)a)->R_obj = robj; + UNPROTECT(1); + return 0; +} + +/* a[i] */ +static PyObject * +Robj_item(PyObject *a, int i) +{ + SEXP ri, robj, e; + PyObject *obj; + int len, c; + + if ((len = Robj_len(a)) < 0) + return NULL; + if (i >= len || i < 0) { + PyErr_SetString(PyExc_IndexError, "R object index out of range"); + return NULL; + } + + PROTECT(ri = NEW_INTEGER(1)); + INTEGER_DATA(ri)[0] = i+1; + PROTECT(e = allocVector(LANGSXP, 3)); + SETCAR(e, get_item); + SETCAR(CDR(e), ((RobjObject *)a)->R_obj); + SETCAR(CDR(CDR(e)), ri); + + if (!(robj = do_eval_expr(e))) { + UNPROTECT(2); + return NULL; + } + + UNPROTECT(2); + + /* If there is a default mode, use it; otherwise, use the top mode. */ + if (default_mode < 0) + c = TOP_MODE; + else + c = default_mode; + obj = to_Pyobj_with_mode(robj, c); + return obj; +} + +/* Get a slice: a[x:y] */ +/*FIXME: starting with Python 2.5, ilow and ihigh should probably + * be of type Py_ssize_t. + */ +static PyObject * +Robj_slice(PyObject *a, int ilow, int ihigh) +{ + SEXP robj, e, index; + PyObject *obj; + int robjLen, sliceLen, c; + int ii; + + robjLen = Robj_len(a); + + if (robjLen < 0) + return NULL; + + if (ilow < 0) { + PyErr_SetString(PyExc_IndexError, + "R object index out of range (lowest index is negative)"); + return NULL; + //ilow = 0; + } else if (ilow > robjLen) { + PyErr_SetString(PyExc_IndexError, + "R object index out of range (lowest index > object length)"); + return NULL; + //ilow = robjLen; + } + if (ihigh < ilow) { + PyErr_SetString(PyExc_IndexError, + "R object index out of range (highest index < lowest index)"); + return NULL; + //ihigh = ilow; + } else if (ihigh > robjLen) { + PyErr_SetString(PyExc_IndexError, + "R object index out of range (highest index > object length)"); + //return NULL; + ihigh = robjLen; + } + sliceLen = ihigh - ilow; + + /* if (ilow >= robjLen || ilow < 0) { */ + /* PyErr_SetString(PyExc_IndexError, "R object index out of range"); */ + /* return NULL; */ + /* } */ + + PROTECT(index = allocVector(INTSXP, sliceLen)); + + for (ii = 0; ii < sliceLen; ii++) { + INTEGER_POINTER(index)[ii] = ii + ilow + 1; + } + + PROTECT(e = allocVector(LANGSXP, 3)); + SETCAR(e, get_item); + SETCAR(CDR(e), ((RobjObject *)a)->R_obj); + SETCAR(CDR(CDR(e)), index); + + if (!(robj = do_eval_expr(e))) { + UNPROTECT(2); + return NULL; + } + + UNPROTECT(2); + + /* If there is a default mode, use it; otherwise, use the top mode. */ + if (default_mode < 0) + c = TOP_MODE; + else + c = default_mode; + obj = to_Pyobj_with_mode(robj, c); + return obj; +} + + +/* FIXME: + * Python 2.5 will feel happier with ssizeargfunc and ssizessizeargfunc + */ +/* We should implement sq_slice, sq_contains ... */ +static PySequenceMethods Robj_as_sequence = { + (inquiry)Robj_len, /* sq_length */ + 0, /* sq_concat */ + 0, /* sq_repeat */ + (intargfunc)Robj_item, /* sq_item */ + (intintargfunc)Robj_slice, /* sq_slice */ + (intobjargproc)Robj_ass_item, /* sq_ass_item */ + 0, /* sq_ass_slice */ + 0, /* sq_contains */ + 0, /* sq_inplace_concat */ + 0 /* sq_inplace_repeat */ +}; + + +/* The 'Robj' table. When compiled under Python 2.2, the type 'Robj' + is subclassable. */ + +#ifdef PRE_2_2 +static PyObject * +Robj_getattr(RobjObject *self, char *name) +{ + return Py_FindMethod(Robj_methods, (PyObject *)self, name); +} +#endif + +PyTypeObject Robj_Type = { + /* The ob_type field must be initialized in the module init function + * to be portable to Windows without using C++. */ +#if defined(PRE_2_2) || defined(_WIN32) // Matjaz + PyObject_HEAD_INIT(NULL) +#else + PyObject_HEAD_INIT(&PyType_Type) +#endif + 0, /*ob_size*/ + "Robj", /*tp_name*/ + sizeof(RobjObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)Robj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ +#ifdef PRE_2_2 + (getattrfunc)Robj_getattr, +#else + 0, +#endif + 0, + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &Robj_as_sequence, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + (ternaryfunc)Robj_call, /*tp_call*/ + 0, /*tp_str*/ +#if defined(PRE_2_2) || defined(_WIN32) + 0, +#else + PyObject_GenericGetAttr, /*tp_getattro*/ +#endif + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ +#ifdef PRE_2_2 + 0, +#else + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#endif + 0, /*tp_doc*/ + 0, /*tp_traverse*/ +#ifndef PRE_2_2 + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + Robj_methods, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ +#ifdef _WIN32 + 0, /*tp_alloc*/ +#else + PyType_GenericAlloc, /*tp_alloc*/ +#endif + Robj_tpnew, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ +#endif +}; + + +/* Module functions */ + +/* Obtain an R object via its name. 'autoconvert' is the keyword to + set the autoconversion flag. */ +static PyObject * +get_fun(PyObject *self, PyObject *args, PyObject *kwds) +{ + char *obj_str; + int conversion=TOP_MODE; + SEXP robj; + + static char *kwlist[] = {"name", "autoconvert", 0}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i:get", kwlist, + &obj_str, &conversion)) + return NULL; + + robj = get_fun_from_name(obj_str); + if (!robj) + return NULL; + + return (PyObject *)Robj_new(robj, conversion); +} + +static PyObject * +set_mode(PyObject *self, PyObject *args) +{ + int i=-1; + + if (!PyArg_ParseTuple(args, "i:set_mode", &i)) + return NULL; + + if (i<-1 || i>TOP_MODE) { + PyErr_SetString(PyExc_ValueError, "wrong mode"); + return NULL; + } + + default_mode = i; + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +get_mode(PyObject *self, PyObject *args) +{ + if (!PyArg_ParseTuple(args, ":get_mode")) + return NULL; + + return PyInt_FromLong(default_mode); +} + +static PyObject * +r_events(PyObject *self, PyObject *args, PyObject *kwds) +#ifdef _WIN32 +{ + return NULL; +} +#else +{ + fd_set *what; + int usec=10000; + + static char *kwlist[] = {"usec", 0}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:r_events", + kwlist, &usec)) + return NULL; + + if (R_interact) { + Py_BEGIN_ALLOW_THREADS + what = R_checkActivity(usec, 0); + R_runHandlers(R_InputHandlers, what); + Py_END_ALLOW_THREADS + } + + Py_INCREF(Py_None); + return Py_None; +} +#endif + +void +stop_events(void) +{ + PyObject *o; + + if (!rpy_dict) + return; + + if (!r_lock) + r_lock = PyDict_GetItemString(rpy_dict, "_r_lock"); + + o = PyObject_CallMethod(r_lock, "acquire", NULL); + Py_XDECREF(o); +} + +void +start_events(void) +{ + PyObject *o; + + if (!rpy_dict) + return; + + if (!r_lock) + r_lock = PyDict_GetItemString(rpy_dict, "_r_lock"); + + o = PyObject_CallMethod(r_lock, "release", NULL); + Py_XDECREF(o); +} + + +/* + * Based on code from Rstd_CleanUp(); + * from src/unix/sys-std.c + */ + +void r_finalize(void) +{ +#if (R_VERSION < R_Version(2,4,0)) + unsigned char buf[1024]; + char * tmpdir; +#endif + + R_dot_Last(); + R_RunExitFinalizers(); + CleanEd(); +#if (R_VERSION >= R_Version(2,7,0)) + Rf_KillAllDevices(); +#else + KillAllDevices(); +#endif + +#if (R_VERSION >= R_Version(2,4,0)) + R_CleanTempDir(); +#else + if((tmpdir = getenv("R_SESSION_TMPDIR"))) { + +# ifdef _WIN32 + snprintf((char *)buf, 1024, "rmdir /S /Q %s", tmpdir); +# else + snprintf((char *)buf, 1024, "rm -rf %s", tmpdir); +# endif + + R_system((char *)buf); + } +#endif + + //PrintWarnings(); /* from device close and .Last */ + R_gc(); /* Remove any remaining R objects from memory */ +} + + +static PyObject * +r_cleanup(void) +{ + r_finalize(); + Py_INCREF(Py_None); + return Py_None; +} + +#ifdef WITH_NUMERIC +static void +init_numeric(void) +{ + PyObject *multiarray, *dict; + + if(use_numeric) + { + import_array(); + multiarray = PyImport_ImportModule(PY_ARRAY_MODULE_NAME); + if (multiarray) { + dict = PyModule_GetDict(multiarray); + if (dict) + Py_transpose = PyDict_GetItemString(dict, "transpose"); + } + } +} +#endif + +static PyObject * +r_init(PyObject *self, PyObject *args) +{ + static int first=1; + int i; + + if (!PyArg_ParseTuple(args, "i:r_init", &i)) + return NULL; + use_numeric = i; + +#ifdef WITH_NUMERIC + if(use_numeric) + init_numeric(); +#endif + + if(first==1) + { + first=0; + Py_INCREF(Py_None); + return Py_None; + } + else + { + PyErr_SetString(PyExc_RuntimeError, "Only one R object may be instantiated per session"); + return NULL; + } +} + +/* List of functions defined in the module */ +static PyMethodDef rpy_methods[] = { + {"get_fun", (PyCFunction)get_fun, METH_VARARGS | METH_KEYWORDS}, + {"set_mode", (PyCFunction)set_mode, METH_VARARGS}, + {"get_mode", (PyCFunction)get_mode, METH_VARARGS}, + {"set_output", (PyCFunction)set_output, METH_VARARGS}, + {"set_input", (PyCFunction)set_input, METH_VARARGS}, + {"set_showfiles", (PyCFunction)set_showfiles, METH_VARARGS}, + {"get_output", (PyCFunction)get_output, METH_VARARGS}, + {"get_input", (PyCFunction)get_input, METH_VARARGS}, + {"get_showfiles", (PyCFunction)get_showfiles, METH_VARARGS}, + {"r_events", (PyCFunction)r_events, METH_VARARGS | METH_KEYWORDS}, + {"r_cleanup", (PyCFunction)r_cleanup, METH_NOARGS}, + {"r_init", (PyCFunction)r_init, METH_VARARGS}, + {NULL, NULL} /* sentinel */ +}; + +#ifdef _WIN32 +static void char_message( char *s ) +{ + if (!s) return; + R_WriteConsole(s, strlen(s)); +} + +static int char_yesnocancel( char *s ) +{ + return 1; +} + +static void +RPyBusy( int which ) +{ + /* set a busy cursor ... in which = 1, unset if which = 0 */ +} + +static void +RPyDoNothing( void ) +{ +} + +/* initialise embedded R; based on rproxy_impl.c from the R distribution */ +static void +init_embedded_win32(int argc, + char *argv[]) +{ + structRstart rp; + Rstart Rp = &rp; + char Rversion[25]; + int index; + + + snprintf( Rversion, 25, "%s.%s", R_MAJOR, R_MINOR ); + if( strcmp( getDLLVersion(), Rversion ) != 0 ) { + PyErr_SetString( PyExc_ImportError, "R.DLL version does not match" ); + return; + } + + R_DefParams(Rp); + + /* set R_HOME */ + Rp->rhome = RHOME; + + index = strlen(RUSER) - 1; + + if (RUSER[index] == '/' || RUSER[index] == '\\') + RUSER[index] = '\0'; + + Rp->home = RUSER; + Rp->CharacterMode = LinkDLL; + + Rp->ReadConsole = (blah1) RPy_ReadConsole; // Matjaz + Rp->WriteConsole = (blah2) RPy_WriteConsole; // Matjaz + + Rp->CallBack = (blah3) RPyDoNothing; +#if R_VERSION < 0x20100 + Rp->message = char_message; + Rp->yesnocancel = char_yesnocancel; + Rp->busy = RPyBusy; +#else + Rp->ShowMessage = char_message; + Rp->YesNoCancel = char_yesnocancel; + Rp->Busy = RPyBusy; +#endif + + Rp->R_Quiet = TRUE; + + /* run as "interactive", so server won't be killed after an error */ + Rp->R_Slave = Rp->R_Verbose = 0; + Rp->R_Interactive = TRUE; + Rp->RestoreAction = SA_NORESTORE; /* no restore */ + Rp->SaveAction = SA_NOSAVE; /* no save */ + +#if R_VERSION < 0x20000 // pre-R-2.0.0 + + Rp->CommandLineArgs = NULL; + Rp->NumCommandLineArgs = 0; +#else + R_set_command_line_arguments(argc, argv); +#endif + R_SetParams(Rp); /* so R_ShowMessage is set */ + R_SizeFromEnv(Rp); + + R_SetParams(Rp); + + setup_term_ui(); + setup_Rmainloop(); +} +#endif + +/* Initialization function for the module */ +DL_EXPORT(void) +INIT_RPY(void) +{ + PyObject *m, *d; + PyOS_sighandler_t old_int; +#ifndef _WIN32 + PyOS_sighandler_t old_usr1, old_usr2; +#endif + SEXP interact; + + /* Get path and version information from environment */ + strncpy(RHOME, getenv("RPY_RHOME"), BUFSIZ); + strncpy(RVERSION, getenv("RPY_RVERSION"), BUFSIZ); + strncpy(RVER, getenv("RPY_RVER"), BUFSIZ); + strncpy(RUSER, getenv("RPY_RUSER"), BUFSIZ); + + if( !strlen(RHOME) || !strlen(RVERSION) || !strlen(RVER) || !strlen(RUSER)) + { + PyErr_Format(RPy_Exception, + "Unable to load R path or version information"); + return; + } + + Robj_Type.ob_type = &PyType_Type; +#if defined( _WIN32 ) && ! defined( PRE_2_2 ) + Robj_Type.tp_getattro = PyObject_GenericGetAttr; + Robj_Type.tp_alloc = PyType_GenericAlloc; +#endif + + /* Initialize the module with its content */ + if (PyType_Ready(&Robj_Type) < 0) + return; + m = Py_InitModule3(xstr(RPY_SHNAME), + rpy_methods, + "Python interface to the R Programming Language"); + Py_INCREF(&Robj_Type); + PyModule_AddObject(m, Robj_Type.tp_name, + (PyObject *)&Robj_Type); + + d = PyModule_GetDict(m); + + /* Save this interpreter */ + PyEval_InitThreads(); + my_interp = PyThreadState_Get()->interp; + + /* Save the Python signal handlers. If R inserts its handlers, we + cannot return to the Python interpreter. */ + old_int = PyOS_getsig(SIGINT); + python_sigint = old_int; +#ifndef _WIN32 + old_usr1 = PyOS_getsig(SIGUSR1); + old_usr2 = PyOS_getsig(SIGUSR2); +#endif + +#ifdef _WIN32 + init_embedded_win32(defaultargc, + defaultargv); +#else + Rf_initEmbeddedR(defaultargc, + defaultargv); +#endif + + +#ifdef CSTACK_DEFNS + /* Disable C stack checking, which is incompatible with use as a + shared library. */ + R_CStackLimit = (uintptr_t)-1; +#endif + + /* Restore Python handlers */ + PyOS_setsig(SIGINT, old_int); +#ifndef _WIN32 + PyOS_setsig(SIGUSR1, old_usr1); + PyOS_setsig(SIGUSR2, old_usr2); +#endif + + /* Several new exceptions: */ + RPy_Exception = PyErr_NewException("rpy.RPy_Exception", NULL, NULL); + RPy_TypeConversionException = PyErr_NewException("rpy.RPy_TypeConversionException", RPy_Exception, NULL); + RPy_RException = PyErr_NewException("rpy.RPy_RException", RPy_Exception, NULL); + + if (!RPy_Exception || !RPy_TypeConversionException || !RPy_RException ) + { + PyErr_Format(RPy_Exception, "Unable create RPy exceptions"); + return; + } + + PyDict_SetItemString(d, "RPy_Exception", RPy_Exception); + PyDict_SetItemString(d, "RPy_TypeConversionException", RPy_TypeConversionException); + PyDict_SetItemString(d, "RPy_RException", RPy_RException); + + // The conversion table + class_table = PyDict_New(); + proc_table = PyDict_New(); + PyDict_SetItemString(d, "__class_table__", class_table); + PyDict_SetItemString(d, "__proc_table__", proc_table); + + // The globals R objects for the sequence protocol + get_item = get_fun_from_name("["); + set_item = get_fun_from_name("[<-"); + length = get_fun_from_name("length"); + + // Function to transpose arrays + aperm = get_fun_from_name("aperm"); + + // Initialize the list of protected objects + R_References = R_NilValue; + SET_SYMVALUE(install("R.References"), R_References); + + // Initialize the default mode + default_mode = -1; + + // Check whether R is interactive or no + interact = do_eval_fun("interactive"); + R_interact = INTEGER(interact)[0]; + + // I/O routines + init_io_routines(); + + rpy = PyImport_ImportModule("rpy"); + rpy_dict = PyModule_GetDict(rpy); + // r_lock = PyDict_GetItemString(rpy_dict, "_r_lock"); + // PyObject_Print(r_lock, stderr, Py_PRINT_RAW); + r_lock = NULL; + + if( Py_AtExit( r_finalize ) ) + { + fprintf(stderr, "Warning: Unable to set R finalizer."); + fflush(stderr); + } + + +} + + --- rpy-1.0.3.orig/src/rpymodule3002.c +++ rpy-1.0.3/src/rpymodule3002.c @@ -0,0 +1,2108 @@ +/* + * $Id: rpymodule.c 797 2013-04-23 00:23:43Z eddelbuettel $ + * Implementation of the module '_rpy' and the 'Robj' type. + */ + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the RPy python module. + * + * The Initial Developer of the Original Code is Walter Moreira. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Gregory R. Warnes (Maintainer) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include +#if (R_VERSION >= R_Version(2,3,0)) + +# ifndef _WIN32 +# define CSTACK_DEFNS // Enable definitions needed for stack checking control +# endif + +#endif + +#include "RPy.h" + +#define NONAMELESSUNION +#include +#include +#include + +/* Flag indicating whether Numpy/Numeric is available in this session + * + * This is necessary since Numpy/Numeric may not available at run time, even if + * it was available at compile time. +*/ +static int use_numeric=0; + + +/* Local function definitions */ +DL_EXPORT(void) INIT_RPY(void); /* Module initializer */ +static PyObject *r_init(PyObject *self, /* Class initializer */ + PyObject *args); +static PyObject *r_cleanup(void); /* Clean up R & release resources */ + +#ifdef _WIN32 +static void init_embedded_win32(int argc, char *argv[]); +#endif + +/* Global objects */ +static SEXP get_item; +static SEXP set_item; +static SEXP length; +static SEXP aperm; +static PyObject *class_table; +static PyObject *proc_table; +static int default_mode; +static PyObject *r_lock; +PyObject *RPy_Exception; +PyObject *RPy_TypeConversionException; +PyObject *RPy_RException; + +static char RHOME[BUFSIZ]; +static char RVERSION[BUFSIZ]; +static char RVER[BUFSIZ]; +static char RUSER[BUFSIZ]; +char *defaultargv[] = {"rpy", "-q", "--vanilla"}; +int defaultargc = sizeof(defaultargv) / sizeof(defaultargv[0]); + +/* Global interpreter */ +PyInterpreterState *my_interp; + +/* Signal whether R is running interactively */ +int R_interact; + +/* RPy namespace */ +PyObject *rpy; +PyObject *rpy_dict; + + +#ifdef WITH_NUMERIC +static PyObject *Py_transpose; +#endif + +/* Global list to protect R objects from garbage collection */ +/* This is inspired in $R_SRC/src/main/memory.c */ +static SEXP R_References; + +static SEXP +RecursiveRelease(SEXP obj, SEXP list) +{ + if (!isNull(list)) { + if (obj == CAR(list)) + return CDR(list); + else + SETCDR(list, RecursiveRelease(obj, CDR(list))); + } + return list; +} + +/* Robj methods. Following xxmodule.c from Python distro. */ + +static void +Robj_dealloc(RobjObject *self) +{ + /* Remove the object from the list of protected objects */ + R_References = RecursiveRelease(self->R_obj, R_References); + SET_SYMVALUE(install("R.References"), R_References); + + PyObject_Del(self); +} + +RobjObject * +Robj_new(SEXP robj, int conversion) +{ + RobjObject *self; + self = PyObject_New(RobjObject, &Robj_Type); + if (!self) + return NULL; + + if (!robj) + return NULL; + + /* Protect the R object */ + R_References = CONS(robj, R_References); + SET_SYMVALUE(install("R.References"), R_References); + + self->R_obj = robj; + self->conversion = conversion; + return self; +} + +#ifndef PRE_2_2 +static PyObject * +Robj_tpnew(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *self; + + self = type->tp_alloc(type, 0); + return self; +} +#endif + +/* Type conversion routines. See documentation for details */ + +/* These are auxiliaries for a state machine for converting Python + list to the coarsest R vector type */ +#define ANY_T 0 +#define BOOL_T 1 +#define INT_T 2 +#define FLOAT_T 3 +#define COMPLEX_T 4 +#define STRING_T 5 +#define ROBJ_T 6 + +static int +type_to_int(PyObject *obj) +{ + if (PyBool_Check(obj)) + return BOOL_T; + else if (PyInt_Check(obj)) + return INT_T; + else if (PyFloat_Check(obj)) + return FLOAT_T; + else if (PyComplex_Check(obj)) + return COMPLEX_T; + else if (PyNumber_Check(obj)) + return ANY_T; + else if (PyString_Check(obj)) + return STRING_T; + else if (PyUnicode_Check(obj)) + return STRING_T; + else if (Robj_Check(obj)) + return ROBJ_T; + else + return ANY_T; +} + +/* Make a R list or vector from a Python sequence */ +static SEXP +seq_to_R(PyObject *obj) +{ + PyObject *it; + SEXP robj, rit; + int i, len, state; + + /* This matrix defines what mode a vector should take given what + it already contains and a new item + + E.g. Row 0 indicates that if we've seen an any, the vector will + always remain an any. Row 3 indicates that if we've seen a + float, then seeing an boolean, integer, or float will preserve + the vector as a float vector, while seeing a string or an Robj will + convert it into an any vector. + */ + int fsm[7][7] = { + {0, 0, 0, 0, 0, 0, 0}, // any + {0, 1, 2, 3, 4, 0, 0}, // bool + {0, 2, 2, 3, 4, 0, 0}, // int + {0, 3, 3, 3, 4, 0, 0}, // float + {0, 4, 4, 4, 4, 0, 0}, // complex + {0, 0, 0, 0, 0, 5, 0}, // string + {0, 0, 0, 0, 0, 0, 6} // RObj + }; + + len = PySequence_Length(obj); + if (len == 0) + return R_NilValue; + + PROTECT(robj = NEW_LIST(len)); + + state = -1; + for (i=0; idimensions; + type = obj->descr->type_num; + size = PyArray_Size( (PyObject*) obj); + + /* Handle a vector without dimensions, just length */ + if(obj->nd==0) + { + PROTECT(Rdims = allocVector(INTSXP, 1)); + PROTECT(tRdims = allocVector(INTSXP, 1)); + INTEGER(Rdims)[0] = size; + INTEGER(tRdims)[0] = size; + } + else + { + PROTECT(Rdims = allocVector(INTSXP, obj->nd)); + PROTECT(tRdims = allocVector(INTSXP, obj->nd)); + + for (i=0; ind; i++) + { + if (dims[i] == 0) + { + UNPROTECT(2); + return R_NilValue; + } + INTEGER(Rdims)[i] = dims[(obj->nd)-i-1]; + INTEGER(tRdims)[i] = (obj->nd)-i; + } + } + + switch(type) + { + + /*******************/ + /* String Variants */ + /*******************/ + /* TODO: Add proper handling of NumPy character arrays. + The following code DOES NOT WORK: + + #if WITH_NUMERIC==3 + case PyArray_UNICODE: + case PyArray_STRING: + case PyArray_CHAR: + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_STRING, 0, 0); + #endif + + The problem is that the PyArray call throws an exception, + presumably because we haven't given a width specifier. + + NumPy strings are fixed-width, and may not be null terminated. R only handles + null terminated (varying width) strings. We need a separate + code path to handle this, as it requires quite different + handling than the numeric arrays dealt with below. + */ + + + /******************************************/ + /* All complex to (double,double) complex */ + /******************************************/ + +#if WITH_NUMERIC==1 /* Numeric */ + case PyArray_CFLOAT: + case PyArray_CDOUBLE: +#else /* NumPy */ + case PyArray_COMPLEX64: + case PyArray_COMPLEX128: +#endif + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_CDOUBLE, 0, 0); + break; + + + /**********************************************************************************/ + /* Convert all integers to platform integer (except 64 bit int on 32 bit platforms) */ + /************************************************************************************/ + +#if WITH_NUMERIC==1 /* Numeric */ + case PyArray_UBYTE: + case PyArray_SBYTE: + case PyArray_SHORT: + case PyArray_INT: + case PyArray_LONG: + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_INT, 0, 0); + break; +#else /* NumPy */ + case PyArray_BOOL: + case PyArray_INT8: + case PyArray_UINT8: + case PyArray_INT16: + case PyArray_UINT16: + case PyArray_INT32: + case PyArray_UINT32: +#if PyArray_INT==PyArray_INT64 /* 64 bit platform */ + case PyArray_INT64: + case PyArray_UINT64: +#else + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_INT, 0, 0); + break; +#endif +#endif + + /**************************************************/ + /* All floats (and over-sized integers) to double */ + /**************************************************/ +#if WITH_NUMERIC==1 /* Numeric */ + case PyArray_FLOAT: + case PyArray_DOUBLE: +#else /* NumPy */ + case PyArray_FLOAT32: + case PyArray_FLOAT64: +#if PyArray_INT!=PyArray_INT64 /* 32 bit platform */ + case PyArray_INT64: + case PyArray_UINT64: +#endif +#endif + obj = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)obj, + PyArray_DOUBLE, 0, 0); + break; + + default: + UNPROTECT(2); + PyErr_Format(RPy_TypeConversionException, + "Numeric/NumPy arrays containing %s are not supported.", + obj->ob_type->tp_name); + return R_NilValue; + break; + } + + + pytl = Py_BuildValue("[i]", size); + nobj = PyArray_Reshape(obj, pytl); + Py_XDECREF(pytl); + Py_XDECREF(obj); + + if (nobj == NULL) + { + UNPROTECT(2); + return R_NilValue; + } + + + PROTECT(Rarray = seq_to_R(nobj)); + if (Rarray == NULL) + { + UNPROTECT(3); + return R_NilValue; + } + + + Py_XDECREF(nobj); + SET_DIM(Rarray, Rdims); + + PROTECT(e = allocVector(LANGSXP, 3)); + SETCAR(e, aperm); + SETCAR(CDR(e), Rarray); + SETCAR(CDR(CDR(e)), tRdims); + PROTECT(Rarray = do_eval_expr(e)); + + UNPROTECT(5); + return Rarray; +} +#endif + +/* Convert a Python object to a R object. An Robj is passed w/o + * modifications, an object which provides a '.as_r()' method, is + * passed as the result of that method */ +SEXP +to_Robj(PyObject *obj) +{ + SEXP robj; + Py_complex c; + PyObject *to_r_meth; + PyObject *tempObj; + int do_decref = 0; + + if (obj==NULL) + return NULL; + + if (obj == Py_None) { + return R_NilValue; + } + + to_r_meth = PyObject_GetAttrString(obj, "as_r"); + if (to_r_meth) { + obj = PyObject_CallObject(to_r_meth, NULL); + Py_DECREF(to_r_meth); + if (obj==NULL) + return NULL; + do_decref = 1; + } + PyErr_Clear(); + + + if (Robj_Check(obj)) + { + PROTECT(robj = ((RobjObject *)obj)->R_obj); + } + else if (PyBool_Check(obj)) + { + PROTECT(robj = NEW_LOGICAL(1)); + LOGICAL_DATA(robj)[0] = (Py_True==obj); + } + else if (PyInt_Check(obj)) + { + PROTECT(robj = NEW_INTEGER(1)); + INTEGER_DATA(robj)[0] = (int) PyInt_AsLong(obj); + } + else if (PyFloat_Check(obj)) + { + PROTECT(robj = NEW_NUMERIC(1)); + NUMERIC_DATA(robj)[0] = PyFloat_AsDouble(obj); + } + else if (PyComplex_Check(obj)) + { + PROTECT(robj = NEW_COMPLEX(1)); + c = PyComplex_AsCComplex(obj); + COMPLEX_DATA(robj)[0].r = c.real; + COMPLEX_DATA(robj)[0].i = c.imag; + } + else if (PyUnicode_Check(obj)) + { + /** Handle Unicode Strings. + * + * Ideally: Python Unicode -> R Unicode, + * + * Unfortunately, the R documentation is not forthcoming on how + * to accomplish this + * + * So, for the moment: + * python Unicode -> Python ASCII -> ordinary string -> R string + * + */ + PROTECT(robj = NEW_STRING(1)); + SET_STRING_ELT(robj, 0, COPY_TO_USER_STRING(PyString_AsString(PyUnicode_AsASCIIString(obj)))); + } + else if (PyString_Check(obj)) + { + PROTECT(robj = NEW_STRING(1)); + SET_STRING_ELT(robj, 0, COPY_TO_USER_STRING(PyString_AsString(obj))); + } +#ifdef WITH_NUMERIC + else if (use_numeric && PyArray_Check(obj)) + { + PROTECT(robj = to_Rarray(obj)); + } +#endif + else if ((PySequence_Check(obj)) && + (PySequence_Size(obj) >= 0)) + { + PROTECT(robj = seq_to_R(obj)); /* No labels */ + } + else if ((PyMapping_Check(obj)) && + (PyMapping_Size(obj) >= 0)) + { + PROTECT(robj = dict_to_R(obj)); + } + else if (PyNumber_Check(obj)) /* generic number interface */ + { + tempObj = PyNumber_Float(obj); + if(!tempObj) goto error; + + PROTECT(robj = NEW_NUMERIC(1)); + NUMERIC_DATA(robj)[0] = PyFloat_AsDouble(tempObj); + Py_DECREF(tempObj); + } + else + { + error: + PyErr_Format(RPy_TypeConversionException, + "cannot convert from type '%s'", + obj->ob_type->tp_name); + PROTECT(robj = NULL); /* Protected to avoid stack inbalance */ + } + + if (do_decref) + { + Py_DECREF(obj); + } + UNPROTECT(1); + return robj; +} + +/* Convert a R named vector or list to a Python dictionary */ +static PyObject * +to_PyDict(PyObject *obj, SEXP names) +{ + int len, i; + PyObject *it, *dict; + const char *name; + + if ((len = PySequence_Length(obj)) < 0) + return NULL; + + dict = PyDict_New(); + for (i=0; i 1) && (res[l-1] == '_') && (res[l-2] != '_')) + res[l-1]=0; + + while ((r=strchr(r, '_'))) + *r = '.'; + + return res; +} + +/* Convert a dict to keywords arguments for a R function */ +int +make_kwds(int lkwds, PyObject *kwds, SEXP *e) +{ + SEXP r; + const char *s; + int i; + PyObject *citems=NULL, *it; + PyObject *kwname; + + if (kwds) { + citems = PyMapping_Items(kwds); + } + + for (i=0; iR_obj); + e = CDR(e); + + if (!make_args(largs, args, &e)) { + UNPROTECT(1); + return NULL; + } + if (!make_kwds(lkwds, kwds, &e)) { + UNPROTECT(1); + return NULL; + } + + PROTECT(res = do_eval_expr(exp)); + if (!res) { + UNPROTECT(2); + return NULL; + } + + if (default_mode < 0) + conv = ((RobjObject *)self)->conversion; + else + conv = default_mode; + + obj = to_Pyobj_with_mode(res, conv); + UNPROTECT(2); + + //PrintWarnings(); /* show any warning messages */ + + return obj; +} + +/* Convert a sequence of (name, value) pairs to arguments to an R + function call */ +int +make_argl(int largl, PyObject *argl, SEXP *e) +{ + SEXP rvalue; + const char *name; + int i; + PyObject *it, *nobj, *value; + + if( !PySequence_Check(argl) ) goto fail_arg; + + for (i=0; i0) + { + SET_TAG(*e, Rf_install(name)); + PyMem_Free((void*) name); + } + + /* Move index to new end of call */ + *e = CDR(*e); + } + return 1; + + fail_arg: + PyErr_SetString(PyExc_ValueError, + "Argument must be a sequence of (\"name\", value) pairs.\n"); + fail: + return 0; +} + +/* Methods for the 'Robj' type */ + +/* Explicitly call an R object with a list containing (name, value) * + * argument pairs. 'name' can be None or '' to provide unnamed + * arguments. This function is necessary when the *order* of named + * arguments needs to be preserved. + */ + +static PyObject * +Robj_lcall(PyObject *self, PyObject *args) +{ + SEXP exp, e, res; + int largs, largl, conv; + PyObject *obj, *argl; + + /* Check arguments, there should be *exactly one* unnamed sequence. */ + largs = 0; + if (args) + largs = PyObject_Length(args); + if (largs<0) + return NULL; + + if(largs != 1 || !PySequence_Check(args) ) + { + PyErr_SetString(PyExc_ValueError, + "Argument must be a sequence of (\"name\", value) pairs.\n"); + return NULL; + } + + // extract our one argument + argl = PySequence_GetItem(args, 0); + Py_DECREF(args); + + largl = 0; + if (argl) + largl = PyObject_Length(argl); + if (largl<0) + return NULL; + + // A SEXP with the function to call and the arguments + PROTECT(exp = allocVector(LANGSXP, largl+1)); + e = exp; + SETCAR(e, ((RobjObject *)self)->R_obj); + e = CDR(e); + + // Add the arguments to the SEXP + if (!make_argl(largl, argl, &e)) { + UNPROTECT(1); + return NULL; + } + + // Evaluate + PROTECT(res = do_eval_expr(exp)); + if (!res) { + UNPROTECT(2); + return NULL; + } + + // Convert + if (default_mode < 0) + conv = ((RobjObject *)self)->conversion; + else + conv = default_mode; + + obj = to_Pyobj_with_mode(res, conv); + UNPROTECT(2); + + // Return + return obj; +} + + +/* Without args return the value of the conversion flag. With an + argument set the conversion flag to the truth value of the argument. */ +static PyObject * +Robj_autoconvert(PyObject *self, PyObject *args, PyObject *kwds) +{ + PyObject *obj; + int conversion=-2; + char *kwlist[] = {"val", 0}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:autoconvert", kwlist, + &conversion)) + return NULL; + + if (conversion > TOP_MODE) { + PyErr_SetString(PyExc_ValueError, "wrong mode"); + return NULL; + } + + if (conversion == -2) { + obj = PyInt_FromLong((long)((RobjObject *)self)->conversion); + } else { + ((RobjObject *)self)->conversion = conversion; + obj = Py_None; + Py_XINCREF(obj); + } + + return obj; +} + +static PyObject * +Robj_as_py(PyObject *self, PyObject *args, PyObject *kwds) +{ + PyObject *obj; + char *kwlist[] = {"mode", 0}; + int conv=default_mode; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:as_py", kwlist, + &conv)) + return NULL; + + if (conv <= -2 || conv > TOP_MODE) { + PyErr_SetString(PyExc_ValueError, "wrong mode"); + return NULL; + } + + if (conv < 0) + conv = TOP_MODE; + + obj = to_Pyobj_with_mode(((RobjObject *)self)->R_obj, conv); + return obj; +} + +static PyMethodDef Robj_methods[] = { + {"autoconvert", (PyCFunction)Robj_autoconvert, METH_VARARGS|METH_KEYWORDS}, + {"local_mode", (PyCFunction)Robj_autoconvert, METH_VARARGS|METH_KEYWORDS}, + {"as_py", (PyCFunction)Robj_as_py, METH_VARARGS|METH_KEYWORDS}, + {"lcall", (PyCFunction)Robj_lcall, METH_VARARGS}, + {NULL, NULL} /* sentinel */ +}; + +/* Sequence protocol implementation */ + +/* len(a) */ +static int +Robj_len(PyObject *a) +{ + SEXP e, robj; + + PROTECT(e = allocVector(LANGSXP, 2)); + SETCAR(e, length); + SETCAR(CDR(e), ((RobjObject *)a)->R_obj); + + if (!(robj = do_eval_expr(e))) { + UNPROTECT(1); + return -1; + } + + UNPROTECT(1); + return INTEGER_DATA(robj)[0]; +} + +/* a[i] = v */ +static int +Robj_ass_item(PyObject *a, int i, PyObject *v) +{ + SEXP e, ri, robj; + + PROTECT(e = allocVector(LANGSXP, 4)); + ri = NEW_INTEGER(1); + INTEGER_DATA(ri)[0] = i+1; + SETCAR(e, set_item); + SETCAR(CDR(e), ((RobjObject *)a)->R_obj); + SETCAR(CDR(CDR(e)), ri); + SETCAR(CDR(CDR(CDR(e))), to_Robj(v)); + + if(PyErr_Occurred()) + return -1; + + if (!(robj = do_eval_expr(e))) { + UNPROTECT(1); + return -1; + } + + ((RobjObject *)a)->R_obj = robj; + UNPROTECT(1); + return 0; +} + +/* a[i] */ +static PyObject * +Robj_item(PyObject *a, int i) +{ + SEXP ri, robj, e; + PyObject *obj; + int len, c; + + if ((len = Robj_len(a)) < 0) + return NULL; + if (i >= len || i < 0) { + PyErr_SetString(PyExc_IndexError, "R object index out of range"); + return NULL; + } + + PROTECT(ri = NEW_INTEGER(1)); + INTEGER_DATA(ri)[0] = i+1; + PROTECT(e = allocVector(LANGSXP, 3)); + SETCAR(e, get_item); + SETCAR(CDR(e), ((RobjObject *)a)->R_obj); + SETCAR(CDR(CDR(e)), ri); + + if (!(robj = do_eval_expr(e))) { + UNPROTECT(2); + return NULL; + } + + UNPROTECT(2); + + /* If there is a default mode, use it; otherwise, use the top mode. */ + if (default_mode < 0) + c = TOP_MODE; + else + c = default_mode; + obj = to_Pyobj_with_mode(robj, c); + return obj; +} + +/* Get a slice: a[x:y] */ +/*FIXME: starting with Python 2.5, ilow and ihigh should probably + * be of type Py_ssize_t. + */ +static PyObject * +Robj_slice(PyObject *a, int ilow, int ihigh) +{ + SEXP robj, e, index; + PyObject *obj; + int robjLen, sliceLen, c; + int ii; + + robjLen = Robj_len(a); + + if (robjLen < 0) + return NULL; + + if (ilow < 0) { + PyErr_SetString(PyExc_IndexError, + "R object index out of range (lowest index is negative)"); + return NULL; + //ilow = 0; + } else if (ilow > robjLen) { + PyErr_SetString(PyExc_IndexError, + "R object index out of range (lowest index > object length)"); + return NULL; + //ilow = robjLen; + } + if (ihigh < ilow) { + PyErr_SetString(PyExc_IndexError, + "R object index out of range (highest index < lowest index)"); + return NULL; + //ihigh = ilow; + } else if (ihigh > robjLen) { + PyErr_SetString(PyExc_IndexError, + "R object index out of range (highest index > object length)"); + //return NULL; + ihigh = robjLen; + } + sliceLen = ihigh - ilow; + + /* if (ilow >= robjLen || ilow < 0) { */ + /* PyErr_SetString(PyExc_IndexError, "R object index out of range"); */ + /* return NULL; */ + /* } */ + + PROTECT(index = allocVector(INTSXP, sliceLen)); + + for (ii = 0; ii < sliceLen; ii++) { + INTEGER_POINTER(index)[ii] = ii + ilow + 1; + } + + PROTECT(e = allocVector(LANGSXP, 3)); + SETCAR(e, get_item); + SETCAR(CDR(e), ((RobjObject *)a)->R_obj); + SETCAR(CDR(CDR(e)), index); + + if (!(robj = do_eval_expr(e))) { + UNPROTECT(2); + return NULL; + } + + UNPROTECT(2); + + /* If there is a default mode, use it; otherwise, use the top mode. */ + if (default_mode < 0) + c = TOP_MODE; + else + c = default_mode; + obj = to_Pyobj_with_mode(robj, c); + return obj; +} + + +/* FIXME: + * Python 2.5 will feel happier with ssizeargfunc and ssizessizeargfunc + */ +/* We should implement sq_slice, sq_contains ... */ +static PySequenceMethods Robj_as_sequence = { + (inquiry)Robj_len, /* sq_length */ + 0, /* sq_concat */ + 0, /* sq_repeat */ + (intargfunc)Robj_item, /* sq_item */ + (intintargfunc)Robj_slice, /* sq_slice */ + (intobjargproc)Robj_ass_item, /* sq_ass_item */ + 0, /* sq_ass_slice */ + 0, /* sq_contains */ + 0, /* sq_inplace_concat */ + 0 /* sq_inplace_repeat */ +}; + + +/* The 'Robj' table. When compiled under Python 2.2, the type 'Robj' + is subclassable. */ + +#ifdef PRE_2_2 +static PyObject * +Robj_getattr(RobjObject *self, char *name) +{ + return Py_FindMethod(Robj_methods, (PyObject *)self, name); +} +#endif + +PyTypeObject Robj_Type = { + /* The ob_type field must be initialized in the module init function + * to be portable to Windows without using C++. */ +#if defined(PRE_2_2) || defined(_WIN32) // Matjaz + PyObject_HEAD_INIT(NULL) +#else + PyObject_HEAD_INIT(&PyType_Type) +#endif + 0, /*ob_size*/ + "Robj", /*tp_name*/ + sizeof(RobjObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)Robj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ +#ifdef PRE_2_2 + (getattrfunc)Robj_getattr, +#else + 0, +#endif + 0, + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &Robj_as_sequence, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + (ternaryfunc)Robj_call, /*tp_call*/ + 0, /*tp_str*/ +#if defined(PRE_2_2) || defined(_WIN32) + 0, +#else + PyObject_GenericGetAttr, /*tp_getattro*/ +#endif + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ +#ifdef PRE_2_2 + 0, +#else + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#endif + 0, /*tp_doc*/ + 0, /*tp_traverse*/ +#ifndef PRE_2_2 + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + Robj_methods, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ +#ifdef _WIN32 + 0, /*tp_alloc*/ +#else + PyType_GenericAlloc, /*tp_alloc*/ +#endif + Robj_tpnew, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ +#endif +}; + + +/* Module functions */ + +/* Obtain an R object via its name. 'autoconvert' is the keyword to + set the autoconversion flag. */ +static PyObject * +get_fun(PyObject *self, PyObject *args, PyObject *kwds) +{ + char *obj_str; + int conversion=TOP_MODE; + SEXP robj; + + static char *kwlist[] = {"name", "autoconvert", 0}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i:get", kwlist, + &obj_str, &conversion)) + return NULL; + + robj = get_fun_from_name(obj_str); + if (!robj) + return NULL; + + return (PyObject *)Robj_new(robj, conversion); +} + +static PyObject * +set_mode(PyObject *self, PyObject *args) +{ + int i=-1; + + if (!PyArg_ParseTuple(args, "i:set_mode", &i)) + return NULL; + + if (i<-1 || i>TOP_MODE) { + PyErr_SetString(PyExc_ValueError, "wrong mode"); + return NULL; + } + + default_mode = i; + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +get_mode(PyObject *self, PyObject *args) +{ + if (!PyArg_ParseTuple(args, ":get_mode")) + return NULL; + + return PyInt_FromLong(default_mode); +} + +static PyObject * +r_events(PyObject *self, PyObject *args, PyObject *kwds) +#ifdef _WIN32 +{ + return NULL; +} +#else +{ + fd_set *what; + int usec=10000; + + static char *kwlist[] = {"usec", 0}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:r_events", + kwlist, &usec)) + return NULL; + + if (R_interact) { + Py_BEGIN_ALLOW_THREADS + what = R_checkActivity(usec, 0); + R_runHandlers(R_InputHandlers, what); + Py_END_ALLOW_THREADS + } + + Py_INCREF(Py_None); + return Py_None; +} +#endif + +void +stop_events(void) +{ + PyObject *o; + + if (!rpy_dict) + return; + + if (!r_lock) + r_lock = PyDict_GetItemString(rpy_dict, "_r_lock"); + + o = PyObject_CallMethod(r_lock, "acquire", NULL); + Py_XDECREF(o); +} + +void +start_events(void) +{ + PyObject *o; + + if (!rpy_dict) + return; + + if (!r_lock) + r_lock = PyDict_GetItemString(rpy_dict, "_r_lock"); + + o = PyObject_CallMethod(r_lock, "release", NULL); + Py_XDECREF(o); +} + + +/* + * Based on code from Rstd_CleanUp(); + * from src/unix/sys-std.c + */ + +void r_finalize(void) +{ +#if (R_VERSION < R_Version(2,4,0)) + unsigned char buf[1024]; + char * tmpdir; +#endif + + R_dot_Last(); + R_RunExitFinalizers(); + CleanEd(); +#if (R_VERSION >= R_Version(2,7,0)) + Rf_KillAllDevices(); +#else + KillAllDevices(); +#endif + +#if (R_VERSION >= R_Version(2,4,0)) + R_CleanTempDir(); +#else + if((tmpdir = getenv("R_SESSION_TMPDIR"))) { + +# ifdef _WIN32 + snprintf((char *)buf, 1024, "rmdir /S /Q %s", tmpdir); +# else + snprintf((char *)buf, 1024, "rm -rf %s", tmpdir); +# endif + + R_system((char *)buf); + } +#endif + + //PrintWarnings(); /* from device close and .Last */ + R_gc(); /* Remove any remaining R objects from memory */ +} + + +static PyObject * +r_cleanup(void) +{ + r_finalize(); + Py_INCREF(Py_None); + return Py_None; +} + +#ifdef WITH_NUMERIC +static void +init_numeric(void) +{ + PyObject *multiarray, *dict; + + if(use_numeric) + { + import_array(); + multiarray = PyImport_ImportModule(PY_ARRAY_MODULE_NAME); + if (multiarray) { + dict = PyModule_GetDict(multiarray); + if (dict) + Py_transpose = PyDict_GetItemString(dict, "transpose"); + } + } +} +#endif + +static PyObject * +r_init(PyObject *self, PyObject *args) +{ + static int first=1; + int i; + + if (!PyArg_ParseTuple(args, "i:r_init", &i)) + return NULL; + use_numeric = i; + +#ifdef WITH_NUMERIC + if(use_numeric) + init_numeric(); +#endif + + if(first==1) + { + first=0; + Py_INCREF(Py_None); + return Py_None; + } + else + { + PyErr_SetString(PyExc_RuntimeError, "Only one R object may be instantiated per session"); + return NULL; + } +} + +/* List of functions defined in the module */ +static PyMethodDef rpy_methods[] = { + {"get_fun", (PyCFunction)get_fun, METH_VARARGS | METH_KEYWORDS}, + {"set_mode", (PyCFunction)set_mode, METH_VARARGS}, + {"get_mode", (PyCFunction)get_mode, METH_VARARGS}, + {"set_output", (PyCFunction)set_output, METH_VARARGS}, + {"set_input", (PyCFunction)set_input, METH_VARARGS}, + {"set_showfiles", (PyCFunction)set_showfiles, METH_VARARGS}, + {"get_output", (PyCFunction)get_output, METH_VARARGS}, + {"get_input", (PyCFunction)get_input, METH_VARARGS}, + {"get_showfiles", (PyCFunction)get_showfiles, METH_VARARGS}, + {"r_events", (PyCFunction)r_events, METH_VARARGS | METH_KEYWORDS}, + {"r_cleanup", (PyCFunction)r_cleanup, METH_NOARGS}, + {"r_init", (PyCFunction)r_init, METH_VARARGS}, + {NULL, NULL} /* sentinel */ +}; + +#ifdef _WIN32 +static void char_message( char *s ) +{ + if (!s) return; + R_WriteConsole(s, strlen(s)); +} + +static int char_yesnocancel( char *s ) +{ + return 1; +} + +static void +RPyBusy( int which ) +{ + /* set a busy cursor ... in which = 1, unset if which = 0 */ +} + +static void +RPyDoNothing( void ) +{ +} + +/* initialise embedded R; based on rproxy_impl.c from the R distribution */ +static void +init_embedded_win32(int argc, + char *argv[]) +{ + structRstart rp; + Rstart Rp = &rp; + char Rversion[25]; + int index; + + + snprintf( Rversion, 25, "%s.%s", R_MAJOR, R_MINOR ); + if( strcmp( getDLLVersion(), Rversion ) != 0 ) { + PyErr_SetString( PyExc_ImportError, "R.DLL version does not match" ); + return; + } + + R_DefParams(Rp); + + /* set R_HOME */ + Rp->rhome = RHOME; + + index = strlen(RUSER) - 1; + + if (RUSER[index] == '/' || RUSER[index] == '\\') + RUSER[index] = '\0'; + + Rp->home = RUSER; + Rp->CharacterMode = LinkDLL; + + Rp->ReadConsole = (blah1) RPy_ReadConsole; // Matjaz + Rp->WriteConsole = (blah2) RPy_WriteConsole; // Matjaz + + Rp->CallBack = (blah3) RPyDoNothing; +#if R_VERSION < 0x20100 + Rp->message = char_message; + Rp->yesnocancel = char_yesnocancel; + Rp->busy = RPyBusy; +#else + Rp->ShowMessage = char_message; + Rp->YesNoCancel = char_yesnocancel; + Rp->Busy = RPyBusy; +#endif + + Rp->R_Quiet = TRUE; + + /* run as "interactive", so server won't be killed after an error */ + Rp->R_Slave = Rp->R_Verbose = 0; + Rp->R_Interactive = TRUE; + Rp->RestoreAction = SA_NORESTORE; /* no restore */ + Rp->SaveAction = SA_NOSAVE; /* no save */ + +#if R_VERSION < 0x20000 // pre-R-2.0.0 + + Rp->CommandLineArgs = NULL; + Rp->NumCommandLineArgs = 0; +#else + R_set_command_line_arguments(argc, argv); +#endif + R_SetParams(Rp); /* so R_ShowMessage is set */ + R_SizeFromEnv(Rp); + + R_SetParams(Rp); + + setup_term_ui(); + setup_Rmainloop(); +} +#endif + +/* Initialization function for the module */ +DL_EXPORT(void) +INIT_RPY(void) +{ + PyObject *m, *d; + PyOS_sighandler_t old_int; +#ifndef _WIN32 + PyOS_sighandler_t old_usr1, old_usr2; +#endif + SEXP interact; + + /* Get path and version information from environment */ + strncpy(RHOME, getenv("RPY_RHOME"), BUFSIZ); + strncpy(RVERSION, getenv("RPY_RVERSION"), BUFSIZ); + strncpy(RVER, getenv("RPY_RVER"), BUFSIZ); + strncpy(RUSER, getenv("RPY_RUSER"), BUFSIZ); + + if( !strlen(RHOME) || !strlen(RVERSION) || !strlen(RVER) || !strlen(RUSER)) + { + PyErr_Format(RPy_Exception, + "Unable to load R path or version information"); + return; + } + + Robj_Type.ob_type = &PyType_Type; +#if defined( _WIN32 ) && ! defined( PRE_2_2 ) + Robj_Type.tp_getattro = PyObject_GenericGetAttr; + Robj_Type.tp_alloc = PyType_GenericAlloc; +#endif + + /* Initialize the module with its content */ + if (PyType_Ready(&Robj_Type) < 0) + return; + m = Py_InitModule3(xstr(RPY_SHNAME), + rpy_methods, + "Python interface to the R Programming Language"); + Py_INCREF(&Robj_Type); + PyModule_AddObject(m, Robj_Type.tp_name, + (PyObject *)&Robj_Type); + + d = PyModule_GetDict(m); + + /* Save this interpreter */ + PyEval_InitThreads(); + my_interp = PyThreadState_Get()->interp; + + /* Save the Python signal handlers. If R inserts its handlers, we + cannot return to the Python interpreter. */ + old_int = PyOS_getsig(SIGINT); + python_sigint = old_int; +#ifndef _WIN32 + old_usr1 = PyOS_getsig(SIGUSR1); + old_usr2 = PyOS_getsig(SIGUSR2); +#endif + +#ifdef _WIN32 + init_embedded_win32(defaultargc, + defaultargv); +#else + Rf_initEmbeddedR(defaultargc, + defaultargv); +#endif + + +#ifdef CSTACK_DEFNS + /* Disable C stack checking, which is incompatible with use as a + shared library. */ + R_CStackLimit = (uintptr_t)-1; +#endif + + /* Restore Python handlers */ + PyOS_setsig(SIGINT, old_int); +#ifndef _WIN32 + PyOS_setsig(SIGUSR1, old_usr1); + PyOS_setsig(SIGUSR2, old_usr2); +#endif + + /* Several new exceptions: */ + RPy_Exception = PyErr_NewException("rpy.RPy_Exception", NULL, NULL); + RPy_TypeConversionException = PyErr_NewException("rpy.RPy_TypeConversionException", RPy_Exception, NULL); + RPy_RException = PyErr_NewException("rpy.RPy_RException", RPy_Exception, NULL); + + if (!RPy_Exception || !RPy_TypeConversionException || !RPy_RException ) + { + PyErr_Format(RPy_Exception, "Unable create RPy exceptions"); + return; + } + + PyDict_SetItemString(d, "RPy_Exception", RPy_Exception); + PyDict_SetItemString(d, "RPy_TypeConversionException", RPy_TypeConversionException); + PyDict_SetItemString(d, "RPy_RException", RPy_RException); + + // The conversion table + class_table = PyDict_New(); + proc_table = PyDict_New(); + PyDict_SetItemString(d, "__class_table__", class_table); + PyDict_SetItemString(d, "__proc_table__", proc_table); + + // The globals R objects for the sequence protocol + get_item = get_fun_from_name("["); + set_item = get_fun_from_name("[<-"); + length = get_fun_from_name("length"); + + // Function to transpose arrays + aperm = get_fun_from_name("aperm"); + + // Initialize the list of protected objects + R_References = R_NilValue; + SET_SYMVALUE(install("R.References"), R_References); + + // Initialize the default mode + default_mode = -1; + + // Check whether R is interactive or no + interact = do_eval_fun("interactive"); + R_interact = INTEGER(interact)[0]; + + // I/O routines + init_io_routines(); + + rpy = PyImport_ImportModule("rpy"); + rpy_dict = PyModule_GetDict(rpy); + // r_lock = PyDict_GetItemString(rpy_dict, "_r_lock"); + // PyObject_Print(r_lock, stderr, Py_PRINT_RAW); + r_lock = NULL; + + if( Py_AtExit( r_finalize ) ) + { + fprintf(stderr, "Warning: Unable to set R finalizer."); + fflush(stderr); + } + + +} + + --- rpy-1.0.3.orig/tests/logit.r +++ rpy-1.0.3/tests/logit.r @@ -0,0 +1,78 @@ +glm.od <- +function(object, maxit = 30, verbose = TRUE) +{ + if (class(object)[1] != "glm") + stop("first argument must be a fitted model of class \"glm\" !") + class <- class(object) + if (!(family(object)$family == "binomial" & family(object)$link == "logit")) + stop("overdispersed model fitting available only for \nbinomial regression models with logit link function!") + + pearson.X2 <- function(x) sum(residuals(x, "pearson")^2) + + y <- object$model[,1] # observed proportion of success & failures + trials <- apply(y, 1, sum) # = object$prior.weights + X <- model.matrix(object) + p <- length(object$coefficients) + n <- dim(X)[[1]] + h <- lm.influence(object)$hat + X2 <- pearson.X2(object) + # initial estimate of dispersion parameter + phi <- (X2 - (n-p)) / sum((trials-1)*(1-h)) + if(phi <0){phi <- 0;} + w <- 1/(1+phi*(trials-1)) + if (verbose) + cat("\nBinomial overdispersed logit model fitting...\n") + # loop until Pearson X2 approx equal to 1 + i <- 0 + + while( (X2/(n-p)-1) > object$control$epsilon ) + { + i <- i + 1 + if (i > maxit) + { warning("algoritm not converged after ", i, " iterations!") + break } + else + if (verbose) cat("Iter. ", i, " phi:", format(phi), "\n") + # computes weights + w <- 1/(1+phi*(trials-1)) + # re-fit the model using update() evaluated in original model + # environment, usually R_GlobalEnv + disp.weights <<- w; object <<- object + object <- eval(expression(update(object, weights=disp.weights)), + envir = object$data) + + h <- lm.influence(object)$hat + X2 <- pearson.X2(object) + # current estimate of dispersion parameter + phi <- (X2 - sum(w*(1-h))) / sum(w*(trials-1)*(1-h)) + } + + if (verbose) + { cat("Converged after", i, "iterations. \n") + cat("Estimated dispersion parameter:", format(phi), "\n") + print(summary(object)) } + ##### Jun Lu + if (X2 < (n-p)){ + phi <- 0; + w <- 1; + } + #cat(c("w is ",w,"\n")); + #if(phi <0){phi <- 0;} + #w[w>1] <- 1; + #cat(c("w is ",w,"\n")); + ##### + object <- c(object, list(dispersion=phi, disp.weights=w)) + class(object) <- class + invisible(object) +} + + +logit.1fact <- function(lib.size, counts, gp.des){ + tmp <- counts + #if (sum(tmp)<5) next ; + #if(sum(tmp>0) <3) {tmp <- tmp+1;} + mod <- glm(cbind(tmp, lib.size-tmp) ~ gp.des, family=binomial(logit)); + mod.disp <- glm.od(mod,verbose=FALSE); + test <- summary(mod.disp)$coefficients[2,]; + return (list(zp = test)) +} --- rpy-1.0.3.orig/tests/table.txt +++ rpy-1.0.3/tests/table.txt @@ -0,0 +1,4 @@ +A B C D +X1 4 5 6 +X2 7 8 9 +X3 6.0 2 Foo