{"id":18806397,"url":"https://github.com/ansiwen/ptrguard","last_synced_at":"2025-04-13T19:12:48.649Z","repository":{"id":57615275,"uuid":"371174033","full_name":"ansiwen/ptrguard","owner":"ansiwen","description":"Go package for using Go pointers in external code","archived":false,"fork":false,"pushed_at":"2021-10-30T14:13:24.000Z","size":47,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T09:51:59.264Z","etag":null,"topics":["cgo","cgo-bindings","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ansiwen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-26T21:34:08.000Z","updated_at":"2024-08-28T10:24:03.000Z","dependencies_parsed_at":"2022-09-13T15:50:15.632Z","dependency_job_id":null,"html_url":"https://github.com/ansiwen/ptrguard","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansiwen%2Fptrguard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansiwen%2Fptrguard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansiwen%2Fptrguard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansiwen%2Fptrguard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ansiwen","download_url":"https://codeload.github.com/ansiwen/ptrguard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766745,"owners_count":21158301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cgo","cgo-bindings","go","golang"],"created_at":"2024-11-07T22:48:25.389Z","updated_at":"2025-04-13T19:12:48.627Z","avatar_url":"https://github.com/ansiwen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PtrGuard\n[![Build Status](https://github.com/ansiwen/ptrguard/actions/workflows/go.yml/badge.svg)](https://github.com/ansiwen/ptrguard/actions)\n[![Go Reference](https://pkg.go.dev/badge/github.com/ansiwen/ptrguard.svg)](https://pkg.go.dev/github.com/ansiwen/ptrguard)\n\nPtrGuard is a small Go package that allows to pin objects referenced by a Go\npointer (that is pointing to memory allocated by the Go runtime) so that it will\nnot be touched by the garbage collector. This is done by creating a `Pinner`\nobject that has a `Pin()` method, which accepts a pointer of any type and pins\nthe referenced object, until the `Unpin()` method of the same `Pinner` is\ncalled. A `Pinner` can be used to pin more than one object, in which case\n`Unpin()` releases all the pinned objects of a `Pinner`.\n\nGo pointers to pinned objects can either be directly stored in C memory with the\n`Store()` method, or are allowed to be contained in Go memory that is passed to\nC functions, which both usually violates the [pointer passing\nrules](https://golang.org/cmd/cgo/#hdr-Passing_pointers). In the second case you\nmight need the `NoCheck()` helper function to call the C function in a context,\nwhere the cgocheck debug feature is disabled. This is necessary because PtrGuard\ndoesn't have any possibility to tell cgocheck, that certain pointers are pinned.\n\n## Example\nLet's say we want to use a C API that uses [vectored\nI/O](https://en.wikipedia.org/wiki/Vectored_I/O), like the\n[`readv()`](https://pubs.opengroup.org/onlinepubs/000095399/functions/readv.html)\nPOSIX system call, in order to read data into an array of buffers. Because we\nwant to avoid making a copy of the data, we want to read directly into Go\nbuffers. The pointer passing rules wouldn't allow that, because\n* either we can allocate the buffer array in C memory, but then we can't store\n  the pointers of the Go buffers in it. (Storing Go pointers in C memory is\n  forbidden.)\n* or we would allocate the buffer array in Go memory and store the Go buffers in\n  it. But then we can't pass the pointer to that buffer array to a C function.\n  (Passing a Go pointer that points to memory containing other Go pointers to a\n  C function is forbidden.)\n\nWith PtrGuard both is still possible. (See examples.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fansiwen%2Fptrguard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fansiwen%2Fptrguard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fansiwen%2Fptrguard/lists"}