+ pystring_fromstring (!cocci_file_name)
+
+(* initialisation routines *)
+let _pycocci_setargs argv0 =
+ let argv =
+ pysequence_list (pytuple_fromsingle (pystring_fromstring argv0)) in
+ let sys_mod = load_module "sys" in
+ pyobject_setattrstring (sys_mod, "argv", argv)
+
+let pycocci_init () =
+ (* initialize *)
+ if not !initialised then (
+ initialised := true;
+ (* use python_path_base as default (overridable) dir for coccilib *)
+ let python_path_base = Printf.sprintf "%s/coccinelle" (Unix.getenv "HOME") in
+ let python_path = try Unix.getenv "PYTHONPATH" ^ ":" ^ python_path_base
+ with Not_found -> python_path_base in
+ Unix.putenv "PYTHONPATH" python_path;
+ let _ = if not (py_isinitialized () != 0) then
+ (if !Flag.show_misc then Common.pr2 "Initializing python\n%!";
+ py_initialize()) in
+
+ (* set argv *)
+ let argv0 = Sys.executable_name in
+ let _ = _pycocci_setargs argv0 in
+
+ coccinelle_module := (pymodule_new "coccinelle");
+ module_map := StringMap.add "coccinelle" !coccinelle_module !module_map;
+ let _ = load_module "coccilib.elems" in
+ let _ = load_module "coccilib.output" in
+
+ let module_dictionary = pyimport_getmoduledict() in
+ coccinelle_module := pymodule_new "coccinelle";
+ let mx = !coccinelle_module in
+ let (cd, cx) = build_class "Cocci" (!Flag.pyoutput)
+ [("exit", sp_exit, (pynull()));
+ ("include_match", include_match, (pynull()));
+ ("has_env_binding", has_environment_binding, (pynull()))] mx in
+ pyoutputinstance := cx;
+ pyoutputdict := cd;
+ let v1 = pydict_setitemstring(module_dictionary, "coccinelle", mx) in
+ check_int_return_value "adding coccinelle python module" v1;
+ let mypystring = pystring_fromstring !cocci_file_name in
+ let v2 = pydict_setitemstring(cd, "cocci_file", mypystring) in
+ check_int_return_value "adding python field cocci_file" v2;
+ ()) else
+ ()
+
+(*let _ = pycocci_init ()*)
+(* end initialisation routines *)
+
+let added_variables = ref []