Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.project
.settings
.DS_Store
.vscode/
*/.DS_Store
gcovr-output/
gcov-data/
Expand Down Expand Up @@ -74,6 +75,7 @@ libtool
doxy.conf
doxygen_warnings.txt
main_page.doxygen
dmr_memory_cache

## libdap specific files
gl/*.h
Expand Down Expand Up @@ -201,6 +203,14 @@ unit-tests/GridTest
unit-tests/IsDap4ProjectedTest
unit-tests/util_mitTest
unit-tests/MarshallerFutureTest
unit-tests/BaseTypeTest
unit-tests/ConstraintEvaluatorTest
unit-tests/D4StreamRoundTripTest
unit-tests/DAPCache3Test
unit-tests/ErrorTest
unit-tests/MarshallerThreadTest
unit-tests/dmr_memory_cache
unit-tests/dapcache3test.*

d4_ce/unit-tests/D4ConstraintEvaluatorTest
d4_ce/unit-tests/test_config.h
Expand Down
55 changes: 18 additions & 37 deletions DAPCache3.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,18 @@
#ifndef DAPCache3_h_
#define DAPCache3_h_ 1

// #include <algorithm>
#include <list>
#include <map>
#include <string>
// #include <sstream>

#include "DapObj.h"

#if 0
#include "BESDebug.h"
#include "BESObj.h"

class BESKeys;
#endif

namespace libdap {

// These typedefs are used to record information about the files in the cache.
// See DAPCache3.cc and look at the purge() method.
typedef struct {
string name;
std::string name;
unsigned long long size;
time_t time;
} cache_entry;
Expand Down Expand Up @@ -80,25 +71,19 @@ typedef std::list<cache_entry> CacheFiles;
* on the cache info file must only be called when the lock has been obtained.
*/
class DAPCache3 : public libdap::DapObj {

private:
static DAPCache3 *d_instance;

static const char DAP_CACHE_CHAR = '#';

string d_cache_dir; /// pathname of the cache directory
string d_prefix; /// tack this on the front of cache file name
std::string d_cache_dir; /// pathname of the cache directory
std::string d_prefix; /// tack this on the front of cache file name

/// How many megabytes can the cache hold before we have to purge
unsigned long long d_max_cache_size_in_bytes;
// When we purge, how much should we throw away. Set in the ctor to 80% of the max size.
unsigned long long d_target_size;
#if 0
// This class implements a singleton, so the constructor is hidden.
BESCache3(BESKeys *keys, const string &cache_dir_key, const string &prefix_key, const string &size_key);
#endif
// Testing
DAPCache3(const string &cache_dir, const string &prefix, unsigned long long size);
DAPCache3(const std::string &cache_dir, const std::string &prefix, unsigned long long size);

// Suppress the assignment operator and default copy ctor, ...
DAPCache3();
Expand All @@ -111,47 +96,43 @@ class DAPCache3 : public libdap::DapObj {
unsigned long long m_collect_cache_dir_info(CacheFiles &contents);

/// Name of the file that tracks the size of the cache
string d_cache_info;
std::string d_cache_info;
int d_cache_info_fd;

void m_record_descriptor(const string &file, int fd);
int m_get_descriptor(const string &file);
void m_record_descriptor(const std::string &file, int fd);
int m_get_descriptor(const std::string &file);

// map that relates files to the descriptor used to obtain a lock
typedef std::map<string, int> FilesAndLockDescriptors;
typedef std::map<std::string, int> FilesAndLockDescriptors;
FilesAndLockDescriptors d_locks;

// Life-cycle control
virtual ~DAPCache3() {}
~DAPCache3() override {}
static void delete_instance();

public:
static DAPCache3 *get_instance(const string &cache_dir, const string &prefix, unsigned long long size);
static DAPCache3 *get_instance(const std::string &cache_dir, const std::string &prefix, unsigned long long size);
static DAPCache3 *get_instance();

string get_cache_file_name(const string &src, bool mangle = true);
std::string get_cache_file_name(const std::string &src, bool mangle = true);

virtual bool create_and_lock(const string &target, int &fd);
virtual bool get_read_lock(const string &target, int &fd);
virtual bool create_and_lock(const std::string &target, int &fd);
virtual bool get_read_lock(const std::string &target, int &fd);
virtual void exclusive_to_shared_lock(int fd);
virtual void unlock_and_close(const string &target);
virtual void unlock_and_close(const std::string &target);
virtual void unlock_and_close(int fd);

virtual void lock_cache_write();
virtual void lock_cache_read();
virtual void unlock_cache();

virtual unsigned long long update_cache_info(const string &target);
virtual unsigned long long update_cache_info(const std::string &target);
virtual bool cache_too_big(unsigned long long current_size) const;
virtual unsigned long long get_cache_size();
virtual void update_and_purge(const string &new_file);
virtual void purge_file(const string &file);

#if 0
static BESCache3 *get_instance(BESKeys *keys, const string &cache_dir_key, const string &prefix_key, const string &size_key);
#endif
virtual void update_and_purge(const std::string &new_file);
virtual void purge_file(const std::string &file);

void dump(ostream &strm) const override;
void dump(std::ostream &strm) const override;
};

} // namespace libdap
Expand Down
3 changes: 0 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ dmr_memory_cache_SOURCES = dmr_mcache_test.cc
dmr_memory_cache_LDADD = libdapclient.la libdap.la
dmr_memory_cache_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/http_dap $(CURL_CFLAGS)



LEX_YACC_EXTRA = das.lex das.yy dds.lex dds.yy ce_expr.lex ce_expr.yy \
Error.lex Error.yy

Expand Down Expand Up @@ -132,7 +130,6 @@ cccc:
# dist-hook:
# if test -n "$$VERSION"; then cat $$VERSION NEWS > NEWS.tmp; mv NEWS.tmp NEWS; fi


# Build linux RPMs. Use the environment variable 'RPM_OPTIONS' to pass in
# extra options like --nodeps and --macros

Expand Down
31 changes: 11 additions & 20 deletions parser-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ int check_uint32(const char *val, unsigned int &v) {
return FALSE;
}
// See above.
else if (tmp > DODS_UINT_MAX) {
if (tmp > DODS_UINT_MAX) {
return FALSE;
} else {
v = (unsigned int)tmp;
return TRUE;
}

v = (unsigned int)tmp;
return TRUE;
}

int check_int64(const char *val) {
Expand All @@ -362,19 +362,8 @@ int check_int64(const char *val) {
if (errno == ERANGE) {
return FALSE;
}
#if 0
// This could be combined with the above, or course, but I'm making it
// separate to highlight the test. On 64-bit linux boxes 'long' may be
// 64-bits and so 'v' can hold more than a DODS_INT32. jhrg 3/23/10
//
// Removed - Coverity says it can never be false. Makes sense. jhrg 5/10/16
else if (v <= DODS_LLONG_MAX && v >= DODS_LLONG_MIN) {
return FALSE;
}
#endif
else {
return TRUE;
}

return TRUE;
}

int check_uint64(const char *val) {
Expand All @@ -398,11 +387,13 @@ int check_uint64(const char *val) {

if (errno == ERANGE) {
return FALSE;
} else if (v > DODS_ULLONG_MAX) { // 2^61
}

if (v > DODS_ULLONG_MAX) { // 2^61
return FALSE;
} else {
return v;
}

return TRUE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... That was an actual bug that the new tests caught.

}

// Check first for system errors (like numbers so small they convert
Expand Down
2 changes: 1 addition & 1 deletion retired/VCPP/BeforeInstall.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
In addition to installing libdap 3.8.2, this will also install other run-time libraries libdap uses. However, this will not install the software need to compile our source code on the Windows XP platform. For more information about building our software from source, see http://scm.opendap.org/trac/wiki/XP or contact us at support at opendap.org.
In addition to installing libdap 3.8.2, this will also install other run-time libraries libdap uses. However, this will not install the software need to compile our source code on the Windows XP platform. For more information about building our software from source, see http://scm.opendap.org/trac/wiki/XP or contact us at support at opendap.org.
33 changes: 33 additions & 0 deletions unit-tests/ArrayTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class ArrayTest : public TestFixture {
CPPUNIT_TEST(duplicate_cardinal_test);
CPPUNIT_TEST(duplicate_string_test);
CPPUNIT_TEST(duplicate_structure_test);
CPPUNIT_TEST(zero_length_array_test);
CPPUNIT_TEST(deep_copy_cardinal_test);

CPPUNIT_TEST_SUITE_END();

Expand Down Expand Up @@ -324,6 +326,37 @@ class ArrayTest : public TestFixture {
a = 0;
}

void zero_length_array_test() {
Int16 i16("i16");
Array a("zero_len", &i16);
a.append_dim(0, "empty");
CPPUNIT_ASSERT_EQUAL(0, a.length());
CPPUNIT_ASSERT_EQUAL((int64_t)0, a.length_ll());
CPPUNIT_ASSERT_EQUAL((unsigned int)0, a.width());
CPPUNIT_ASSERT_EQUAL((int64_t)0, a.width_ll());
}

void deep_copy_cardinal_test() {
Int16 i16("i16");
Array a1("a1", &i16);
a1.append_dim(4, "d0");

dods_int16 v1[4] = {10, 20, 30, 40};
a1.set_value(v1, 4);

Array a2(a1);

dods_int16 v2[4] = {1, 2, 3, 4};
a1.set_value(v2, 4);

dods_int16 out[4] = {0, 0, 0, 0};
a2.value(out);
CPPUNIT_ASSERT(out[0] == 10);
CPPUNIT_ASSERT(out[1] == 20);
CPPUNIT_ASSERT(out[2] == 30);
CPPUNIT_ASSERT(out[3] == 40);
}

void duplicate_string_test() {
Array::Dim_iter i = d_string->dim_begin();
CPPUNIT_ASSERT(d_string->dimension_size(i) == 4);
Expand Down
Loading