10 examples of 'golang pointer receiver' in Go

Every line of 'golang pointer receiver' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
100func (p Struct) Ptr(i uint16) (Ptr, error) {
101 if p.seg == nil || i >= p.size.PointerCount {
102 return Ptr{}, nil
103 }
104 return p.seg.readPtr(p.pointerAddress(i), p.depthLimit)
105}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

1575func (v Value) Pointer() uintptr {
1576 // TODO: deprecate
1577 k := v.kind()
1578 switch k {
1579 case Ptr:
1580 if v.typ.ptrdata == 0 {
1581 // Handle pointers to go:notinheap types directly,
1582 // so we never materialize such pointers as an
1583 // unsafe.Pointer. (Such pointers are always indirect.)
1584 // See issue 42076.
1585 return *(*uintptr)(v.ptr)
1586 }
1587 fallthrough
1588 case Chan, Map, UnsafePointer:
1589 return uintptr(v.pointer())
1590 case Func:
1591 if v.flag&flagMethod != 0 {
1592 // As the doc comment says, the returned pointer is an
1593 // underlying code pointer but not necessarily enough to
1594 // identify a single function uniquely. All method expressions
1595 // created via reflect have the same underlying code pointer,
1596 // so their Pointers are equal. The function used here must
1597 // match the one used in makeMethodValue.
1598 f := methodValueCall
1599 return **(**uintptr)(unsafe.Pointer(&f))
1600 }
1601 p := v.pointer()
1602 // Non-nil func value points at data block.
1603 // First word of data block is actual code.
1604 if p != nil {
1605 p = *(*unsafe.Pointer)(p)
1606 }
1607 return uintptr(p)
1608
1609 case Slice:
1610 return (*SliceHeader)(v.ptr).Data
1611 }
1612 panic(&ValueError{"reflect.Value.Pointer", v.kind()})
1613}
740func (g *genDeepCopy) doPointer(t *types.Type, sw *generator.SnippetWriter) {
741 sw.Do("if *in == nil { *out = nil } else {\n", t)
742 if hasDeepCopyMethod(t.Elem) {
743 sw.Do("*out = new($.Elem|raw$)\n", t)
744 sw.Do("**out = (*in).DeepCopy()\n", nil)
745 } else if t.Elem.IsAssignable() {
746 sw.Do("*out = new($.Elem|raw$)\n", t)
747 sw.Do("**out = **in", nil)
748 } else {
749 switch t.Elem.Kind {
750 case types.Map, types.Slice:
751 sw.Do("*out = new($.Elem|raw$)\n", t)
752 sw.Do("if **in != nil {\n", t)
753 sw.Do("in, out := *in, *out\n", nil)
754 g.generateFor(t.Elem, sw)
755 sw.Do("}\n", nil)
756 default:
757 sw.Do("*out = new($.Elem|raw$)\n", t)
758 sw.Do("(*in).DeepCopyInto(*out)\n", nil)
759 }
760 }
761 sw.Do("}", t)
762}
2766func (r *Reader) readBytesPointer(v reflect.Value) error {
2767 return r.readPointer(v, r.getBytes, r.setBytes)
2768}
13func getReceiver(v interface{}, target string) (reflect.Value, error) {
14 return getReceiverFromValue(reflect.ValueOf(v), target)
15}
132func (p *Process) ReadPtr(a Address) Address {
133 return Address(p.ReadUintptr(a))
134}
389func sockLenPointer(t *kernel.Task, addr usermem.Addr) string {
390 if addr == 0 {
391 return "null"
392 }
393 l, err := copySockLen(t, addr)
394 if err != nil {
395 return fmt.Sprintf("%#x {error reading length: %v}", addr, err)
396 }
397 return fmt.Sprintf("%#x {length=%v}", addr, l)
398}
1689func (v Value) SetPointer(x unsafe.Pointer) {
1690 v.mustBeAssignable()
1691 v.mustBe(UnsafePointer)
1692 *(*unsafe.Pointer)(v.ptr) = x
1693}
27func pointer(idx int) ptr {
28 if !(0 <= idx && int64(idx) < maxUint32) {
29 panic("index out of range")
30 }
31 return ptr(idx + 1)
32}
315func (w *walker) Pointer(v reflect.Value) error {
316 if _, ok := w.shallowCopiers[v.Type()]; ok {
317 // Shallow copy this value. Use the same logic as primitive, then
318 // return skip.
319 if err := w.Primitive(v); err != nil {
320 return err
321 }
322
323 return reflectwalk.SkipEntry
324 }
325
326 return nil
327}

Related snippets