code: def wrap(func):
      
      @functools.wraps(func, assigned=('restype', 'argtypes'))
      def wrapped(*args):
          if len(args) != len(func.argtypes):
              logger.warn("{} {} not of same length",
                          args, func.argtypes)
  
          typed_args = []
          for (arg, argtype) in zip(args, func.argtypes):
              if argtype == c_char_p:
                  # create a string buffer for strings
                  typed_arg = create_string_buffer(arg)
              else:
                  # for other types, use the type to do the conversion
                  if hasattr(argtype, 'contents'):
                      # type is a pointer
                      typed_arg = argtype(argtype._type_(arg))
                  else:
                      typed_arg = argtype(arg)
              typed_args.append(typed_arg)
          result = func(*typed_args)
          if hasattr(result, 'contents'):
              return result.contents
          else:
              return result
      return wrapped
docs: Return wrapped function with type conversion and sanity checks.