[Pkg-ocaml-maint-commits] [SCM] pgocaml packaging branch, master, updated. debian/1.4-1-7-gf1be592

Mehdi Dogguy mehdi at debian.org
Wed Jan 4 20:22:57 UTC 2012


The following commit has been merged in the master branch:
commit e819a6f57440c6a09b54f48801870aa0e337d76d
Author: Mehdi Dogguy <mehdi at debian.org>
Date:   Wed Jan 4 21:05:22 2012 +0100

    Add support for hex format (Closes: #640134)

diff --git a/debian/patches/05_support_hex_format b/debian/patches/05_support_hex_format
new file mode 100644
index 0000000..248cf68
--- /dev/null
+++ b/debian/patches/05_support_hex_format
@@ -0,0 +1,59 @@
+Author: Dario Teixeira
+Description: Added support for the 'hex' format used in PostgreSQL 9.0 for serialising
+
+--- a/pGOCaml_generic.ml
++++ b/pGOCaml_generic.ml
+@@ -1548,7 +1548,35 @@
+ let is_oct_digit c = c >= '0' && c <= '7'
+ let oct_val c = Char.code c - 0x30
+ 
+-let bytea_of_string str =
++let is_hex_digit = function '0'..'9' | 'a'..'f' | 'A'..'F' -> true | _ -> false
++
++let hex_val c =
++  let offset = match c with
++    | '0'..'9' -> 0x30
++    | 'a'..'f' -> 0x57
++    | 'A'..'F' -> 0x37
++    | _	       -> failwith "hex_val"
++  in Char.code c - offset
++
++(* Deserialiser for the new 'hex' format introduced in PostgreSQL 9.0. *)
++let bytea_of_string_hex str =
++  let len = String.length str in
++  let buf = Buffer.create ((len-2)/2) in
++  let i = ref 3 in
++  while !i < len do
++    let hi_nibble = str.[!i-1] in
++    let lo_nibble = str.[!i] in
++    i := !i+2;
++    if is_hex_digit hi_nibble && is_hex_digit lo_nibble
++    then begin
++      let byte = ((hex_val hi_nibble) lsl 4) + (hex_val lo_nibble) in
++      Buffer.add_char buf (Char.chr byte)
++    end
++  done;
++  Buffer.contents buf
++
++(* Deserialiser for the old 'escape' format used in PostgreSQL < 9.0. *)
++let bytea_of_string_escape str =
+   let len = String.length str in
+   let buf = Buffer.create len in
+   let i = ref 0 in
+@@ -1578,6 +1606,16 @@
+   done;
+   Buffer.contents buf
+ 
++(* PostgreSQL 9.0 introduced the new 'hex' format for binary data.
++   We must therefore check whether the data begins with a magic sequence
++   that identifies this new format and if so call the appropriate parser;
++   if it doesn't, then we invoke the parser for the old 'escape' format.
++*)
++let bytea_of_string str =
++	if String.starts_with str "\\x"
++	then bytea_of_string_hex str
++	else bytea_of_string_escape str
++
+ let bind = (>>=)
+ let return = Thread.return
+ end
diff --git a/debian/patches/series b/debian/patches/series
index 30105b5..92e8a9e 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,4 @@
 01_postgresql_socket
 03_makefile_cmxs
 04_makefile_byte
+05_support_hex_format

-- 
pgocaml packaging



More information about the Pkg-ocaml-maint-commits mailing list