cpy3/sys.go

93 lines
2.2 KiB
Go
Raw Normal View History

2018-12-13 22:09:42 +00:00
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the MIT License.
2018-12-13 22:09:42 +00:00
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
2018-12-06 17:23:54 +00:00
package python3
/*
2023-05-24 08:30:48 +00:00
#cgo pkg-config: python-3.9-embed
2018-12-06 17:23:54 +00:00
#include "Python.h"
*/
import "C"
import (
"fmt"
"unsafe"
)
2023-05-24 08:30:48 +00:00
// PySys_GetObject : https://docs.python.org/3/c-api/sys.html#c.PySys_GetObject
2018-12-06 17:23:54 +00:00
func PySys_GetObject(name string) *PyObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return togo(C.PySys_GetObject(cname))
}
2023-05-24 08:30:48 +00:00
// PySys_SetObject : https://docs.python.org/3/c-api/sys.html#c.PySys_SetObject
2018-12-06 17:23:54 +00:00
func PySys_SetObject(name string, v *PyObject) int {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return int(C.PySys_SetObject(cname, toc(v)))
}
2023-05-24 08:30:48 +00:00
// PySys_ResetWarnOptions : https://docs.python.org/3/c-api/sys.html#c.PySys_ResetWarnOptions
2018-12-06 17:23:54 +00:00
func PySys_ResetWarnOptions() {
C.PySys_ResetWarnOptions()
}
2023-05-24 08:30:48 +00:00
// PySys_AddWarnOption : https://docs.python.org/3/c-api/sys.html#c.PySys_AddWarnOption
2018-12-06 17:23:54 +00:00
func PySys_AddWarnOption(s string) error {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
ws := C.Py_DecodeLocale(cs, nil)
if ws == nil {
return fmt.Errorf("fail to call Py_DecodeLocale on '%s'", s)
}
defer C.PyMem_RawFree(unsafe.Pointer(ws))
C.PySys_AddWarnOption(ws)
return nil
}
2023-05-24 08:30:48 +00:00
// PySys_SetPath : https://docs.python.org/3/c-api/sys.html#c.PySys_SetPath
2018-12-06 17:23:54 +00:00
func PySys_SetPath(path string) error {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
wpath := C.Py_DecodeLocale(cpath, nil)
if wpath == nil {
return fmt.Errorf("fail to call Py_DecodeLocale on '%s'", path)
}
defer C.PyMem_RawFree(unsafe.Pointer(wpath))
C.PySys_SetPath(wpath)
return nil
}
2023-05-24 08:30:48 +00:00
// PySys_AddXOption : https://docs.python.org/3/c-api/sys.html#c.PySys_AddXOption
2018-12-06 17:23:54 +00:00
func PySys_AddXOption(s string) error {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
ws := C.Py_DecodeLocale(cs, nil)
if ws == nil {
return fmt.Errorf("fail to call Py_DecodeLocale on '%s'", s)
}
defer C.PyMem_RawFree(unsafe.Pointer(ws))
C.PySys_AddXOption(ws)
return nil
}
2023-05-24 08:30:48 +00:00
// PySys_GetXOptions : https://docs.python.org/3/c-api/sys.html#c.PySys_GetXOptions
2018-12-06 17:23:54 +00:00
func PySys_GetXOptions() *PyObject {
return togo(C.PySys_GetXOptions())
}