Skip to content

Commit

Permalink
bindings: many improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rhash committed Sep 14, 2011
1 parent c29c463 commit 3be91ea
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 23 deletions.
49 changes: 49 additions & 0 deletions bindings/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
MAKE = make
RUBY = ruby
PERL = /usr/bin/perl
DESTDIR =
PREFIX = /usr/local
PERL_OPTIMIZE = -O2 -g -Wall

all: configure build test
configure: configure-ruby configure-perl
build: build-java build-perl build-ruby
test: test-java test-perl test-ruby
install: install-ruby install-perl
clean: distclean

configure-perl:
cd perl && perl Makefile.PL INSTALLDIRS=vendor

configure-ruby:
$(RUBY) -C ruby extconf.rb

build-java:
$(MAKE) -C java/ jar jar-symlink jni javadoc

build-perl:
$(MAKE) -C perl OPTIMIZE="$(PERL_OPTIMIZE)"

build-ruby:
$(MAKE) -C ruby

test-java:
$(MAKE) -C java test

test-perl:
$(MAKE) -C perl test

test-ruby:
$(RUBY) -C ruby test_rhash.rb

install-ruby:
$(MAKE) -C ruby install DESTDIR=$(DESTDIR) sitedir=$(DESTDIR)/usr/lib/ruby

install-perl:
$(MAKE) -C perl install DESTDIR=$(DESTDIR)
# $(MAKE) -C perl install DESTDIR=$(DESTDIR) PREFIX=$(PREFIX) SITEPREFIX=$(PREFIX)

distclean:
$(MAKE) -C java distclean
[ ! -f ruby/Makefile ] || $(MAKE) -C ruby distclean
[ ! -f perl/Makefile ] || $(MAKE) -C perl distclean
5 changes: 4 additions & 1 deletion bindings/java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ JAVADOC = javadoc
JAVAH = javah
JAR = jar

VERSION = $(shell sed -e 's/\(.*\)"\(.*\)"\(.*\)/\2/' ../../version.h)
VERSION = $(shell sed -e 's/.*"\(.*\)".*/\1/' ../../version.h)

JAVASRC_DIR = src
CSRC_DIR = native
Expand All @@ -42,6 +42,9 @@ jar: compile-classes
mkdir -p $(DEST_DIR)
$(JAR) cf $(JARFILE) -C $(CLASSES_DIR) org/

jar-symlink:
ln -s rhash-$(VERSION).jar $(DEST_DIR)/rhash.jar

compile-classes:
mkdir -p $(CLASSES_DIR)
$(JAVAC) -d $(CLASSES_DIR) -sourcepath $(JAVASRC_DIR) `find ${JAVASRC_DIR} -name '*.java'`
Expand Down
6 changes: 4 additions & 2 deletions bindings/java/native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

CC = gcc
CFLAGS = -g -O2
LDFLAGS = -lrhash
ALLCFLAGS = $(CFLAGS) -fPIC
LIBRHASH_INC =
LIBRHASH_LD =
LDFLAGS = -lrhash $(LIBRHASH_LD)
ALLCFLAGS = $(CFLAGS) $(LIBRHASH_INC) -fPIC

#Platform dependent
JNI_INCLUDES = /usr/lib/jvm/default-java/include
Expand Down
7 changes: 7 additions & 0 deletions bindings/perl/MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Makefile.PL
Rhash.pm
Rhash.xs
t/1test_hash_calculation.t
t/2test_static_functions.t
t/3test_all_hash_functions.t
typemap
17 changes: 11 additions & 6 deletions bindings/perl/Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use strict;
use warnings;

use ExtUtils::MakeMaker;

my $libs = '-lrhash';
my $inc = '';
$inc = $ENV{'LIBRHASH_INC'} if defined($ENV{'LIBRHASH_INC'});
if(defined($ENV{'LIBRHASH_LD'}) && $ENV{'LIBRHASH_LD'} =~ /^-L/) {
$libs = $ENV{'LIBRHASH_LD'} . ' ' . $libs;
}

# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Rhash',
AUTHOR => 'Aleksey Kravchenko',
AUTHOR => 'Aleksey Kravchenko',
VERSION_FROM => 'Rhash.pm', # finds $VERSION
LIBS => ['-lrhash'],
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => '', # e.g., '-I/usr/include/other'
LIBS => [ $libs ],
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => $inc, # e.g., '-I/usr/include/other'
);

8 changes: 2 additions & 6 deletions bindings/perl/Rhash.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ sub new
my $context = rhash_init(scalar($hash_id)) or return undef;
my $self = {
context => $context,
finalized => 0
};
return bless $self;
}
Expand Down Expand Up @@ -120,15 +119,13 @@ sub final($)
{
my $self = shift;
rhash_final($self->{context});
$self->{finalized} = 1;
return $self;
}

sub reset($)
{
my $self = shift;
rhash_reset($self->{context});
$self->{finalized} = 0;
return $self;
}

Expand Down Expand Up @@ -161,7 +158,6 @@ sub hash($;$$)
my $self = shift;
my $hash_id = scalar(shift) || 0;
my $print_flags = scalar(shift) || RHPR_DEFAULT;
$self->final() if !$self->{finalized};
return rhash_print($self->{context}, $hash_id, $print_flags);
}

Expand Down Expand Up @@ -370,11 +366,11 @@ Returns the hash mask, the $rhash object was constructed with.
=head1 FORMATING HASH VALUE
=over
Computed hash can be formated as a hexadecimal string (in the forward or
reverse byte order), a base32/base64-encoded string or as raw binary data.
=over
=item $rhash->hash( $hash_id )
Returns the hash string in the default format,
Expand Down
14 changes: 7 additions & 7 deletions bindings/perl/Rhash.xs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ rhash_msg_raw(hash_id, message)
PROTOTYPE: $$
PREINIT:
STRLEN length;
char out[264];
unsigned char out[264];
int res;
INPUT:
char* message = SvPV(ST(1), length);
Expand All @@ -63,7 +63,7 @@ rhash_msg_raw(hash_id, message)
if(res < 0) {
croak("%s: %s", "rhash_msg_raw", strerror(errno));
}
RETVAL = newSVpv(out, rhash_get_digest_size(hash_id));
RETVAL = newSVpv((char*)out, rhash_get_digest_size(hash_id));
OUTPUT:
RETVAL

Expand All @@ -74,14 +74,14 @@ rhash_file_raw(hash_id, filepath)
PROTOTYPE: $$
PREINIT:
int res;
char out[264];
unsigned char out[264];
CODE:
verify_single_bit_hash_id(hash_id, cv);
res = rhash_file(hash_id, filepath, out);
if(res < 0) {
croak("%s: %s: %s", "rhash_file", filepath, strerror(errno));
}
RETVAL = newSVpv(out, rhash_get_digest_size(hash_id));
RETVAL = newSVpv((char*)out, rhash_get_digest_size(hash_id));
OUTPUT:
RETVAL

Expand Down Expand Up @@ -220,7 +220,7 @@ raw2hex(bytes)
PREINIT:
STRLEN size;
INPUT:
unsigned char * bytes = SvPV(ST(0), size);
unsigned char * bytes = (unsigned char*)SvPV(ST(0), size);
CODE:
RETVAL = allocate_string_buffer(size * 2);
rhash_print_bytes(SvPVX(RETVAL), bytes, size, RHPR_HEX);
Expand All @@ -233,7 +233,7 @@ raw2base32(bytes)
PREINIT:
STRLEN size;
INPUT:
unsigned char * bytes = SvPV(ST(0), size);
unsigned char * bytes = (unsigned char*)SvPV(ST(0), size);
CODE:
RETVAL = allocate_string_buffer(BASE32_LENGTH(size));
rhash_print_bytes(SvPVX(RETVAL), bytes, size, RHPR_BASE32);
Expand All @@ -246,7 +246,7 @@ raw2base64(bytes)
PREINIT:
STRLEN size;
INPUT:
unsigned char * bytes = SvPV(ST(0), size);
unsigned char * bytes = (unsigned char*)SvPV(ST(0), size);
CODE:
RETVAL = allocate_string_buffer(BASE64_LENGTH(size));
rhash_print_bytes(SvPVX(RETVAL), bytes, size, RHPR_BASE64);
Expand Down
7 changes: 6 additions & 1 deletion bindings/ruby/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require 'mkmf'

have_header('rhash/rhash.h')
if ENV['LIBRHASH_INC'] and ENV['LIBRHASH_LD']
$CFLAGS += ENV['LIBRHASH_INC']
$LDFLAGS += ' ' + ENV['LIBRHASH_LD']
else
have_header('rhash/rhash.h')
end
$LDFLAGS += ' -lrhash'

dir_config('rhash')
Expand Down
1 change: 1 addition & 0 deletions librhash/rhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ RHASH_API void rhash_reset(rhash ctx)
assert(info->init != NULL);
info->init(ectx->vector[i].context);
}
ectx->flags &= ~RCTX_FINALIZED; /* clear finalized state */
}

/**
Expand Down

0 comments on commit 3be91ea

Please sign in to comment.