|
| 1 | +package python3 |
| 2 | + |
| 3 | +/* |
| 4 | +#include "Python.h" |
| 5 | +*/ |
| 6 | +import "C" |
| 7 | +import ( |
| 8 | +"fmt" |
| 9 | +"unsafe" |
| 10 | +) |
| 11 | + |
| 12 | +//PySys_GetObject : https://docs.python.org/3/c-api/sys.html#c.PySys_GetObject |
| 13 | +func PySys_GetObject(name string) *PyObject { |
| 14 | +cname := C.CString(name) |
| 15 | +defer C.free(unsafe.Pointer(cname)) |
| 16 | + |
| 17 | +return togo(C.PySys_GetObject(cname)) |
| 18 | +} |
| 19 | + |
| 20 | +//PySys_SetObject : https://docs.python.org/3/c-api/sys.html#c.PySys_SetObject |
| 21 | +func PySys_SetObject(name string, v *PyObject) int { |
| 22 | +cname := C.CString(name) |
| 23 | +defer C.free(unsafe.Pointer(cname)) |
| 24 | + |
| 25 | +return int(C.PySys_SetObject(cname, toc(v))) |
| 26 | +} |
| 27 | + |
| 28 | +//PySys_ResetWarnOptions : https://docs.python.org/3/c-api/sys.html#c.PySys_ResetWarnOptions |
| 29 | +func PySys_ResetWarnOptions() { |
| 30 | +C.PySys_ResetWarnOptions() |
| 31 | +} |
| 32 | + |
| 33 | +//PySys_AddWarnOption : https://docs.python.org/3/c-api/sys.html#c.PySys_AddWarnOption |
| 34 | +func PySys_AddWarnOption(s string) error { |
| 35 | +cs := C.CString(s) |
| 36 | +defer C.free(unsafe.Pointer(cs)) |
| 37 | + |
| 38 | +ws := C.Py_DecodeLocale(cs, nil) |
| 39 | +if ws == nil { |
| 40 | +return fmt.Errorf("fail to call Py_DecodeLocale on '%s'", s) |
| 41 | +} |
| 42 | +defer C.PyMem_RawFree(unsafe.Pointer(ws)) |
| 43 | + |
| 44 | +C.PySys_AddWarnOption(ws) |
| 45 | + |
| 46 | +return nil |
| 47 | +} |
| 48 | + |
| 49 | +//PySys_AddWarnOptionUnicode : https://docs.python.org/3/c-api/sys.html#c.PySys_AddWarnOptionUnicode |
| 50 | +func PySys_AddWarnOptionUnicode(unicode *PyObject) { |
| 51 | +C.PySys_AddWarnOptionUnicode(toc(unicode)) |
| 52 | +} |
| 53 | + |
| 54 | +//PySys_SetPath : https://docs.python.org/3/c-api/sys.html#c.PySys_SetPath |
| 55 | +func PySys_SetPath(path string) error { |
| 56 | +cpath := C.CString(path) |
| 57 | +defer C.free(unsafe.Pointer(cpath)) |
| 58 | + |
| 59 | +wpath := C.Py_DecodeLocale(cpath, nil) |
| 60 | +if wpath == nil { |
| 61 | +return fmt.Errorf("fail to call Py_DecodeLocale on '%s'", path) |
| 62 | +} |
| 63 | +defer C.PyMem_RawFree(unsafe.Pointer(wpath)) |
| 64 | + |
| 65 | +C.PySys_SetPath(wpath) |
| 66 | + |
| 67 | +return nil |
| 68 | +} |
| 69 | + |
| 70 | +//PySys_AddXOption : https://docs.python.org/3/c-api/sys.html#c.PySys_AddXOption |
| 71 | +func PySys_AddXOption(s string) error { |
| 72 | +cs := C.CString(s) |
| 73 | +defer C.free(unsafe.Pointer(cs)) |
| 74 | + |
| 75 | +ws := C.Py_DecodeLocale(cs, nil) |
| 76 | +if ws == nil { |
| 77 | +return fmt.Errorf("fail to call Py_DecodeLocale on '%s'", s) |
| 78 | +} |
| 79 | +defer C.PyMem_RawFree(unsafe.Pointer(ws)) |
| 80 | + |
| 81 | +C.PySys_AddXOption(ws) |
| 82 | + |
| 83 | +return nil |
| 84 | +} |
| 85 | + |
| 86 | +//PySys_GetXOptions : https://docs.python.org/3/c-api/sys.html#c.PySys_GetXOptions |
| 87 | +func PySys_GetXOptions() *PyObject { |
| 88 | +return togo(C.PySys_GetXOptions()) |
| 89 | +} |
0 commit comments