Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- added util.h

- applied Lux::IO::clean_data() to return value
  • Loading branch information...
commit 6aec3f6b30b7c92639a0aff2e11c673553c8a2be 1 parent 6696e4c
@kentaro authored
View
15 src/luxio.cpp
@@ -1,4 +1,5 @@
#include "luxio.h"
+#include "util.h"
bool Omnivore::Storage::LuxIO::open (std::string name) {
Lux::IO::Btree* db = new Lux::IO::Btree(Lux::IO::NONCLUSTER);
@@ -16,17 +17,19 @@ void Omnivore::Storage::LuxIO::free () {
return delete _storage;
}
-Omnivore::Storage::data_t *Omnivore::Storage::LuxIO::get (const void *key, int key_size) {
+Omnivore::Storage::data_t
+Omnivore::Storage::LuxIO::get (const void *key, int key_size) {
Lux::IO::data_t *value = _storage->get(key, key_size);
- Omnivore::Storage::data_t *result;
+ Omnivore::Storage::data_t result;
if (value != NULL) {
- result->data = value->data;
- result->size = value->size;
+ result.data = Omnivore::duplicate_memory(value->data, value->size);
+ result.size = value->size;
}
else {
- result->data = NULL;
- result->size = 0;
+ result.data = NULL;
+ result.size = 0;
}
+ _storage->clean_data(value);
return result;
}
View
2  src/luxio.h
@@ -13,7 +13,7 @@ namespace Omnivore {
bool open (std::string name);
bool close ();
- Omnivore::Storage::data_t *
+ Omnivore::Storage::data_t
get (const void *key, int key_size);
bool put (const void *key, int key_size, const void *value, int value_size);
bool del (const void *key, int key_size);
View
2  src/storage.h
@@ -21,7 +21,7 @@ namespace Omnivore {
virtual bool open (std::string name) = 0;
virtual bool close () = 0;
- virtual Omnivore::Storage::data_t *
+ virtual Omnivore::Storage::data_t
get (const void *key, int key_size) = 0;
virtual bool put (const void *key, int key_size, const void *value, int value_size) = 0;
virtual bool del (const void *key, int key_size) = 0;
View
15 src/util.h
@@ -0,0 +1,15 @@
+#ifndef OMNIVORE_UTIL_H
+#define OMNIVORE_UTIL_H
+
+#include <cstdlib>
+
+namespace Omnivore {
+ void *duplicate_memory(const void *ptr, int size) {
+ void *dupped;
+ if (!(dupped = malloc(size))) return 0;
+ memcpy(dupped, ptr, size);
+ return dupped;
+ }
+}
+
+#endif
View
4 test/luxio.cpp
@@ -9,9 +9,9 @@ int main () {
db->open("test");
db->put(key.c_str(), key.length(), value.c_str(), value.length());
- Omnivore::Storage::data_t *result = db->get(key.c_str(), key.length());
+ Omnivore::Storage::data_t result = db->get(key.c_str(), key.length());
std::cout << "key: " << key << std::endl;
- std::cout << "val: " << (char *)result->data << std::endl;
+ std::cout << "val: " << (char *)result.data << std::endl;
db->close();
db->free();
Please sign in to comment.
Something went wrong with that request. Please try again.