C ++ Name Mangling Library for Python

I would like to manipulate and deactivate C ++ function names in a Python program. Is there anything similar? I was looking for a watch, maybe I was lucky here ...

+6
source share
2 answers

Most likely you do not want to do this in Python. As an aside, you probably should not export malformed names from your DLLs, as this makes it difficult for anyone else to use the compiler.

If you need to use malformed names then just copy them into your Python code. If you are going to manipulate Python code, you need to:

  • Know the specific implementation rules for the compiler in question.
  • Specify a Python C ++ function signature for each function.

It seems unlikely to me that coding all of this in Python would be better than just hard coding the garbled names.

+3
source

If you want to expand the names, for example. for display, you can create a channel that runs the C ++ filter.

def demangle(names): args = ['c++filt'] args.extend(names) pipe = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) stdout, _ = pipe.communicate() demangled = stdout.split("\n") # Each line ends with a newline, so the final entry of the split output # will always be ''. assert len(demangled) == len(names)+1 return demangled[:-1] print demangle(['_ZNSt15basic_stringbufIcSt11char_traitsIcESaIcEE17_M_stringbuf_initESt13_Ios_Openmode', '_ZNSt15basic_stringbufIcSt11char_traitsIcESaIcEE6setbufEPci']) 

You can specify arguments for a C ++ filter if you need to use a specific demangling method.

Interlacing a name is much more complicated and probably impossible to do without knowing the definition of the types used.

+16
source

Source: https://habr.com/ru/post/891674/


All Articles