Skip to content

Commit a051174

Browse files
committed
Sync Callcontext
1 parent 93f5c26 commit a051174

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/CallContext.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct CallContext {
5858
kIsCreator = 0x000002, // if method creates python-owned objects
5959
kIsConstructor = 0x000004, // if method is a C++ constructor
6060
kHaveImplicit = 0x000008, // indicate that implicit converters are available
61-
kAllowImplicit = 0x000010, // indicate that implicit coversions are allowed
61+
kAllowImplicit = 0x000010, // indicate that implicit conversions are allowed
6262
kNoImplicit = 0x000020, // disable implicit to prevent recursion
6363
kCallDirect = 0x000040, // call wrapped method directly, no inheritance
6464
kFromDescr = 0x000080, // initiated from a descriptor
@@ -154,6 +154,24 @@ inline bool UseStrictOwnership(CallContext* ctxt) {
154154
return CallContext::sMemoryPolicy == CallContext::kUseStrict;
155155
}
156156

157+
template<CallContext::ECallFlags F>
158+
class CallContextRAII {
159+
public:
160+
CallContextRAII(CallContext* ctxt) : fCtxt(ctxt) {
161+
fPrior = fCtxt->fFlags & F;
162+
fCtxt->fFlags |= F;
163+
}
164+
CallContextRAII(const CallContextRAII&) = delete;
165+
CallContextRAII& operator=(const CallContextRAII&) = delete;
166+
~CallContextRAII() {
167+
if (!fPrior) fCtxt->fFlags &= ~F;
168+
}
169+
170+
private:
171+
CallContext* fCtxt;
172+
bool fPrior;
173+
};
174+
157175
} // namespace CPyCppyy
158176

159177
#endif // !CPYCPPYY_CALLCONTEXT_H

0 commit comments

Comments
 (0)