github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/runtime/go-interface-eface-compare.c (about)

     1  /* go-interface-eface-compare.c -- compare non-empty and empty interface.
     2  
     3     Copyright 2011 The Go Authors. All rights reserved.
     4     Use of this source code is governed by a BSD-style
     5     license that can be found in the LICENSE file.  */
     6  
     7  #include "runtime.h"
     8  #include "go-type.h"
     9  #include "interface.h"
    10  
    11  /* Compare a non-empty interface value with an empty interface value.
    12     Return 0 for equal, not zero for not equal (return value is like
    13     strcmp).  */
    14  
    15  intgo
    16  __go_interface_empty_compare (struct __go_interface left,
    17  			      struct __go_empty_interface right)
    18  {
    19    const struct __go_type_descriptor *left_descriptor;
    20  
    21    if (left.__methods == NULL && right.__type_descriptor == NULL)
    22      return 0;
    23    if (left.__methods == NULL || right.__type_descriptor == NULL)
    24      return 1;
    25    left_descriptor = left.__methods[0];
    26    if (!__go_type_descriptors_equal (left_descriptor, right.__type_descriptor))
    27      return 1;
    28    if (__go_is_pointer_type (left_descriptor))
    29      return left.__object == right.__object ? 0 : 1;
    30    if (!__go_call_equalfn (left_descriptor->__equalfn, left.__object,
    31  			  right.__object, left_descriptor->__size))
    32      return 1;
    33    return 0;
    34  }