]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Add a Chksum::from_bin to the bindings
authorMichael Schroeder <mls@suse.de>
Fri, 28 Aug 2015 11:59:15 +0000 (13:59 +0200)
committerMichael Schroeder <mls@suse.de>
Fri, 28 Aug 2015 11:59:15 +0000 (13:59 +0200)
Also make use of the new solv_chksum_cmp function.

bindings/solv.i
doc/libsolv-bindings.3
doc/libsolv-bindings.txt

index 21d39d1b9b6b5b06c3a48c03ebf4fb142c8dfba6..1c6128848d70b60eec7fee84fc900a26ec5c84b8 100644 (file)
@@ -1335,6 +1335,19 @@ typedef struct {
       return 0;
     return solv_chksum_create_from_bin(type, buf);
   }
+  %newobject from_bin;
+  static Chksum *from_bin(Id type, const unsigned char *str, size_t len) {
+    return len == solv_chksum_len(type) ? solv_chksum_create_from_bin(type, str) : 0;
+  }
+  %perlcode {
+    # make from_bin look like a constructor
+    undef *solv::Chksum::from_bin;
+    *solv::Chksum::from_bin = sub {
+      my $pkg = shift;
+      my $self = solvc::Chksum_from_bin(@_);
+      bless $self, $pkg if defined $self;
+    };
+  }
   ~Chksum() {
     solv_chksum_free($self, 0);
   }
@@ -1407,21 +1420,13 @@ typedef struct {
   %rename("==") __eq__;
 #endif
   bool __eq__(Chksum *chk) {
-    int l;
-    const unsigned char *b, *bo;
-    if (!chk)
-      return 0;
-    if (solv_chksum_get_type($self) != solv_chksum_get_type(chk))
-      return 0;
-    b = solv_chksum_get($self, &l);
-    bo = solv_chksum_get(chk, 0);
-    return memcmp(b, bo, l) == 0;
+    return solv_chksum_cmp($self, chk);
   }
 #if defined(SWIGTCL)
   %rename("!=") __ne__;
 #endif
   bool __ne__(Chksum *chk) {
-    return !Chksum___eq__($self, chk);
+    return !solv_chksum_cmp($self, chk);
   }
 #if defined(SWIGRUBY)
   %rename("to_s") __str__;
index b2d8d4cd228cfbfeb101431c2614e5e7f9d0ca27..e07b229bd06c826581248875b77a057b6c4ab229 100644 (file)
@@ -5000,7 +5000,22 @@ my \fI$chksum\fR \fB= solv::Chksum\->new(\fR\fI$type\fR\fB,\fR \fI$hex\fR\fB)\fR
 .RE
 .\}
 .sp
-Create an already finalized checksum object\&.
+Create an already finalized checksum object from a hex string\&.
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fBChksum Chksum_from_bin(Id\fR \fItype\fR\fB, char *\fR\fIbin\fR\fB)\fR
+my \fI$chksum\fR \fB= solv::Chksum\->from_bin(\fR\fI$type\fR\fB,\fR \fI$bin\fR\fB)\fR;
+\fIchksum\fR \fB= solv\&.Chksum\&.from_bin(\fR\fItype\fR\fB,\fR \fIbin\fR\fB)\fR
+\fIchksum\fR \fB= Solv::Chksum\&.from_bin(\fR\fItype\fR\fB,\fR \fIbin\fR\fB)\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Create an already finalized checksum object from a binary checksum\&.
 .SS "ATTRIBUTES"
 .sp
 .if n \{\
@@ -5032,7 +5047,7 @@ Return the type of the checksum object\&.
 .RE
 .\}
 .sp
-Add a string to the checksum\&.
+Add a (binary) string to the checksum\&.
 .sp
 .if n \{\
 .RS 4
index f1834ff7f1003d22644757cd496426d421455f3b..dcbc2d177e7e4961135e85fa4fc3e77a63b77780 100644 (file)
@@ -3085,7 +3085,14 @@ These keys are constants in the *solv* class.
        chksum = solv.Chksum(type, hex)
        chksum = Solv::Chksum.new(type, hex)
 
-Create an already finalized checksum object.
+Create an already finalized checksum object from a hex string.
+
+       Chksum Chksum_from_bin(Id type, char *bin)
+       my $chksum = solv::Chksum->from_bin($type, $bin);
+       chksum = solv.Chksum.from_bin(type, bin)
+       chksum = Solv::Chksum.from_bin(type, bin)
+
+Create an already finalized checksum object from a binary checksum.
 
 === ATTRIBUTES ===
 
@@ -3103,7 +3110,7 @@ Return the type of the checksum object.
        chksum.add(str)
        chksum.add(str)
 
-Add a string to the checksum.
+Add a (binary) string to the checksum.
 
        void add_fp(FILE *fp)
        $chksum->add_fp($file);