summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Sandoval2016-11-12 01:06:08 -0800
committerOmar Sandoval2016-11-12 01:08:34 -0800
commit540550d09c602fac376a87544833eda2a77e9647 (patch)
tree7eb4fc53ed9e40d3aad2a378656de0a022beed10
parentec7e6f87024e2e5488bef135e677c9beb30918bc (diff)
downloadaur-540550d09c602fac376a87544833eda2a77e9647.tar.gz
Fix Python scripting support
This backports a couple of patches from the current git to fix Python scripting support. Since one of these patches configure.ac, we also need to run ./autogen. This isn't a problem because all of the necessary tools for ./autogen are in base-devel.
-rw-r--r--.SRCINFO6
-rw-r--r--0001-Fixed-compatibility-with-3.12.patch278
-rw-r--r--0002-Added-Support-for-with-python-and-python.patch351
-rw-r--r--PKGBUILD17
4 files changed, 648 insertions, 4 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 1bf2d49ad833..a81241a43b2d 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,7 +1,7 @@
pkgbase = coccinelle
pkgdesc = Provides spatch program used to apply semantic patches
pkgver = 1.0.6
- pkgrel = 1
+ pkgrel = 2
url = http://coccinelle.lip6.fr/
arch = i686
arch = x86_64
@@ -15,7 +15,11 @@ pkgbase = coccinelle
optdepends = ocaml-findlib: OCaml scripting feature
options = !strip
source = http://coccinelle.lip6.fr/distrib/coccinelle-1.0.6.tgz
+ source = 0001-Fixed-compatibility-with-3.12.patch
+ source = 0002-Added-Support-for-with-python-and-python.patch
sha256sums = 8452ed265c209dae99cbb33b67bc7912e72f8bca1e24f33f1a88ba3d7985e909
+ sha256sums = ddaa7263813276487ddff956bd660dcdfa25642a9a7919c431aa290b8f01b6f0
+ sha256sums = 7e6100c9ea3dd79868835e324e6072672dabc9a2b9ee0ba93180465f35a99d07
pkgname = coccinelle
diff --git a/0001-Fixed-compatibility-with-3.12.patch b/0001-Fixed-compatibility-with-3.12.patch
new file mode 100644
index 000000000000..1df66bcc966f
--- /dev/null
+++ b/0001-Fixed-compatibility-with-3.12.patch
@@ -0,0 +1,278 @@
+From cc454c831e5b61e8cdd961b4c5a47ae18a570387 Mon Sep 17 00:00:00 2001
+From: Thierry Martinez <martinez@nsup.org>
+Date: Wed, 12 Oct 2016 17:09:52 +0200
+Subject: [PATCH 1/2] Fixed: compatibility with 3.12
+
+- Update py.ml
+- Remove the use of |>
+---
+ bundles/pyml/pyml-current/generate.ml | 17 +++++++++--------
+ bundles/pyml/pyml-current/py.ml | 17 ++++++++++-------
+ bundles/pyml/pyml-current/py.mli | 14 +++++++++-----
+ bundles/pyml/pyml-current/pycaml.ml | 4 ++--
+ bundles/pyml/pyml-current/pyml_compat.mli | 2 ++
+ bundles/pyml/pyml-current/pyml_compat312.ml | 2 ++
+ bundles/pyml/pyml-current/pyml_compat400.ml | 2 ++
+ bundles/pyml/pyml-current/pyml_compat403.ml | 2 ++
+ bundles/pyml/pyml-current/pyml_stubs.c | 6 ++++--
+ tools/spgen/source/context_rule.ml | 2 +-
+ 10 files changed, 43 insertions(+), 25 deletions(-)
+
+diff --git a/bundles/pyml/pyml-current/generate.ml b/bundles/pyml/pyml-current/generate.ml
+index 82af8c9..e8d9cff 100644
+--- a/bundles/pyml/pyml-current/generate.ml
++++ b/bundles/pyml/pyml-current/generate.ml
+@@ -2,7 +2,7 @@ type ty =
+ PyObject of bool
+ | PyCompilerFlags | String | WideString | Int | Int64 | Long | Size | IntPtr
+ | Compare | Input | Unit | File | Double | StringOption | NeverReturn
+- | UCS2 | UCS4 | UCS2Option | UCS4Option
++ | UCS2 | UCS4 | UCS2Option | UCS4Option of bool
+
+ type arguments =
+ Value
+@@ -825,7 +825,7 @@ let wrappers_ucs4 =
+ result = PyObject false; };
+ { symbol = "PyUnicodeUCS4_AsUnicode";
+ arguments = Fun [PyObject false];
+- result = UCS4Option; };]
++ result = UCS4Option false; };]
+
+ let wrappers_python3 =
+ [{ symbol = "Py_GetProgramName";
+@@ -919,7 +919,7 @@ let wrappers_python3 =
+ result = PyObject false; };
+ { symbol = "PyUnicode_AsUCS4Copy";
+ arguments = Fun [PyObject false];
+- result = UCS4Option; };]
++ result = UCS4Option true; };]
+
+ let string_of_type_ml ty =
+ match ty with
+@@ -936,7 +936,7 @@ let string_of_type_ml ty =
+ | StringOption -> "string option"
+ | NeverReturn -> "'a"
+ | UCS2 | UCS4 -> "int array"
+- | UCS2Option | UCS4Option -> "int array option"
++ | UCS2Option | UCS4Option _ -> "int array option"
+
+ let decapitalize prefix symbol =
+ prefix ^ symbol
+@@ -1102,7 +1102,7 @@ let string_of_type_c ty =
+ | File -> "FILE *"
+ | Double -> "double"
+ | UCS2 | UCS2Option -> "int16_t *"
+- | UCS4 | UCS4Option -> "int32_t *"
++ | UCS4 | UCS4Option _ -> "int32_t *"
+
+ let print_declaration prefix channel wrapper =
+ let symbol = wrapper.symbol in
+@@ -1149,7 +1149,7 @@ let coercion_of_caml ty v =
+ | IntPtr -> Printf.sprintf "pyunwrap_intref(%s)" v
+ | PyCompilerFlags -> Printf.sprintf "pyunwrap_compilerflags(%s)" v
+ | Compare -> Printf.sprintf "Int_val(%s)" v
+- | Unit | NeverReturn | UCS2Option | UCS4Option -> assert false
++ | Unit | NeverReturn | UCS2Option | UCS4Option _ -> assert false
+ | Input -> Printf.sprintf "256 + Int_val(%s)" v
+ | File -> Printf.sprintf "fdopen(dup(Int_val(%s)), \"r\")" v
+ | Double -> Printf.sprintf "Double_val(%s)" v
+@@ -1180,8 +1180,9 @@ let coercion_of_c ty =
+ | Input | File | UCS2 | UCS4 -> assert false
+ | Double -> Printf.sprintf " CAMLreturn(caml_copy_double(result));"
+ | UCS2Option -> Printf.sprintf " CAMLreturn(pywrap_ucs2_option(result));"
+- | UCS4Option ->
+- Printf.sprintf " CAMLreturn(pywrap_ucs4_option_and_free(result));"
++ | UCS4Option free ->
++ Printf.sprintf " CAMLreturn(pywrap_ucs4_option_and_free(result, %s));"
++ (string_of_bool free)
+
+ let space_if_not_starred s =
+ if s.[String.length s - 1] = '*' then
+diff --git a/bundles/pyml/pyml-current/py.ml b/bundles/pyml/pyml-current/py.ml
+index fca9527..b0f64ce 100644
+--- a/bundles/pyml/pyml-current/py.ml
++++ b/bundles/pyml/pyml-current/py.ml
+@@ -177,8 +177,8 @@ let find_library_path version_major version_minor =
+ | Some library_filename -> library_filename in
+ (library_paths, [library_filename])
+
+-let initialize_version_value () =
+- let version_line = run_command "python --version" true in
++let initialize_version_value python =
++ let version_line = run_command (Printf.sprintf "%s --version" python) true in
+ let version = extract_version version_line in
+ let (version_major, version_minor) = extract_version_major_minor version in
+ version_value := version;
+@@ -220,10 +220,10 @@ let initialize_library () =
+ | Some s -> set_python_home s
+ end
+
+-let initialize () =
++let initialize ?(interpreter = "python") () =
+ if !initialized then
+ failwith "Py.initialize: already initialized";
+- initialize_version_value ();
++ initialize_version_value interpreter;
+ initialize_library ();
+ initialized := true
+
+@@ -449,6 +449,8 @@ let as_UTF8_string s =
+ check_not_null (f s)
+
+ module Type = struct
++ let none = None
++
+ type t =
+ Unknown
+ | Bool
+@@ -497,12 +499,12 @@ module Type = struct
+ match get s with
+ Bytes -> Some (pystring_asstringandsize s)
+ | Unicode -> Some (pystring_asstringandsize (as_UTF8_string s))
+- | _ -> None
++ | _ -> none
+
+ let string_of_repr item =
+ match to_string (object_repr item) with
+- None -> failwith "Py.Object.string_of_repr"
+- | Some repr -> check_some repr
++ Some repr -> check_some repr
++ | _ (* None *) -> failwith "Py.Object.string_of_repr"
+
+ let mismatch t o =
+ failwith
+@@ -1371,6 +1373,7 @@ module Utils = struct
+ with e ->
+ close_in_noerr channel;
+ raise e
++
+ let write_and_close channel f arg =
+ try
+ let result = f arg in
+diff --git a/bundles/pyml/pyml-current/py.mli b/bundles/pyml/pyml-current/py.mli
+index c81c913..8553cf4 100644
+--- a/bundles/pyml/pyml-current/py.mli
++++ b/bundles/pyml/pyml-current/py.mli
+@@ -2,11 +2,15 @@
+
+ (** Call [initialize ()] first. *)
+
+-val initialize: unit -> unit
+-(** [initialize ()] finds and loads the Python library. This function
+- should be called before any other functions, except if explicitely
+- mentioned. The version of Python is determined by the output of
+- the shell command [python --version]. The library is searched by
++val initialize: ?interpreter:string -> unit -> unit
++(** [initialize ~interpreter ()] finds and loads the Python library.
++ This function should be called before any other functions, except
++ if explicitely mentioned.
++ The version of Python is determined by the output of the shell command
++ [python --version].
++ If an [interpreter] executable name is given, this executable is
++ used in place of [python] in the previous command line.
++ The library is searched by
+ using [pkg-config] if available, by considering system paths, and
+ in the directory [../lib] relatively to the directory where the
+ [python] executable is. If the library has been statically linked
+diff --git a/bundles/pyml/pyml-current/pycaml.ml b/bundles/pyml/pyml-current/pycaml.ml
+index bb3421d..cfd0a1a 100644
+--- a/bundles/pyml/pyml-current/pycaml.ml
++++ b/bundles/pyml/pyml-current/pycaml.ml
+@@ -123,7 +123,7 @@ let py_false () = Py.Bool.f
+
+ let py_finalize = Py.finalize
+
+-let py_initialize = Py.initialize
++let py_initialize () = Py.initialize ()
+
+ let py_is_true = Py.Object.is_true
+
+@@ -490,7 +490,7 @@ let unpythonizing_function ?name ?(catch_weird_exceptions = true) ?extra_guards
+
+ let py_profiling_active = ref false
+
+-let py_profile_hash = Lazy.from_fun (fun () -> Hashtbl.create 100)
++let py_profile_hash = Pyml_compat.lazy_from_fun (fun () -> Hashtbl.create 100)
+
+ let py_activate_profiling () =
+ let old_value = !py_profiling_active in
+diff --git a/bundles/pyml/pyml-current/pyml_compat.mli b/bundles/pyml/pyml-current/pyml_compat.mli
+index 19c5b8a..c717f93 100644
+--- a/bundles/pyml/pyml-current/pyml_compat.mli
++++ b/bundles/pyml/pyml-current/pyml_compat.mli
+@@ -1,3 +1,5 @@
+ val lowercase: string -> string
+
+ val mapi: (int -> 'a -> 'b) -> 'a list -> 'b list
++
++val lazy_from_fun: (unit -> 'a) -> 'a Lazy.t
+diff --git a/bundles/pyml/pyml-current/pyml_compat312.ml b/bundles/pyml/pyml-current/pyml_compat312.ml
+index 3185799..ddfd5f1 100644
+--- a/bundles/pyml/pyml-current/pyml_compat312.ml
++++ b/bundles/pyml/pyml-current/pyml_compat312.ml
+@@ -7,3 +7,5 @@ let rec mapi_from f i l =
+
+ let mapi f l =
+ mapi_from f 0 l
++
++let lazy_from_fun = Lazy.lazy_from_fun
+diff --git a/bundles/pyml/pyml-current/pyml_compat400.ml b/bundles/pyml/pyml-current/pyml_compat400.ml
+index 26512eb..564da81 100644
+--- a/bundles/pyml/pyml-current/pyml_compat400.ml
++++ b/bundles/pyml/pyml-current/pyml_compat400.ml
+@@ -1,3 +1,5 @@
+ let lowercase = String.lowercase
+
+ let mapi = List.mapi
++
++let lazy_from_fun = Lazy.from_fun
+diff --git a/bundles/pyml/pyml-current/pyml_compat403.ml b/bundles/pyml/pyml-current/pyml_compat403.ml
+index d960204..192a787 100644
+--- a/bundles/pyml/pyml-current/pyml_compat403.ml
++++ b/bundles/pyml/pyml-current/pyml_compat403.ml
+@@ -1,3 +1,5 @@
+ let lowercase = String.lowercase_ascii
+
+ let mapi = List.mapi
++
++let lazy_from_fun = Lazy.from_fun
+diff --git a/bundles/pyml/pyml-current/pyml_stubs.c b/bundles/pyml/pyml-current/pyml_stubs.c
+index 69ab87a..c8d33af 100644
+--- a/bundles/pyml/pyml-current/pyml_stubs.c
++++ b/bundles/pyml/pyml-current/pyml_stubs.c
+@@ -872,7 +872,7 @@ pywrap_ucs2_option(int16_t *buffer)
+ }
+
+ static value
+-pywrap_ucs4_option_and_free(int32_t *buffer)
++pywrap_ucs4_option_and_free(int32_t *buffer, bool free)
+ {
+ CAMLparam0();
+ CAMLlocal2(result, array);
+@@ -891,7 +891,9 @@ pywrap_ucs4_option_and_free(int32_t *buffer)
+ }
+ result = caml_alloc(1, 0);
+ Store_field(result, 0, array);
+- Python_PyMem_Free(buffer);
++ if (free) {
++ Python_PyMem_Free(buffer);
++ }
+ CAMLreturn(result);
+ }
+
+diff --git a/tools/spgen/source/context_rule.ml b/tools/spgen/source/context_rule.ml
+index e925a36..80db2a9 100644
+--- a/tools/spgen/source/context_rule.ml
++++ b/tools/spgen/source/context_rule.ml
+@@ -52,7 +52,7 @@ let generate ~context_mode ~disj_map ~new_name ~rule_names ~rule =
+ then MV.inherit_rule ~force:true ~new_rule:(Globals.get_context_name ~context_mode r) mv
+ else mv
+ in
+- MV.extract ~minus_rule ~rule_name:old_nm |> List.map inherit_name
++ List.map inherit_name (MV.extract ~minus_rule ~rule_name:old_nm)
+ in
+
+ let deps = Globals.add_context_dependency ~context_mode deps in
+--
+2.10.1
+
diff --git a/0002-Added-Support-for-with-python-and-python.patch b/0002-Added-Support-for-with-python-and-python.patch
new file mode 100644
index 000000000000..1649bea84bf4
--- /dev/null
+++ b/0002-Added-Support-for-with-python-and-python.patch
@@ -0,0 +1,351 @@
+From c8025ac6bd9874663f4445288056702c424db8cb Mon Sep 17 00:00:00 2001
+From: Thierry Martinez <martinez@nsup.org>
+Date: Tue, 18 Oct 2016 18:38:05 +0200
+Subject: [PATCH 2/2] Added: Support for --with-python and --python
+
+The option --with-python is restored in configure to give a default
+path/command for the Python interpreter.
+
+The value can be overwritten with the --python option in the command
+line.
+
+Py.ml library has been updated to support custom Python interpreters. As
+a side effect, the environment variable PYTHONHOME is now dynamically
+set if it is not already defined. It should make the Python library work
+even on systems where the environment variable has not been properly
+set.
+---
+ bundles/pyml/pyml-current/py.ml | 94 ++++++++++++++++++++++++++--------
+ bundles/pyml/pyml-current/py.mli | 10 ++--
+ bundles/pyml/pyml-current/pyml_stubs.c | 24 +++++++--
+ changes.txt | 2 +
+ configure.ac | 10 ++++
+ globals/config.ml.in | 2 +
+ main.ml | 2 +
+ python/yes_pycocci.ml | 2 +-
+ 8 files changed, 116 insertions(+), 30 deletions(-)
+
+diff --git a/bundles/pyml/pyml-current/py.ml b/bundles/pyml/pyml-current/py.ml
+index b0f64ce..50caab2 100644
+--- a/bundles/pyml/pyml-current/py.ml
++++ b/bundles/pyml/pyml-current/py.ml
+@@ -6,7 +6,8 @@ type compare = Pytypes.compare = LT | LE | EQ | NE | GT | GE
+
+ type ucs = UCSNone | UCS2 | UCS4
+
+-external load_library: int -> string option -> unit = "py_load_library"
++external load_library: string option -> unit = "py_load_library"
++external unsetenv: string -> unit = "py_unsetenv"
+ external finalize_library: unit -> unit = "py_finalize_library"
+ external pywrap_closure: string -> (pyobject -> pyobject) -> pyobject
+ = "pywrap_closure"
+@@ -84,13 +85,13 @@ let extract_version version_line =
+
+ let extract_version_major_minor version =
+ try
+- let first_dot = String.index version '.' in
+- let second_dot = String.index_from version (succ first_dot) '.' in
+- let major = int_of_string (String.sub version 0 first_dot) in
+- let minor =
+- int_of_string (substring_between version first_dot second_dot) in
+- (major, minor)
+- with Not_found | Failure _ ->
++ if String.length version >= 3 && (String.sub version 1 1 = ".") then
++ let major = int_of_string (String.sub version 0 1) in
++ let minor = int_of_string (String.sub version 2 1) in
++ (major, minor)
++ else
++ raise Exit
++ with Exit | Failure _ ->
+ let msg =
+ Printf.sprintf
+ "Py.extract_version_major: unable to parse the version number '%s'"
+@@ -134,6 +135,19 @@ let rec split string ?(from=0) separator =
+ let word = String.sub string from (position - from) in
+ word :: split string ~from:(succ position) separator
+
++let parent_dir filename =
++ let dirname = Filename.dirname filename in
++ Filename.concat dirname Filename.parent_dir_name
++
++let has_putenv = ref false
++
++let init_pythonhome pythonhome =
++ try
++ ignore (Sys.getenv "PYTHONHOME")
++ with Not_found ->
++ Unix.putenv "PYTHONHOME" pythonhome;
++ has_putenv := true
++
+ let find_library_path version_major version_minor =
+ let command =
+ Printf.sprintf "pkg-config --libs python-%d.%d" version_major
+@@ -144,10 +158,16 @@ let find_library_path version_major version_minor =
+ with
+ None ->
+ let library_paths =
+- try
+- [Filename.concat (Filename.dirname (run_command "which python" false))
+- "../lib"]
+- with Failure _ -> [] in
++ match
++ try Some (Sys.getenv "PYTHONHOME")
++ with Not_found -> None
++ with
++ None -> []
++ | Some pythonhome ->
++ let prefix =
++ try String.sub pythonhome 0 (String.index pythonhome ':')
++ with Not_found -> pythonhome in
++ [Filename.concat prefix "lib"] in
+ let library_filenames =
+ [Printf.sprintf "python%d.%dm" version_major version_minor;
+ Printf.sprintf "python%d.%d" version_major version_minor] in
+@@ -177,8 +197,20 @@ let find_library_path version_major version_minor =
+ | Some library_filename -> library_filename in
+ (library_paths, [library_filename])
+
+-let initialize_version_value python =
+- let version_line = run_command (Printf.sprintf "%s --version" python) true in
++let initialize_version_value interpreter =
++ begin
++ let python_full_path =
++ if String.contains interpreter '/' then interpreter
++ else
++ let which_python = Printf.sprintf "which \"%s\"" interpreter in
++ run_command which_python false in
++ let pythonhome = parent_dir python_full_path in
++ init_pythonhome pythonhome
++ end;
++ let version_line =
++ let python_version_cmd = Printf.sprintf "\"%s\" --version" interpreter in
++ try run_command python_version_cmd false
++ with Failure _ -> run_command python_version_cmd true in
+ let version = extract_version version_line in
+ let (version_major, version_minor) = extract_version_major_minor version in
+ version_value := version;
+@@ -187,7 +219,7 @@ let initialize_version_value python =
+
+ let find_library () =
+ try
+- load_library !version_major_value None
++ load_library None
+ with Failure _ ->
+ let (library_paths, library_filenames) =
+ find_library_path !version_major_value !version_minor_value in
+@@ -206,7 +238,9 @@ let find_library () =
+ [] -> failwith "Py.find_library: unable to find the Python library"
+ | filename :: others ->
+ begin
+- try load_library !version_major_value (Some filename)
++ try
++ init_pythonhome (parent_dir filename);
++ load_library (Some filename)
+ with Failure _ -> try_load_library others
+ end in
+ try_load_library library_filenames
+@@ -220,16 +254,38 @@ let initialize_library () =
+ | Some s -> set_python_home s
+ end
+
+-let initialize ?(interpreter = "python") () =
++let get_version = Pywrappers.py_getversion
++
++let initialize ?(interpreter = "python") ?version () =
+ if !initialized then
+ failwith "Py.initialize: already initialized";
+- initialize_version_value interpreter;
++ begin
++ match version with
++ Some (version_major, version_minor) ->
++ version_major_value := version_major;
++ version_minor_value := version_minor
++ | _ ->
++ initialize_version_value interpreter;
++ end;
+ initialize_library ();
++ let version = get_version () in
++ let (version_major, version_minor) = extract_version_major_minor version in
++ if version_major != !version_major_value ||
++ version_minor != !version_minor_value then
++ begin
++ finalize_library ();
++ failwith "Version mismatch"
++ end;
+ initialized := true
+
+ let finalize () =
+ assert_initialized ();
+ finalize_library ();
++ if !has_putenv then
++ begin
++ unsetenv "PYTHONHOME";
++ has_putenv := false
++ end;
+ initialized := false
+
+ let version () =
+@@ -335,8 +391,6 @@ let get_path () =
+ else
+ Pywrappers.Python3.py_getpath ()
+
+-let get_version = Pywrappers.py_getversion
+-
+ let get_platform = Pywrappers.py_getplatform
+
+ let get_copyright = Pywrappers.py_getcopyright
+diff --git a/bundles/pyml/pyml-current/py.mli b/bundles/pyml/pyml-current/py.mli
+index 8553cf4..f8db91e 100644
+--- a/bundles/pyml/pyml-current/py.mli
++++ b/bundles/pyml/pyml-current/py.mli
+@@ -2,12 +2,14 @@
+
+ (** Call [initialize ()] first. *)
+
+-val initialize: ?interpreter:string -> unit -> unit
+-(** [initialize ~interpreter ()] finds and loads the Python library.
++val initialize: ?interpreter:string -> ?version:(int * int) -> unit -> unit
++(** [initialize ~interpreter ~version ()] finds and loads the Python library.
+ This function should be called before any other functions, except
+ if explicitely mentioned.
+- The version of Python is determined by the output of the shell command
+- [python --version].
++ [version] should be a pair specifying the major and the minor version
++ number.
++ If no version number is given, the version of Python is determined by the
++ output of the shell command [python --version].
+ If an [interpreter] executable name is given, this executable is
+ used in place of [python] in the previous command line.
+ The library is searched by
+diff --git a/bundles/pyml/pyml-current/pyml_stubs.c b/bundles/pyml/pyml-current/pyml_stubs.c
+index c8d33af..5732026 100644
+--- a/bundles/pyml/pyml-current/pyml_stubs.c
++++ b/bundles/pyml/pyml-current/pyml_stubs.c
+@@ -12,6 +12,7 @@
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <unistd.h>
++#include <errno.h>
+
+ /* The following definitions are extracted and simplified from
+ #include <Python.h>
+@@ -458,10 +459,9 @@ pywrap_closure(value docstring, value closure)
+ }
+
+ CAMLprim value
+-py_load_library(value version_major_ocaml, value filename_ocaml)
++py_load_library(value filename_ocaml)
+ {
+- CAMLparam2(version_major_ocaml, filename_ocaml);
+- version_major = Int_val(version_major_ocaml);
++ CAMLparam1(filename_ocaml);
+ if (Is_block(filename_ocaml)) {
+ char *filename = String_val(Field(filename_ocaml, 0));
+ library = dlopen(filename, RTLD_LAZY);
+@@ -472,10 +472,13 @@ py_load_library(value version_major_ocaml, value filename_ocaml)
+ else {
+ library = RTLD_DEFAULT;
+ }
+- Python_PyCFunction_NewEx = dlsym(library, "PyCFunction_NewEx");
+- if (!Python_PyCFunction_NewEx) {
++ Python_Py_GetVersion = dlsym(library, "Py_GetVersion");
++ if (!Python_Py_GetVersion) {
+ failwith("No Python symbol");
+ }
++ const char *version = Python_Py_GetVersion();
++ version_major = version[0] - '0';
++ Python_PyCFunction_NewEx = resolve("PyCFunction_NewEx");
+ Python_PyCapsule_New = resolve("PyCapsule_New");
+ Python_PyCapsule_GetPointer = resolve("PyCapsule_GetPointer");
+ Python_PyObject_CallFunctionObjArgs =
+@@ -524,6 +527,17 @@ py_finalize_library(value unit)
+ }
+
+ CAMLprim value
++py_unsetenv(value name_ocaml)
++{
++ CAMLparam1(name_ocaml);
++ char *name = String_val(name_ocaml);
++ if (unsetenv(name) == -1) {
++ failwith(strerror(errno));
++ }
++ CAMLreturn(Val_unit);
++}
++
++CAMLprim value
+ py_get_UCS(value unit)
+ {
+ CAMLparam1(unit);
+diff --git a/changes.txt b/changes.txt
+index 4a48965..552bb3f 100644
+--- a/changes.txt
++++ b/changes.txt
+@@ -16,6 +16,8 @@
+ - New scripting languages
+ - more than one SP on the command line
+ - interpret #if, as is done for #ifdef
++- restored support for with-python in configure and support for --python option
++ in the command line to use a specific python interpreter
+
+ ** Bugfix:
+ - Add more information in documentation, man pages and wiki
+diff --git a/configure.ac b/configure.ac
+index 8402b59..fa51ca5 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -276,6 +276,16 @@ dnl variables:
+ dnl with_python: whether to enable the python feature (and what version)
+ AC_ARG_ENABLE([python], [AS_HELP_STRING([--enable-python], [enable python scripting (yes/no) (default: auto)])])
+
++AC_ARG_WITH([python], [AS_HELP_STRING([--with-python], [which python interpreter to use (default: python)])])
++
++AS_IF([test -n "$with_python"],
++[dnl
++ AC_SUBST([PYTHON], ["$with_python"])
++],
++[dnl
++ AC_SUBST([PYTHON], ["python"])
++])
++
+ AS_IF([test "x$enable_python" != xno],
+ [dnl
+ AC_CHECK_COCCI_EXTPKG([pyml]) dnl will set $enable_pyml to 'yes', 'no', or 'local'
+diff --git a/globals/config.ml.in b/globals/config.ml.in
+index 978fa77..02b7ef1 100644
+--- a/globals/config.ml.in
++++ b/globals/config.ml.in
+@@ -12,3 +12,5 @@ let get_temp_dir_name = @GET_TEMP_DIR_NAME_EXPR@
+
+ let configure_flags = "@CONFIGURE_FLAGS@"
+ let ocaml_version = "@OCAMLVERSION@"
++
++let python_interpreter = ref "@PYTHON@"
+diff --git a/main.ml b/main.ml
+index 66aaff4..2444d39 100644
+--- a/main.ml
++++ b/main.ml
+@@ -353,6 +353,8 @@ let short_options = [
+ " \"\" for a file in the current directory");
+ "--kbuild-info", Arg.Set_string kbuild_info,
+ " <file> improve -dir by grouping related c files";
++ "--python", Arg.Set_string Config.python_interpreter,
++ " Sets the path to the python interpreter";
+ "--pyoutput", Arg.Set_string Flag.pyoutput,
+ " Sets output routine: Standard values: <coccilib.output.Gtk|coccilib.output.Console>";
+ "--parse-handler",
+diff --git a/python/yes_pycocci.ml b/python/yes_pycocci.ml
+index 920d22f..55ac501 100644
+--- a/python/yes_pycocci.ml
++++ b/python/yes_pycocci.ml
+@@ -172,7 +172,7 @@ let pycocci_init () =
+ initialised := true;
+ let _ = if not (Py.is_initialized ()) then
+ (if !Flag.show_misc then Common.pr2 "Initializing python\n%!";
+- Py.initialize ()) in
++ Py.initialize ~interpreter:!Config.python_interpreter ()) in
+
+ (* set argv *)
+ let argv0 = Sys.executable_name in
+--
+2.10.1
+
diff --git a/PKGBUILD b/PKGBUILD
index 802c86ea5446..f65c11a766e5 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -9,7 +9,7 @@
pkgname=coccinelle
pkgver=1.0.6
-pkgrel=1
+pkgrel=2
pkgdesc="Provides spatch program used to apply semantic patches"
arch=('i686' 'x86_64')
url="http://coccinelle.lip6.fr/"
@@ -19,12 +19,23 @@ depends=('pcre' 'python')
optdepends=('ocaml: OCaml scripting feature'
'ocaml-findlib: OCaml scripting feature')
options=('!strip')
-source=(http://coccinelle.lip6.fr/distrib/${pkgname}-${pkgver}.tgz)
-sha256sums=('8452ed265c209dae99cbb33b67bc7912e72f8bca1e24f33f1a88ba3d7985e909')
+source=(http://coccinelle.lip6.fr/distrib/${pkgname}-${pkgver}.tgz
+ 0001-Fixed-compatibility-with-3.12.patch
+ 0002-Added-Support-for-with-python-and-python.patch)
+sha256sums=('8452ed265c209dae99cbb33b67bc7912e72f8bca1e24f33f1a88ba3d7985e909'
+ 'ddaa7263813276487ddff956bd660dcdfa25642a9a7919c431aa290b8f01b6f0'
+ '7e6100c9ea3dd79868835e324e6072672dabc9a2b9ee0ba93180465f35a99d07')
+
+prepare() {
+ cd "$pkgname-$pkgver"
+ patch -p1 <"$srcdir/0001-Fixed-compatibility-with-3.12.patch"
+ patch -p1 <"$srcdir/0002-Added-Support-for-with-python-and-python.patch"
+}
build() {
cd "$pkgname-$pkgver"
+ ./autogen
./configure --prefix=/usr
make
}