Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat symbol validation #166

Merged
merged 2 commits into from Mar 4, 2024
Merged

Conversation

fishingfly
Copy link
Contributor

@fishingfly fishingfly commented Mar 4, 2024

#165

How to use

yaml file will add a Validations filed in TRANSLATOR:

---
GENERATOR:
  PackageName: device
  PackageDescription: "Package Device bindings"
  PackageLicense: |-
  Includes: ["device.h", "device_internal.h"]
  FlagGroups:
    - {name: "LDFLAGS", flags: ["-ldevice"]}
  Options:
    SafeStrings: true
PARSER:
  IncludePaths: ["."]
  SourcesPaths: ["device.h", "device_internal.h"]
TRANSLATOR:
  ....
+  Validations:
+     - validatefunc: libdevice.Lookup
+       ret: ERROR_NOT_SUPPORTED
+       matchedfunc: ^(?!.*deviceErrorString).*$
+     - validatefunc: libdevice.Lookup
+        ret: ERROR_NOT_SUPPORTED_STRING
+        matchedfunc: ^deviceErrorString

and the generated go function codes as follows:

// deviceErrorString function as declared in device/device.h
func deviceErrorString(Result Return) string {
+       if libdevice.Lookup("deviceGetMode") != nil {
+		return ERROR_NOT_SUPPORTED_STRING
+	}
	cResult, cResultAllocMap := (C.DeviceReturn)(Result), cgoAllocsUnknown
	__ret := C.deviceErrorString(cResult)
	runtime.KeepAlive(cResultAllocMap)
	__v := packPCharString(__ret)
	return __v
}

// deviceGetMode function as declared in device/device.h
func deviceGetMode(Device *Device, Mode Mode) Return {
+	if libdevice.Lookup("deviceGetMode") != nil {
+		return ERROR_NOT_SUPPORTED
+	}
	cDevice, cDeviceAllocMap := (*C.Device)(unsafe.Pointer(Device)), cgoAllocsUnknown
	cMode, cModeAllocMap := (C.Mode)(Mode), cgoAllocsUnknown
	__ret := C.deviceGetMode(cDevice, cMode)
	runtime.KeepAlive(cModeAllocMap)
	runtime.KeepAlive(cDeviceAllocMap)
	__v := (Return)(__ret)
	return __v
}
  • validatefunc field is used to specify the lookup function which defined bu user.
  • ret filed is used to specify the ret value which defined by user.
  • matchedfunc field is used to specify a full-featured regex to match functions or skip functions.

Signed-off-by: zhouyu <zhouyuzf@163.com>
Copy link
Owner

@xlab xlab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thanks for contribution, the feature looks really interesting. However, is it possible to avoid adding vendor dir? The project uses go.mod system. Otherwise it makes PR big and codebase becomes confusing.

@yeahdongcn
Copy link

yeahdongcn commented Mar 4, 2024

It is super useful to me as various versions of a library coexist in my production environment. The go client always consumes the latest binding (shipping with container), while in runtime, certain APIs may not exist in the runtime library.

Signed-off-by: zhouyu <zhouyuzf@163.com>
@fishingfly
Copy link
Contributor Author

Hello! Thanks for contribution, the feature looks really interesting. However, is it possible to avoid adding vendor dir? The project uses go.mod system. Otherwise it makes PR big and codebase becomes confusing.

ACK

@fishingfly fishingfly requested a review from xlab March 4, 2024 10:46
@xlab xlab merged commit 06bec1a into xlab:master Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants