Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: swig/Lib/python/pyopers.swg

Issue 553095: Checkin swig binaries for win, linux and Mac... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « swig/Lib/python/pyname_compat.i ('k') | swig/Lib/python/pyprimtypes.swg » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: swig/Lib/python/pyopers.swg
===================================================================
--- swig/Lib/python/pyopers.swg (revision 0)
+++ swig/Lib/python/pyopers.swg (revision 0)
@@ -0,0 +1,136 @@
+/* ------------------------------------------------------------
+ * Overloaded operator support
+ * ------------------------------------------------------------ */
+
+
+#ifdef __cplusplus
+
+#define %pybinoperator(pyname,oper) %rename(pyname) oper; %pythonmaybecall oper
+
+%pybinoperator(__add__, *::operator+);
+%pybinoperator(__pos__, *::operator+());
+%pybinoperator(__pos__, *::operator+() const);
+%pybinoperator(__sub__, *::operator-);
+%pybinoperator(__neg__, *::operator-());
+%pybinoperator(__neg__, *::operator-() const);
+%pybinoperator(__mul__, *::operator*);
+%pybinoperator(__div__, *::operator/);
+%pybinoperator(__mod__, *::operator%);
+%pybinoperator(__lshift__, *::operator<<);
+%pybinoperator(__rshift__, *::operator>>);
+%pybinoperator(__and__, *::operator&);
+%pybinoperator(__or__, *::operator|);
+%pybinoperator(__xor__, *::operator^);
+%pybinoperator(__lt__, *::operator<);
+%pybinoperator(__le__, *::operator<=);
+%pybinoperator(__gt__, *::operator>);
+%pybinoperator(__ge__, *::operator>=);
+%pybinoperator(__eq__, *::operator==);
+%pybinoperator(__ne__, *::operator!=);
+
+
+
+/* Special cases */
+%rename(__invert__) *::operator~;
+%rename(__call__) *::operator();
+
+%feature("shadow") *::operator bool %{
+def __nonzero__(self):
+ return $action(self)
+__bool__ = __nonzero__
+%};
+%rename(__nonzero__) *::operator bool;
+
+/* Ignored operators */
+%ignoreoperator(LNOT) operator!;
+%ignoreoperator(LAND) operator&&;
+%ignoreoperator(LOR) operator||;
+%ignoreoperator(EQ) *::operator=;
+%ignoreoperator(PLUSPLUS) *::operator++;
+%ignoreoperator(MINUSMINUS) *::operator--;
+%ignoreoperator(ARROWSTAR) *::operator->*;
+%ignoreoperator(INDEX) *::operator[];
+
+/*
+ Inplace operator declarations.
+
+ They translate the inplace C++ operators (+=, -=, ...) into the
+ corresponding python equivalents(__iadd__,__isub__), etc,
+ disabling the ownership of the input 'self' pointer, and assigning
+ it to the returning object:
+
+ %feature("del") *::Operator;
+ %feature("new") *::Operator;
+
+ This makes the most common case safe, ie:
+
+ A& A::operator+=(int i) { ...; return *this; }
+ ^^^^ ^^^^^^
+
+ will work fine, even when the resulting python object shares the
+ 'this' pointer with the input one. The input object is usually
+ deleted after the operation, including the shared 'this' pointer,
+ producing 'strange' seg faults, as reported by Lucriz
+ (lucriz@sitilandia.it).
+
+ If you have an interface that already takes care of that, ie, you
+ already are using inplace operators and you are not getting
+ seg. faults, with the new scheme you could end with 'free' elements
+ that never get deleted (maybe, not sure, it depends). But if that is
+ the case, you could recover the old behaviour using
+
+ %feature("del","") A::operator+=;
+ %feature("new","") A::operator+=;
+
+ which recovers the old behaviour for the class 'A', or if you are
+ 100% sure your entire system works fine in the old way, use:
+
+ %feature("del","") *::operator+=;
+ %feature("new","") *::operator+=;
+
+*/
+
+#define %pyinplaceoper(SwigPyOper, Oper) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
+
+%pyinplaceoper(__iadd__ , *::operator +=);
+%pyinplaceoper(__isub__ , *::operator -=);
+%pyinplaceoper(__imul__ , *::operator *=);
+%pyinplaceoper(__idiv__ , *::operator /=);
+%pyinplaceoper(__imod__ , *::operator %=);
+%pyinplaceoper(__iand__ , *::operator &=);
+%pyinplaceoper(__ior__ , *::operator |=);
+%pyinplaceoper(__ixor__ , *::operator ^=);
+%pyinplaceoper(__ilshift__, *::operator <<=);
+%pyinplaceoper(__irshift__, *::operator >>=);
+
+
+/* Finally, in python we need to mark the binary operations to fail as
+ 'maybecall' methods */
+
+#define %pybinopermaybecall(oper) %pythonmaybecall __ ## oper ## __; %pythonmaybecall __r ## oper ## __
+
+%pybinopermaybecall(add);
+%pybinopermaybecall(pos);
+%pybinopermaybecall(pos);
+%pybinopermaybecall(sub);
+%pybinopermaybecall(neg);
+%pybinopermaybecall(neg);
+%pybinopermaybecall(mul);
+%pybinopermaybecall(div);
+%pybinopermaybecall(mod);
+%pybinopermaybecall(lshift);
+%pybinopermaybecall(rshift);
+%pybinopermaybecall(and);
+%pybinopermaybecall(or);
+%pybinopermaybecall(xor);
+%pybinopermaybecall(lt);
+%pybinopermaybecall(le);
+%pybinopermaybecall(gt);
+%pybinopermaybecall(ge);
+%pybinopermaybecall(eq);
+%pybinopermaybecall(ne);
+
+#endif
+
+
+
« no previous file with comments | « swig/Lib/python/pyname_compat.i ('k') | swig/Lib/python/pyprimtypes.swg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698