//AllocStructPtrs find pointers in a struct and alloc than recursivily.
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)
		}
	}
}
925607
func (db *DirBlock) SwapIndirectPtrs(i int, other BlockWithPtrs, otherI int) {
	otherDB, ok := other.(*DirBlock)
	if !ok {
		panic(fmt.Sprintf(
			"SwapIndirectPtrs cannot swap between block types: %T", other))
	}

	db.IPtrs[i], otherDB.IPtrs[otherI] = otherDB.IPtrs[otherI], db.IPtrs[i]
}
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
}
1227687
func (p *PostingsList) Iterator(includeFreq, includeNorm, includeLocs bool,
	prealloc segment.PostingsIterator) segment.PostingsIterator {
	if p.normBits1Hit == 0 && p.postings == nil {
		return emptyPostingsIterator
	}

	var preallocPI *PostingsIterator
	pi, ok := prealloc.(*PostingsIterator)
	if ok && pi != nil {
		preallocPI = pi
	}
	if preallocPI == emptyPostingsIterator {
		preallocPI = nil
	}

	return p.iterator(includeFreq, includeNorm, includeLocs, preallocPI)
}
1027797
func writePointer(bi *BinaryInfo, mem MemoryReadWriter, addr, val uint64) error {
	ptrbuf := make([]byte, bi.Arch.PtrSize())

	// TODO: use target architecture endianness instead of LittleEndian
	switch len(ptrbuf) {
	case 4:
		binary.LittleEndian.PutUint32(ptrbuf, uint32(val))
	case 8:
		binary.LittleEndian.PutUint64(ptrbuf, val)
	default:
		panic(fmt.Errorf("unsupported pointer size %d", len(ptrbuf)))
	}
	_, err := mem.WriteMemory(uintptr(addr), ptrbuf)
	return err
}
1243249
func (w *deploymentWatcher) getAllocs(index uint64) ([]*structs.AllocListStub, uint64, error) {
	resp, index, err := w.state.BlockingQuery(w.getAllocsImpl, index, w.ctx)
	if err != nil {
		return nil, 0, err
	}
	if err := w.ctx.Err(); err != nil {
		return nil, 0, err
	}

	return resp.([]*structs.AllocListStub), index, 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
}
55952
func (r Root) FindAll(args ...string) []Root {
	temp := findAllofem(r.Pointer, args, false)
	if len(temp) == 0 {
		if debug {
			panic("Element `" + args[0] + "` with attributes `" + strings.Join(args[1:], " ") + "` not found")
		}
		return []Root{}
	}
	pointers := make([]Root, 0, len(temp))
	for i := 0; i < len(temp); i++ {
		pointers = append(pointers, Root{temp[i], temp[i].Data, nil})
	}
	return pointers
}
1102468
func PtrShrinker(elementShrinker gopter.Shrinker) gopter.Shrinker {
	return func(v interface{}) gopter.Shrink {
		if v == nil {
			return gopter.NoShrink
		}
		elem := reflect.ValueOf(v).Elem()
		if !elem.IsValid() || !elem.CanInterface() {
			return gopter.NoShrink
		}
		rt := reflect.TypeOf(v)
		elementShink := elementShrinker(reflect.ValueOf(v).Elem().Interface())

		nilShrink := &nilShrink{}
		return gopter.ConcatShrinks(
			nilShrink.Next,
			elementShink.Map(func(elem interface{}) interface{} {
				slice := reflect.MakeSlice(reflect.SliceOf(rt.Elem()), 0, 1)
				slice = reflect.Append(slice, reflect.ValueOf(elem))

				return slice.Index(0).Addr().Interface()
			}),
		)
	}
}
340549
func ObjectsAll(iter ObjectIterator) (Objects, error) {
	objs := make(Objects, 0)
	for {
		o, err := iter.Next()
		if err == iterator.Done {
			break
		} else if err != nil {
			return nil, err
		}
		objs = append(objs, o)
	}
	return objs, nil
}
1004373
func FindByType(g Graph, listPtr interface{}) []reflect.Value {
	ptrType := reflect.TypeOf(listPtr)
	if ptrType.Kind() != reflect.Ptr {
		panic(fmt.Sprintf("listPtr (%v) is not a pointer", ptrType))
	}

	listType := ptrType.Elem()
	if listType.Kind() != reflect.Slice {
		panic(fmt.Sprintf("listPtr (%v) is not a pointer to a slice or array", ptrType))
	}

	listValue := reflect.ValueOf(listPtr).Elem()

	values := g.ResolveByType(listType.Elem())
	listValue = reflect.Append(listValue, values...)

	// update the listPtr value
	reflect.ValueOf(listPtr).Elem().Set(listValue)

	return values
}
222998
func (s *Service) NewPTR(name string, target string) *dns.PTR {
	return &dns.PTR{Hdr: dns.RR_Header{Name: name, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: s.TTL}, Ptr: dns.Fqdn(target)}
}
1055963
func (d *dumpState) dumpPtr(v reflect.Value) {
	// Remove pointers at or below the current depth from map used to detect
	// circular refs.
	for k, depth := range d.pointers {
		if depth >= d.depth {
			delete(d.pointers, k)
		}
	}

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

	// Figure out how many levels of indirection there are by dereferencing
	// 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 := d.pointers[addr]; ok && pd < d.depth {
			cycleFound = true
			indirects--
			break
		}
		d.pointers[addr] = d.depth

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

	// Display type information.
	d.w.Write(openParenBytes)
	d.w.Write(bytes.Repeat(asteriskBytes, indirects))
	d.w.Write([]byte(ve.Type().String()))
	d.w.Write(closeParenBytes)

	// Display pointer information.
	if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 {
		d.w.Write(openParenBytes)
		for i, addr := range pointerChain {
			if i > 0 {
				d.w.Write(pointerChainBytes)
			}
			printHexPtr(d.w, addr)
		}
		d.w.Write(closeParenBytes)
	}

	// Display dereferenced value.
	d.w.Write(openParenBytes)
	switch {
	case nilFound:
		d.w.Write(nilAngleBytes)

	case cycleFound:
		d.w.Write(circularBytes)

	default:
		d.ignoreNextType = true
		d.dump(ve)
	}
	d.w.Write(closeParenBytes)
}
6546
func int64ptr(i interface{}) *int64 {
	v := reflect.ValueOf(i)
	if !v.Type().ConvertibleTo(rTypeInt64) {
		return nil
	}
	j := v.Convert(rTypeInt64).Interface().(int64)
	return &j
}
1220647
func (s *HTTPServer) rpcHandlerForAlloc(allocID string) (localClient, remoteClient, server bool) {
	c := s.agent.Client()
	srv := s.agent.Server()

	// See if the local client can handle the request.
	localAlloc := false
	if c != nil {
		// If there is an error it means that the client doesn't have the
		// allocation so we can't use the local client
		_, err := c.GetAllocState(allocID)
		if err == nil {
			localAlloc = true
		}
	}

	// Only use the client RPC to server if we don't have a server and the local
	// client can't handle the call.
	useClientRPC := c != nil && !localAlloc && srv == nil

	// Use the server as a last case.
	useServerRPC := !localAlloc && !useClientRPC && srv != nil

	return localAlloc, useClientRPC, useServerRPC
}
1365651
func (n Nodeset) ToPointers() (pointers []unsafe.Pointer) {
	for _, node := range n {
		pointers = append(pointers, node.NodePtr())
	}
	return
}
1280230
func wrapPtr(v reflect.Value) reflect.Value {
	if !v.IsValid() {
		return v
	}
	vPtr := reflect.New(v.Type())
	vPtr.Elem().Set(v)
	return vPtr
}