Sunday, April 30, 2023
HomeGolangCgo assembled c-shared binary string returned as unusual inscribing from C++ assembled...

Cgo assembled c-shared binary string returned as unusual inscribing from C++ assembled with Ubuntu – Obtaining Assistance

I have a percentage of go code that I assemble utilizing cgo as a c-shared binary. This code is after that later on utilized in a C++ data that is assembled utilizing gcc with Ubuntu.

Currently when I utilize this very same code yet assemble on M1 Mac whatever is great and also the feature’s returned string in C++ looks typical. Nonetheless when I assemble it in Ubuntu, once again very same code, the features run without mistake yet the feature’s returned string is this unusual garbled encoding. It appears like this yet it varies on each run. I do not believe its file encryption due to the fact that the return string within the C code is typical.

// C

 func GetOsStore( serviceName * C.char, keyName * C.char) * C.char {
fmt.Println(" GetOsStore begin").
backendType, err:= getBackendType().
if err!= nil {
panic(" Obtaining backend kind has actually stopped working!" + err.Error()).
fmt.Println(" GetOsStore.BackendType", backendType).

ring, openErr:= keyring.Open( keyring.Config {
AllowedBackends: [] keyring.BackendType {backendType},.
ServiceName: C.GoString( serviceName),.
} ).
if openErr!= nil {
fmt.Println(" GetOsStore open keyring mistake", openErr).
} else {
fmt.Println(" GetOsStore opened up keyring").

i, getErr:= ring.Get(( C.GoString( keyName))).
dataStr:= string( i.Data[:]).
returnStr:= (* C.char)( C.CString( dataStr))// returnStr prints uncreative.
delay unsafe.Pointer( returnStr)).
if getErr!= nil {
fmt.Println(" GetOsStore obtain keyring mistake", getErr).
} else {
fmt.Println(" GetOsStore obtained keyring").
fmt.Println(" GetOsStore end").
return returnStr.

// C++

 Napi:: String getOsStore( const Napi:: CallbackInfo& & information ){
Napi:: Env env = info.Env();.

sexually transmitted disease:: string serviceNameArg = information[0] As<< Napi:: String>>(). ToString();.
char * serviceName = brand-new char[serviceNameArg.length() + 1];.
strcpy( serviceName, serviceNameArg.c _ str());.

sexually transmitted disease:: string keyNameArg = information[1] As<< Napi:: String>>(). ToString();.
char * keyName = brand-new char[keyNameArg.length() + 1];.
strcpy( keyName, keyNameArg.c _ str());.

Napi:: String outcome = Napi:: String:: New( env, GetOsStore( serviceName, keyName));.
sexually transmitted disease:: string resultStr = result.ToString();.
cout << < < "getOsStore from c++ string:" << < < resultStr;// both these cout create the inscribed message.
char * resultCStr = brand-new char[resultStr.length() + 1];.
strcpy( resultCStr, resultStr.c _ str());.
cout << < < "getOsStore from c string:" << < < resultCStr;.

remove [] serviceName;.
remove [] keyName;.
return outcome;.


Most Popular

Recent Comments