예제 #1
0
// int Py_Main(int argc, char **argv)
// The main program for the standard interpreter. This is made available for programs which embed Python. The argc and argv parameters should be prepared exactly as those which are passed to a C program’s main() function. It is important to note that the argument list may be modified (but the contents of the strings pointed to by the argument list are not). The return value will be the integer passed to the sys.exit() function, 1 if the interpreter exits due to an exception, or 2 if the parameter list does not represent a valid Python command line.
//
// Note that if an otherwise unhandled SystemError is raised, this function will not return 1, but exit the process, as long as Py_InspectFlag is not set.
func Py_Main(args []string) int {
	var argc C.int = C.int(len(args))
	var argv []*C.char = make([]*C.char, argc)
	for idx, arg := range args {
		argv[idx] = C.CString(arg)
		// no need to free. Py_Main takes owner ship.
		//defer C.free(unsafe.Pointer(argv[idx]))
	}
	return int(C.Py_Main(argc, &argv[0]))
}
예제 #2
0
파일: python.go 프로젝트: xushiwei/gopy
func Main(args []string) int {
	argv := make([]*C.char, len(args))

	for i, arg := range args {
		argv[i] = C.CString(arg)
		defer C.free(unsafe.Pointer(argv[i]))
	}

	return int(C.Py_Main(C.int(len(argv)), &argv[0]))
}
예제 #3
0
파일: python.go 프로젝트: z0mbie42/py3
func Main(args []string) int {
	argv := make([]*C.wchar_t, len(args))

	for i, arg := range args {
		ws, _ := wchar.FromGoString(arg)
		argv[i] = (*C.wchar_t)(ws.Pointer())
		defer C.free(unsafe.Pointer(argv[i]))
	}

	return int(C.Py_Main(C.int(len(argv)), &argv[0]))
}
예제 #4
0
파일: veryhigh.go 프로젝트: gward/go-python
// int Py_Main(int argc, char **argv)
// The main program for the standard interpreter. This is made available for programs which embed Python. The argc and argv parameters should be prepared exactly as those which are passed to a C program’s main() function. It is important to note that the argument list may be modified (but the contents of the strings pointed to by the argument list are not). The return value will be the integer passed to the sys.exit() function, 1 if the interpreter exits due to an exception, or 2 if the parameter list does not represent a valid Python command line.
//
// Note that if an otherwise unhandled SystemError is raised, this function will not return 1, but exit the process, as long as Py_InspectFlag is not set.
func Py_Main(args []string) int {
	var argc C.int = C.int(len(args))
	var argv []*C.char = make([]*C.char, argc)
	for idx, arg := range args {
		argv[idx] = C.CString(arg)
	}
	defer func() {
		for idx, _ := range argv {
			C.free(unsafe.Pointer(argv[idx]))
		}
	}()
	return int(C.Py_Main(argc, &argv[0]))
}