This commit is contained in:
Evan Weaver 2008-03-30 18:49:43 +00:00
Родитель a9ede7260c
Коммит 4d3883d744
6 изменённых файлов: 2154 добавлений и 131 удалений

Просмотреть файл

@ -18,12 +18,18 @@ end
dir_config 'rlibmemcached'
# XXX There's probably a better way to do this
unless find_library 'memcached', 'memcached_server_add', *ENV['LD_LIBRARY_PATH'].to_s.split(":")
raise "shared library 'libmemcached' not found"
end
raise "shared library 'libmemcached' not found" unless
find_library('memcached', 'memcached_server_add', *ENV['LD_LIBRARY_PATH'].to_s.split(":"))
['libmemcached/memcached.h', 'libmemcached/memcached_constants.h'].each do |include|
raise "header file '#{include}' not found" unless find_header include, *ENV['INCLUDE_PATH'].to_s.split(":")
[
'libmemcached/memcached.h',
'libmemcached/memcached_constants.h',
'libmemcached/memcached_storage.h',
'libmemcached/memcached_result.h',
'libmemcached/memcached_server.h'
].each do |header|
raise "header file '#{include}' not found" unless
find_header(header, *ENV['INCLUDE_PATH'].to_s.split(":"))
end
create_makefile 'rlibmemcached'

Просмотреть файл

@ -1,7 +1,6 @@
%module rlibmemcached
%{
#include <libmemcached/memcached.h>
#include <libmemcached/memcached_constants.h>
%}
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) memcached_st;
@ -17,14 +16,7 @@
%apply unsigned short { uint8_t };
%apply unsigned int { uint16_t };
%apply unsigned long { uint32_t flags, uint32_t offset };
/* %apply unsigned long long { uint64_t cas }; */
// For behavior's set interface
%typemap(in) (void *data) {
int value = FIX2INT($input);
// printf("%d\n", value);
$1 = &value;
};
%apply unsigned long long {uint64_t data }; /* uint64_t cas, */
// Array of strings map for multiget
%typemap(in) (char **keys, size_t *key_length, unsigned int number_of_keys) {
@ -55,6 +47,14 @@
(char *value, size_t value_length)
};
// Key strings with same master key
// XXX This will have to go once people start doing client-side replication and actually need to set the master key
%typemap(in) (char *master_key, size_t master_key_length, char *key, size_t key_length) {
$3 = $1 = STR2CSTR($input);
$4 = $2 = (size_t) RSTRING($input)->len;
};
//// Output maps
/* %apply unsigned long long { uint64_t cas }; */
@ -89,13 +89,17 @@
free($1);
};
//// SWIG includes, for functions, constants, and structs
%include "/opt/local/include/libmemcached/memcached.h"
%include "/opt/local/include/libmemcached/memcached_constants.h"
%include "/opt/local/include/libmemcached/memcached_storage.h"
%include "/opt/local/include/libmemcached/memcached_result.h"
%include "/opt/local/include/libmemcached/memcached_server.h"
//// Custom C functions
// Namespace and validate key. We could avoid several more dispatches and allocations if we called this from the libmemcached wrappers directly.
VALUE ns(char *namespace, size_t namespace_length, char *key, size_t key_length);
%{
VALUE ns(char *namespace, size_t namespace_length, char *key, size_t key_length) {
@ -120,6 +124,15 @@ VALUE ns(char *namespace, size_t namespace_length, char *key, size_t key_length)
//// Manual wrappers
// Opaque uint64; needed as a placeholder for the send functions
uint64_t zero();
%{
uint64_t zero() {
uint64_t zero = 0;
return zero;
};
%}
// Single get. SWIG likes to use SWIG_FromCharPtr instead of SWIG_FromCharPtrAndSize because
// of the retval/argout split, so it truncates return values with \0 in them.
VALUE memcached_get_rvalue(memcached_st *ptr, char *key, size_t key_length, uint32_t *flags, memcached_return *error);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -41,11 +41,7 @@ class Memcached
end
# STDERR.puts "Setting #{behavior}:#{b_id} => #{value}:#{v_id}"
unless value == false
# XXX Setting false still turns on the behavior; maybe a Lib bug
Lib.memcached_behavior_set(@struct, b_id, v_id)
end
Lib.memcached_behavior_set(@struct, b_id, v_id)
end
end

Просмотреть файл

@ -5,6 +5,8 @@ The Memcached client class.
class Memcached
FLAGS = 0x0
UINT64 = Lib::zero() # SWIG::TYPE_p_uint64_t.allocate
DEFAULTS = {
:hash => :default,
@ -171,7 +173,7 @@ Please note that when non-blocking IO is enabled, setter and deleter methods do
def set(key, value, timeout=0, marshal=true)
value = marshal ? Marshal.dump(value) : value.to_s
check_return_code(
Lib.memcached_set(@struct, Lib.ns(@namespace, key), value, timeout, FLAGS)
Lib.memcached_send(@struct, Lib.ns(@namespace, key), value, timeout, FLAGS, UINT64, Lib::SET_OP)
)
end
@ -179,7 +181,7 @@ Please note that when non-blocking IO is enabled, setter and deleter methods do
def add(key, value, timeout=0, marshal=true)
value = marshal ? Marshal.dump(value) : value.to_s
check_return_code(
Lib.memcached_add(@struct, Lib.ns(@namespace, key), value, timeout, FLAGS)
Lib.memcached_send(@struct, Lib.ns(@namespace, key), value, timeout, FLAGS, UINT64, Lib::ADD_OP)
)
end
@ -210,7 +212,7 @@ Please note that when non-blocking IO is enabled, setter and deleter methods do
def replace(key, value, timeout=0, marshal=true)
value = marshal ? Marshal.dump(value) : value.to_s
check_return_code(
Lib.memcached_replace(@struct, Lib.ns(@namespace, key), value, timeout, FLAGS)
Lib.memcached_send(@struct, Lib.ns(@namespace, key), value, timeout, FLAGS, UINT64, Lib::REPLACE_OP)
)
end
@ -220,7 +222,7 @@ Please note that when non-blocking IO is enabled, setter and deleter methods do
def append(key, value)
# Requires memcached 1.2.4
check_return_code(
Lib.memcached_append(@struct, Lib.ns(@namespace, key), value.to_s, IGNORED, FLAGS)
Lib.memcached_send(@struct, Lib.ns(@namespace, key), value.to_s, IGNORED, FLAGS, UINT64, Lib::APPEND_OP)
)
end
@ -228,7 +230,7 @@ Please note that when non-blocking IO is enabled, setter and deleter methods do
def prepend(key, value)
# Requires memcached 1.2.4
check_return_code(
Lib.memcached_prepend(@struct, Lib.ns(@namespace, key), value.to_s, IGNORED, FLAGS)
Lib.memcached_send(@struct, Lib.ns(@namespace, key), value.to_s, IGNORED, FLAGS, UINT64, Lib::PREPEND_OP)
)
end
@ -246,7 +248,7 @@ Please note that when non-blocking IO is enabled, setter and deleter methods do
value = marshal ? Marshal.dump(value) : value.to_s
check_return_code(
Lib.memcached_cas(@struct, Lib.ns(@namespace, key), value, timeout, FLAGS, @struct.result.cas)
Lib.memcached_send(@struct, Lib.ns(@namespace, key), value, timeout, FLAGS, @struct.result.cas, Lib::CAS_OP)
)
end

Просмотреть файл

@ -104,12 +104,11 @@ class MemcachedTest < Test::Unit::TestCase
cache.servers
cache.destroy
Reversed
XXX Fails due to libmemcached 0.16 bug
cache = Memcached.new(@servers.sort.reverse)
assert_equal @servers.sort.reverse,
cache.servers
cache.destroy
# Reversed
cache = Memcached.new(@servers.sort.reverse)
assert_equal @servers.sort.reverse,
cache.servers
cache.destroy
# Reversed with sort_hosts
cache = Memcached.new(@servers.sort.reverse,
@ -543,12 +542,14 @@ class MemcachedTest < Test::Unit::TestCase
assert_nothing_raised do
cache.set key, @value
end
ret = Rlibmemcached.memcached_set(
ret = Rlibmemcached.memcached_send(
cache.instance_variable_get("@struct"),
"#{@namespace}#{key}",
@marshalled_value,
0,
Memcached::FLAGS
Memcached::FLAGS,
Memcached::UINT64,
Rlibmemcached::SET_OP
)
assert_equal 31, ret
end
@ -557,12 +558,14 @@ class MemcachedTest < Test::Unit::TestCase
assert_nothing_raised do
@nb_cache.set key, @value
end
ret = Rlibmemcached.memcached_set(
ret = Rlibmemcached.memcached_send(
@nb_cache.instance_variable_get("@struct"),
"#{@namespace}#{key}",
@marshalled_value,
0,
Memcached::FLAGS
Memcached::FLAGS,
Memcached::UINT64,
Rlibmemcached::SET_OP
)
assert_equal 31, ret
end