Skip to content

Commit

Permalink
add gyp support for compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
yyfrankyy committed Nov 6, 2012
1 parent 89e4a63 commit 88c9f80
Show file tree
Hide file tree
Showing 11 changed files with 2,289 additions and 12 deletions.
34 changes: 26 additions & 8 deletions binding.cc
Expand Up @@ -21,16 +21,14 @@
#include <v8.h> #include <v8.h>
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include <city.h> #include "city.h"
#ifdef __SSE4_2__
#include "citycrc.h"
#endif


#define MAX_64_HASH_LEN 21 #define MAX_64_HASH_LEN 21
#define MAX_128_HASH_LEN MAX_64_HASH_LEN*2 #define MAX_128_HASH_LEN MAX_64_HASH_LEN*2


// weak symbols.
extern uint128 CityHashCrc128(const char *s, size_t len) __attribute__((weak));
extern uint128 CityHashCrc128WithSeed(const char *s, size_t len, uint128 seed) __attribute__((weak));
extern void CityHashCrc256(const char *s, size_t len, uint64 *result) __attribute__((weak));

using namespace v8; using namespace v8;


inline uint32 Uint64High32(const uint64 &x) { inline uint32 Uint64High32(const uint64 &x) {
Expand Down Expand Up @@ -190,7 +188,7 @@ Local<Object>
objectify_hashs(const uint64 hashs[], size_t size) { objectify_hashs(const uint64 hashs[], size_t size) {
Local<Object> ret = Array::New(size); Local<Object> ret = Array::New(size);


for(int i=0; i<size; i++) { for(size_t i=0; i<size; i++) {
uint64 hash = hashs[i]; uint64 hash = hashs[i];
ret->Set(i, objectify_hash(hash)); ret->Set(i, objectify_hash(hash));
} }
Expand Down Expand Up @@ -284,6 +282,7 @@ node_CityHash128(const Arguments& args) {
Handle<Value> Handle<Value>
node_CityHashCrc128(const Arguments& args) { node_CityHashCrc128(const Arguments& args) {
HandleScope scope; HandleScope scope;
#ifdef __SSE4_2__


int args_len = args.Length(); int args_len = args.Length();
if(args_len == 0 || args_len > 2) { if(args_len == 0 || args_len > 2) {
Expand Down Expand Up @@ -312,13 +311,16 @@ node_CityHashCrc128(const Arguments& args) {
} }


return scope.Close(objectify_hash(hash)); return scope.Close(objectify_hash(hash));
#else
return ThrowException(String::New("SSE4.2 is not supported for your platform"));
#endif
} }


Handle<Value> Handle<Value>
node_CityHashCrc256(const Arguments& args) { node_CityHashCrc256(const Arguments& args) {
HandleScope scope; HandleScope scope;


printf("handle"); #ifdef __SSE4_2__
int args_len = args.Length(); int args_len = args.Length();
if(args_len != 1) { if(args_len != 1) {
return ThrowException(String::New("Invalid arguments.")); return ThrowException(String::New("Invalid arguments."));
Expand All @@ -336,8 +338,23 @@ node_CityHashCrc256(const Arguments& args) {
CityHashCrc256(str, len, hashs); CityHashCrc256(str, len, hashs);


return scope.Close(objectify_hashs(hashs, 4)); return scope.Close(objectify_hashs(hashs, 4));
#else
return ThrowException(String::New("SSE4.2 is not supported for your platform"));
#endif
} }


Handle<Value>
node_isCrcSupported(const Arguments& args) {
HandleScope scope;

#ifdef __SSE4_2__
return scope.Close(Boolean::New(true));
#else
return scope.Close(Boolean::New(false));
#endif
}


extern "C" void extern "C" void
init (Handle<Object> target) { init (Handle<Object> target) {
HandleScope scope; HandleScope scope;
Expand All @@ -347,4 +364,5 @@ init (Handle<Object> target) {
target->Set(String::New("hash128"), FunctionTemplate::New(node_CityHash128)->GetFunction()); target->Set(String::New("hash128"), FunctionTemplate::New(node_CityHash128)->GetFunction());
target->Set(String::New("crc128"), FunctionTemplate::New(node_CityHashCrc128)->GetFunction()); target->Set(String::New("crc128"), FunctionTemplate::New(node_CityHashCrc128)->GetFunction());
target->Set(String::New("crc256"), FunctionTemplate::New(node_CityHashCrc256)->GetFunction()); target->Set(String::New("crc256"), FunctionTemplate::New(node_CityHashCrc256)->GetFunction());
target->Set(String::New("isCrcSupported"), FunctionTemplate::New(node_isCrcSupported)->GetFunction());
} }
12 changes: 12 additions & 0 deletions binding.gyp
@@ -0,0 +1,12 @@
{
"targets": [
{
"target_name": "node-cityhash",
"include_dirs": ["cityhash/"],
"dependencies": ["cityhash/cityhash.gyp:libcityhash"],
"sources": [
"binding.cc"
]
}
]
}
14 changes: 14 additions & 0 deletions cityhash/Makefile.am
@@ -0,0 +1,14 @@
# library
lib_LTLIBRARIES = libcityhash.la
libcityhash_la_SOURCES = city.cc
if SSE42
include_HEADERS = city.h citycrc.h
else
include_HEADERS = city.h
endif

# test
cityhash_unittest_SOURCES = city-test.cc
cityhash_unittest_LDADD = libcityhash.la
TESTS = cityhash_unittest
noinst_PROGRAMS = $(TESTS)
1,335 changes: 1,335 additions & 0 deletions cityhash/city-test.cc

Large diffs are not rendered by default.

0 comments on commit 88c9f80

Please sign in to comment.