// If an error is abad pointer error of any type, returns NotAPointerError
172716
func StandardizeBadPointerError(err error) error {
	if IsBadPointerKeyError(err) {
		badErr := err.(badPointerKeyError)
		if badErr.Expected == "version" {
			return NewNotAPointerError(err)
		}
	}
	return err
}
1351404
func NonEmptyReader(r io.Reader) (io.Reader, error) {
	pr, ok := r.(readPeeker)
	if !ok {
		pr = bufio.NewReader(r)
	}

	_, err := pr.Peek(1)
	if err == io.EOF {
		return nil, ErrEmptyReader
	}

	if err != nil {
		return nil, err
	}

	return pr, nil
}
69301
func encodeDBPointer(buf *bytes.Buffer, path, name string,
	val DBPointer) error {

	if len(val.ObjectId) != 12 {
		return fmt.Errorf("%v, DBPointer must be 12 bytes.", path)
	}

	// type
	if err := buf.WriteByte(_DBPOINTER); err != nil {
		return err
	}

	// name
	if err := writeCstring(buf, name); err != nil {
		return err
	}

	// Name
	if err := writeString(buf, val.Name); err != nil {
		return err
	}

	// ObjectId
	if _, err := buf.Write(val.ObjectId); err != nil {
		return err
	}

	return nil
}
268688
func validatePSPAllowedProcMountTypes(fldPath *field.Path, allowedProcMountTypes []core.ProcMountType) field.ErrorList {
	allErrs := field.ErrorList{}
	for i, procMountType := range allowedProcMountTypes {
		if err := apivalidation.ValidateProcMountType(fldPath.Index(i), procMountType); err != nil {
			allErrs = append(allErrs, err)
		}
	}
	return allErrs
}
968549
func (pm *pointerMap) addPointerReturnTrueIfWasReused(ptr uintptr) bool {
	// Is this allready known to be reused?
	for _, have := range pm.reusedPointers {
		if ptr == have {
			return true
		}
	}
	// Have we seen it once before?
	for _, seen := range pm.pointers {
		if ptr == seen {
			// Add it to the register of pointers we have seen more than once
			pm.reusedPointers = append(pm.reusedPointers, ptr)
			return true
		}
	}
	// This pointer was new to us
	pm.pointers = append(pm.pointers, ptr)
	return false
}
530247
func (l *LibHandle) GetSymbolPointer(symbol string) (unsafe.Pointer, error) {
	sym := C.CString(symbol)
	defer C.free(unsafe.Pointer(sym))

	C.dlerror()
	p := C.dlsym(l.Handle, sym)
	e := C.dlerror()
	if e != nil {
		return nil, fmt.Errorf("error resolving symbol %q: %v", symbol, errors.New(C.GoString(e)))
	}

	return p, nil
}
1048039
func toPointer(i *Message) pointer {
	// Super-tricky - read pointer out of data word of interface value.
	// Saves ~25ns over the equivalent:
	// return valToPointer(reflect.ValueOf(*i))
	return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
}
1083963
func EnforcePtr(obj interface{}) (reflect.Value, error) {
	v := reflect.ValueOf(obj)
	if v.Kind() != reflect.Ptr {
		if v.Kind() == reflect.Invalid {
			return reflect.Value{}, fmt.Errorf("expected pointer, but got invalid kind")
		}
		return reflect.Value{}, fmt.Errorf("expected pointer, but got %v type", v.Type())
	}
	if v.IsNil() {
		return reflect.Value{}, fmt.Errorf("expected pointer, but got nil")
	}
	return v.Elem(), nil
}
163954
func IsUnexpectedServerError(err error) bool {
	switch t := err.(type) {
	case APIStatus:
		if d := t.Status().Details; d != nil {
			for _, cause := range d.Causes {
				if cause.Type == metav1.CauseTypeUnexpectedServerResponse {
					return true
				}
			}
		}
	}
	return false
}
201905
func unPtrType(t reflect.Type) reflect.Type {
	if t.Kind() == reflect.Ptr {
		return t.Elem()
	}
	return t
}
316460
func (d DevicePtr) PtrAttribute(attr PointerAttribute) (unsafe.Pointer, error) {
	var p unsafe.Pointer
	devPtr := C.CUdeviceptr(d)
	a := C.CUpointer_attribute(attr)
	if err := result(C.cuPointerGetAttribute(p, a, devPtr)); err != nil {
		return nil, err
	}
	return p, nil
}
187502
func NubAppend(vs ...T) T {
	if len(vs) == 0 {
		return nil
	}

	rv := reflectSlice(vs[0])
	set := reflect.MakeMap(reflect.MapOf(rv.Type().Elem(), trueVal.Type()))
	out := reflect.MakeSlice(rv.Type(), 0, 0)

	for _, v := range vs {
		rv := reflectSlice(v)
		for i, l := 0, rv.Len(); i < l; i++ {
			x := rv.Index(i)
			if set.MapIndex(x).IsValid() {
				continue
			}
			set.SetMapIndex(x, trueVal)
			out = reflect.Append(out, x)
		}
	}

	return out.Interface()
}
912082
func IsUnexpectedError(err error) bool {
	return yarpcerrors.FromError(err).Code() == yarpcerrors.CodeInternal
}
134389
func LoopFromPoints(pts []Point) *Loop {
	l := &Loop{
		vertices: pts,
	}

	l.initOriginAndBound()
	return l
}
1083494
func (m *Model) AllEndpointBindings() ([]ApplicationEndpointBindings, error) {
	endpointBindings, closer := m.st.db().GetCollection(endpointBindingsC)
	defer closer()

	var docs []endpointBindingsDoc
	err := endpointBindings.Find(nil).All(&docs)
	if err != nil {
		return nil, errors.Annotatef(err, "cannot get endpoint bindings")
	}

	var appEndpointBindings []ApplicationEndpointBindings
	for _, doc := range docs {
		var applicationName string
		applicationKey := m.localID(doc.DocID)
		// for each application deployed we have an instance of ApplicationEndpointBindings struct
		if strings.HasPrefix(applicationKey, "a#") {
			applicationName = applicationKey[2:]
		} else {
			return nil, errors.NotValidf("application key %v", applicationKey)
		}
		endpointBindings := ApplicationEndpointBindings{
			AppName:  applicationName,
			Bindings: doc.Bindings,
		}

		appEndpointBindings = append(appEndpointBindings, endpointBindings)
	}
	return appEndpointBindings, nil
}
1286733
func (pm *pointerMap) addPointer(ptr uintptr) bool {
	// Is this already known to be reused?
	for _, have := range pm.reusedPointers {
		if ptr == have {
			return true
		}
	}
	// Have we seen it once before?
	for _, seen := range pm.allpointers {
		if ptr == seen {
			// Add it to the register of pointers we have seen more than once
			pm.reusedPointers = append(pm.reusedPointers, ptr)
			return true
		}
	}
	// This pointer was new to us
	pm.allpointers = append(pm.allpointers, ptr)
	return false
}
544427
func NewError(e error, p Position) Error {
	return &err{error: e, _position: p}
}