github.com/bir3/gocompiler@v0.9.2202/src/cmd/cgo/internal/test/issue4029.c (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !windows && !static && !(darwin && internal)
     6  
     7  #include <stdint.h>
     8  #include <dlfcn.h>
     9  
    10  // Write our own versions of dlopen/dlsym/dlclose so that we represent
    11  // the opaque handle as a Go uintptr rather than a Go pointer to avoid
    12  // garbage collector confusion.  See issue 23663.
    13  
    14  uintptr_t dlopen4029(char* name, int flags) {
    15  	return (uintptr_t)(dlopen(name, flags));
    16  }
    17  
    18  uintptr_t dlsym4029(uintptr_t handle, char* name) {
    19  	return (uintptr_t)(dlsym((void*)(handle), name));
    20  }
    21  
    22  int dlclose4029(uintptr_t handle) {
    23  	return dlclose((void*)(handle));
    24  }
    25  
    26  void call4029(void *arg) {
    27  	void (*fn)(void) = arg;
    28  	fn();
    29  }