c-for-go icon indicating copy to clipboard operation
c-for-go copied to clipboard

Getting "calling method PassRef with receiver errorInfo (type **ErrorInfo) requires explicit dereference" error on build

Open pieterlexis opened this issue 6 years ago • 1 comments

Hi there,

I have a header file with the following (cut for brevity, full file here):

typedef struct sr_error_info_msg_s {
  char *message;   /**< Error message. */
  char *xpath;     /**< XPath to the node where the error has been discovered. */
} sr_error_info_msg_t;

typedef struct sr_error_info_s {
    sr_error_t err_code; /**< Error code. */
    sr_error_info_msg_t *err; /**< Array of all generated errors. */
    size_t err_count;    /**< Error message count. */
} sr_error_info_t;

int sr_get_error(sr_session_ctx_t *session, const sr_error_info_t **error_info);

I have the following in my yaml (again, cut):

  PtrTips:
    function:
      - target: sr_get_error$
        tips:
          - ref
          - sref

The code generated looks like this:

func GetError(session *SessionCtx, errorInfo **ErrorInfo) int32 {
	csession, _ := (*C.sr_session_ctx_t)(unsafe.Pointer(session)), cgoAllocsUnknown
	cerrorInfo, _ := errorInfo.PassRef()
	__ret := C.sr_get_error(csession, cerrorInfo)
	__v := (int32)(__ret)
	return __v
}

Running go build yields the following error (I assume they are related):

./sr.go:108:28: calling method PassRef with receiver errorInfo (type **ErrorInfo) requires explicit dereference
./sr.go:109:124: cannot use _cgo1 (type *_Ctype_struct_sr_error_info_s) as type **_Ctype_struct_sr_error_info_s in argument to _Cfunc_sr_get_error

I can't figure out why this happens, using sref for other functions that accept a **struct seem to work just fine.

Running c-for-go master with go version go1.13.1 linux/amd64. Any ideas will be appreciated.

pieterlexis avatar Oct 24 '19 15:10 pieterlexis

I have the same problem :(

xaionaro avatar Apr 17 '21 21:04 xaionaro