// formatPtr handles formatting of pointers by indirecting them as necessary.
483693
func (f *formatState) formatPtr(v reflect.Value) {
	// Display nil if top level pointer is nil.
	showTypes := f.fs.Flag('#')
	if v.IsNil() && (!showTypes || f.ignoreNextType) {
		f.fs.Write(nilAngleBytes)
		return
	}

	// Remove pointers at or below the current depth from map used to detect
	// circular refs.
	for k, depth := range f.pointers {
		if depth >= f.depth {
			delete(f.pointers, k)
		}
	}

	// Keep list of all dereferenced pointers to possibly show later.
	pointerChain := make([]uintptr, 0)

	// Figure out how many levels of indirection there are by derferencing
	// pointers and unpacking interfaces down the chain while detecting circular
	// references.
	nilFound := false
	cycleFound := false
	indirects := 0
	ve := v
	for ve.Kind() == reflect.Ptr {
		if ve.IsNil() {
			nilFound = true
			break
		}
		indirects++
		addr := ve.Pointer()
		pointerChain = append(pointerChain, addr)
		if pd, ok := f.pointers[addr]; ok && pd < f.depth {
			cycleFound = true
			indirects--
			break
		}
		f.pointers[addr] = f.depth

		ve = ve.Elem()
		if ve.Kind() == reflect.Interface {
			if ve.IsNil() {
				nilFound = true
				break
			}
			ve = ve.Elem()
		}
	}

	// Display type or indirection level depending on flags.
	if showTypes && !f.ignoreNextType {
		f.fs.Write(openParenBytes)
		f.fs.Write(bytes.Repeat(asteriskBytes, indirects))
		f.fs.Write([]byte(ve.Type().String()))
		f.fs.Write(closeParenBytes)
	} else {
		if nilFound || cycleFound {
			indirects += strings.Count(ve.Type().String(), "*")
		}
		f.fs.Write(openAngleBytes)
		f.fs.Write([]byte(strings.Repeat("*", indirects)))
		f.fs.Write(closeAngleBytes)
	}

	// Display pointer information depending on flags.
	if f.fs.Flag('+') && (len(pointerChain) > 0) {
		f.fs.Write(openParenBytes)
		for i, addr := range pointerChain {
			if i > 0 {
				f.fs.Write(pointerChainBytes)
			}
			printHexPtr(f.fs, addr)
		}
		f.fs.Write(closeParenBytes)
	}

	// Display dereferenced value.
	switch {
	case nilFound:
		f.fs.Write(nilAngleBytes)

	case cycleFound:
		f.fs.Write(circularShortBytes)

	default:
		f.ignoreNextType = true
		f.format(ve)
	}
}
883969
func IoR(t, nr, size uintptr) uintptr {
	return ioc(directionRead, t, nr, size)
}
1134756
func (n NullDateTime) Ptr() *DateTime {
	if n.Valid {
		v := n.DateTime
		return &v
	}
	return nil
}
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
}
894226
func makePtrDecoder(typ reflect.Type) (decoder, error) {
	etype := typ.Elem()
	etypeinfo, err := cachedTypeInfo1(etype, tags{})
	if err != nil {
		return nil, err
	}
	dec := func(s *Stream, val reflect.Value) (err error) {
		newval := val
		if val.IsNil() {
			newval = reflect.New(etype)
		}
		if err = etypeinfo.decoder(s, newval.Elem()); err == nil {
			val.Set(newval)
		}
		return err
	}
	return dec, nil
}
102259
func Eprintf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(os.Stderr, format, a...)
}
1212701
func RemovePtrFromValue(t interface{}) reflect.Value {
	var v reflect.Value
	if rv, isValue := t.(reflect.Value); isValue {
		v = rv
	} else {
		v = reflect.ValueOf(t)
	}
	for v.Type().Kind() == reflect.Ptr {
		v = v.Elem()
	}
	return v
}
132008
func (db *DirBlock) IndirectPtr(i int) (BlockInfo, Offset) {
	if !db.IsInd {
		panic("IndirectPtr called on a direct directory block")
	}
	iptr := db.IPtrs[i]
	off := StringOffset(iptr.Off)
	return iptr.BlockInfo, &off
}
285765
func NewIterator4RowPtr(li *List, ptrs []RowPtr) Iterator {
	return &iterator4RowPtr{li: li, ptrs: ptrs}
}
654554
func (cMgr *ConfigurationManager) handlePtr(rValue reflect.Value, tagName string) error {
	if rValue.IsNil() {
		ptrValue := reflect.New(rValue.Type().Elem())
		err := cMgr.unmarshal(ptrValue, getTagKey(tagName, doNotConsiderTag))
		if err != nil {
			return err
		}

		if rValue.CanSet() {
			rValue.Set(ptrValue)
		}
		return nil
	} else if rValue.Elem().Kind() == reflect.Ptr {
		ptrValue := rValue.Elem()
		err := cMgr.handlePtr(ptrValue, getTagKey(tagName, doNotConsiderTag))
		if err != nil {
			return err
		}
	}

	ptrValue := rValue.Elem()
	err := cMgr.unmarshal(ptrValue, getTagKey(tagName, doNotConsiderTag))
	if err != nil {
		return err
	}

	return nil
}
110169
func ListExportedFieldsPtrs(val interface{}, predicates ...ExportedPredicate) (
	fields []*reflect.StructField, valPtrs []interface{}) {

	rVal := reflect.Indirect(reflect.ValueOf(val))
	valPtrs = []interface{}{}
	fields = []*reflect.StructField{}

	for i := 0; i < rVal.NumField(); i++ {
		field := rVal.Field(i)
		structField := rVal.Type().Field(i)
		if !FieldExported(&structField, predicates...) {
			continue
		}

		switch field.Kind() {
		case reflect.Ptr, reflect.Interface:
			if field.IsNil() {
				p := reflect.New(field.Type().Elem())
				field.Set(p)
				valPtrs = append(valPtrs, p.Interface())
			} else {
				valPtrs = append(valPtrs, field.Interface())
			}
		case reflect.Slice, reflect.Chan, reflect.Map:
			if field.IsNil() {
				p := reflect.New(field.Type())
				field.Set(p.Elem())
				valPtrs = append(valPtrs, field.Addr().Interface())
			} else {
				valPtrs = append(valPtrs, field.Interface())
			}
		default:
			if field.CanAddr() {
				valPtrs = append(valPtrs, field.Addr().Interface())
			} else if field.IsValid() {
				valPtrs = append(valPtrs, field.Interface())
			} else {
				panic("invalid field")
			}
		}

		fields = append(fields, &structField)
	}

	return fields, valPtrs
}
1255418
func mPrintf(format, arg string) *C.char {
	cf := C.CString(format)
	defer C.free(unsafe.Pointer(cf))
	ca := C.CString(arg)
	defer C.free(unsafe.Pointer(ca))
	return C._sqlite3_mprintf(cf, ca)
}
1008630
func pprintAddr(listeners []net.Listener) []byte {
	var out bytes.Buffer
	for i, l := range listeners {
		if i != 0 {
			fmt.Fprint(&out, ", ")
		}
		fmt.Fprint(&out, l.Addr())
	}
	return out.Bytes()
}
691398
func NewStringPtr(val string) *string {
	ptrValue := new(string)
	*ptrValue = val
	return ptrValue
}
1152057
func (h *Hosts) ptr(zone string, ttl uint32, names []string) []dns.RR {
	answers := []dns.RR{}
	for _, n := range names {
		r := new(dns.PTR)
		r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypePTR,
			Class: dns.ClassINET, Ttl: ttl}
		r.Ptr = dns.Fqdn(n)
		answers = append(answers, r)
	}
	return answers
}
546732
func AllocStructPtrs(val reflect.Value) {
	switch val.Kind() {
	case reflect.Struct:
		for i := 0; i < val.Type().NumField(); i++ {
			field := val.Field(i)
			AllocStructPtrs(field)
		}
	case reflect.Ptr:
		v := MakeNewType(val.Type(), 0)
		//TODO: Make recursivy better, include val.Type == v.Type....
		if isRecursive(v) {
			//panic(fmt.Sprintf("struct %v have a field of the same type of this struct", NameOf(v.Type())))
			return
		}
		if val.Type() == v.Type() {
			return
		}
		AllocStructPtrs(v.Elem())
		if val.CanSet() {
			val.Set(v)
		}
	case reflect.Slice:
		v := MakeNewType(val.Type(), 0)
		elem := v.Type().Elem()
		if elem.Kind() == reflect.Ptr && elem.Elem() == v.Type() {
			return
		}
		if val.CanSet() {
			val.Set(v)
		}
	}
}
238611
func (bps *blockPutStateMemory) SaveOldPtr(
	_ context.Context, oldPtr data.BlockPointer) error {
	if bps.lastBlock == data.ZeroPtr {
		return errors.New("No blocks have been added")
	}
	bs, ok := bps.blockStates[bps.lastBlock]
	if !ok {
		return errors.Errorf("Last block %v doesn't exist", bps.lastBlock)
	}
	bs.oldPtr = oldPtr
	bps.blockStates[bps.lastBlock] = bs
	return nil
}