[C++-sig] Pyste bugs again

Nicodemus nicodemus at globalite.com.br
Sat Sep 20 01:12:43 CEST 2003


Hi Niall,

Niall Douglas wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>I hate to be a bore but the patches I submitted here last time have 
>not been implemented in the latest CVS version.
>  
>

No bore: bug reports and suggestions are welcome. 8)

>This means that quite simply pyste DOES NOT WORK on MSVC.
>
>Bug 1: Declaring an unnamed namespace in the pyste output causes 
>MSVC7.1 to gobble memory until infinity.
>
>My solution: Alter Save() in SingleCodeUnit.py:
>
>            if declaration:
>                pyste_namespace = namespaces.pyste[:-2]            
>                if pyste_namespace:
>                    fout.write('namespace %s {\n\n' % 
>pyste_namespace)
>                fout.write(declaration) 
>                if pyste_namespace:
>                    fout.write('\n}// namespace %s\n' % 
>pyste_namespace)
>                fout.write(space)
>
>This simply doesn't write out a namespace declaration if it's 
>unnamed.
>  
>

Sorry, but I replied to your message, and suggested that you try out the 
--pyste-ns option. So you could run pyste with --pyste-ns=pyste or 
something, and the namespace wouldn't be empty anymore. I believe that 
MSVC does support namespaces, right? ;)
If that doesn't work, I think your approach (not writing the 
declarations inside a namespace at all if no namespace is specified) is 
feasible.

>Bug 2: Unnamed enums are still being called "$_xx". MSVC does not 
>like symbols starting with $. Furthermore the export_values() 
>facility is still not being employed.
>
>My solution: Alter Export() in EnumExporter.py:
>
>    def Export(self, codeunit, exported_names):
>        if not self.info.exclude:
>            indent = self.INDENT
>            in_indent = self.INDENT*2
>            rename = self.info.rename or self.enum.name
>            full_name = self.enum.FullName()
>            if rename[0:2] == "$_" or rename == '._0':
>                global uniqueTypeCount
>                full_name = 'UniqueInt<%d>' % uniqueTypeCount
>                uniqueTypeCount+=1
>                rename = "unnamed"
>            code = indent + namespaces.python
>            code += 'enum_< %s >("%s")\n' % (full_name, rename)
>            for name in self.enum.values:         
>                rename = self.info[name].rename or name
>                value_fullname = self.enum.ValueFullName(name)
>                code += in_indent + '.value("%s", %s)\n' % (rename, 
>value_fullname)
>            code += in_indent + '.export_values();\n\n'
>            codeunit.Write('module', code)
>            exported_names[self.enum.FullName()] = 1
>  
>

I'm really sorry about that, this one passed through. I implemented it 
in CVS, but not verbatim as in here. First, only unnamed enums are 
exported with export_values() by default. If you want a normal enum to 
be exported, you have to call export_values on it:

color = Enum('color',...)
export_values(color)

The reason is that if we made it so that all enums were exported with 
export_values, then it would break code that expected the old behaviour. 
But I must say that I prefer enums with export_values, since they mirror 
better in Python the same semathics of enums in C++.

Thanks a lot for the feedback Niall!

Nicodemus.

Ps: I also implemented the change so that any \ will be translated to / 
before being passed to gccxml.





More information about the Cplusplus-sig mailing list