From: Michael Schroeder Date: Fri, 28 Aug 2015 11:59:15 +0000 (+0200) Subject: Add a Chksum::from_bin to the bindings X-Git-Tag: 0.6.12~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f39ae54f34bda6579a61ee349a55ff03b375f030;p=thirdparty%2Flibsolv.git Add a Chksum::from_bin to the bindings Also make use of the new solv_chksum_cmp function. --- diff --git a/bindings/solv.i b/bindings/solv.i index 21d39d1b..1c612884 100644 --- a/bindings/solv.i +++ b/bindings/solv.i @@ -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__; diff --git a/doc/libsolv-bindings.3 b/doc/libsolv-bindings.3 index b2d8d4cd..e07b229b 100644 --- a/doc/libsolv-bindings.3 +++ b/doc/libsolv-bindings.3 @@ -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 diff --git a/doc/libsolv-bindings.txt b/doc/libsolv-bindings.txt index f1834ff7..dcbc2d17 100644 --- a/doc/libsolv-bindings.txt +++ b/doc/libsolv-bindings.txt @@ -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);