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

     1  /* go-interface-val-compare.c -- compare an interface to a value.
     2  
     3     Copyright 2009 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 two interface values.  Return 0 for equal, not zero for not
    12     equal (return value is like strcmp).  */
    13  
    14  intgo
    15  __go_interface_value_compare (
    16      struct __go_interface left,
    17      const struct __go_type_descriptor *right_descriptor,
    18      const void *val)
    19  {
    20    const struct __go_type_descriptor *left_descriptor;
    21  
    22    if (left.__methods == NULL)
    23      return 1;
    24    left_descriptor = left.__methods[0];
    25    if (!__go_type_descriptors_equal (left_descriptor, right_descriptor))
    26      return 1;
    27    if (__go_is_pointer_type (left_descriptor))
    28      return left.__object == val ? 0 : 1;
    29    if (!__go_call_equalfn (left_descriptor->__equalfn, left.__object, val,
    30  			  left_descriptor->__size))
    31      return 1;
    32    return 0;
    33  }