From 6a73a96cbfbafda6e6dc35f935cd189f4057a2da Mon Sep 17 00:00:00 2001 From: Joseph Timothy Foley Date: Mon, 13 Mar 2017 23:42:36 +0000 Subject: [PATCH] swig/comedi.i: Fixed the "break backwards compatibility" The lines: %rename("%(strip:[COMEDI_])s", regextarget=1) "COMEDI_.*"; %rename("%(strip:[comedi_])s", regextarget=1) "comedi_.*"; caused errors on import due to _comedi function names not matching at import time. Stripping names is now completely done in the globals() modification at the end, which works properly. to indicate if the old names should be stripped or not. This makes the intent very clear in the generated comedi.py file. [Reformatted commit message -- Ian Abbott] --- swig/comedi.i | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/swig/comedi.i b/swig/comedi.i index 515ed0c..478331b 100644 --- a/swig/comedi.i +++ b/swig/comedi.i @@ -44,11 +44,6 @@ //#define SWIGPYTHONONLYSHORT #ifdef SWIGPYTHON -#ifdef SWIGPYTHONONLYSHORT -%rename("%(strip:[COMEDI_])s", regextarget=1) "COMEDI_.*"; -%rename("%(strip:[comedi_])s", regextarget=1) "comedi_.*"; -#endif - // These need to be explicitly written as unsigned ints %rename(CR_FLAGS_MASK) _CR_FLAGS_MASK; %rename(CR_INVERT) _CR_INVERT; @@ -118,19 +113,24 @@ unsigned int NI_AO_SCAN_BEGIN_SRC_RTSI(unsigned int rtsi_channel); %array_class(lsampl_t, lsampl_array); %array_class(comedi_insn, insn_array); -#ifndef SWIGPYTHONONLYSHORT +#ifdef SWIGPYTHONONLYSHORT %insert("python") %{ -# Add entries in module dictionary to strip comedi_/COMEDI_ prefix -import copy + delete_comedi_prefix = True + %} +#else +%insert("python") %{ + delete_comedi_prefix = False + %} +#endif + +%insert("python") %{ +# Add entries in module dictionary without comedi_/COMEDI_ prefix import re -myglobals = copy.copy(globals()) -# Copy dictionary before -for k,v in myglobals.items(): +for k,v in globals().copy().items(): if re.match('^comedi_', k, flags=re.IGNORECASE): globals()[k[7:]] = v - # uncommenting following line removes compatibility with old code using - # comedi_ prefix: - # globals().pop(k) -del re, k, v + if delete_comedi_prefix: + globals().pop(k) # Break backwards compatibility +del re, k, v, delete_comedi_prefix %} -#endif +