Skip to content

Commit

Permalink
Squashed 'externals/coda-oss/' changes from d5dafc3..11e1260
Browse files Browse the repository at this point in the history
11e1260 Merge pull request ngageoint#339 from mdaus/fileStream-cleanup
7c34d0a style fix
4ea8a1c Fixing line endings
02eb685 Fix clean up in fileStreamOS destructors
37b85e7 Merge pull request ngageoint#338 from mdaus/fix_bad_unittest_condition
08e98cb Fix incorrect range check. Seconds are floating-point values, so, e.g., 59.23 should be valid.
480de23 Merge pull request ngageoint#337 from mdaus/jenkins-debug
d257f02 Reformat README
e3a0671 Document error in README
c1f065c Remove Python2-specific function
5721dd1 Merge pull request ngageoint#336 from mdaus/getNumpyArraySize
02b1900 Address memory leak
2257341 Proper signature for main
9cab375 Add getNumElements to numpyutils
9cc1dae Merge pull request ngageoint#331 from mdaus/scratch_memory_unittest_fix
0a0b800 Merge pull request ngageoint#335 from mdaus/const_data_to_numpy_array
63be556 Allow converting a const buffer to a numpy array
473f206 Merge pull request ngageoint#332 from mdaus/pass_swig_home
37fb901 Merge pull request ngageoint#333 from mdaus/8_bit_integer_to_string
ae40302 mDayOfWeek for Saturday should be 7, not 0
fbe556c Use proper offset when converting to tm_wday
723d901 Treat 8-bit integers as numbers rather than characters when converting to string
9a3ef58 Throw if attempting to release key not in ScratchMemory
eda690e Push back element before getting iterator
321af0c Allow specifying custom swig install
6e28a86 Add <algorithm> header for std::find
5ea6906 Fix incorrect checking in unittest

git-subtree-dir: externals/coda-oss
git-subtree-split: 11e126064f6891ca9f74e44347ae010a6cd1ae43
  • Loading branch information
vkrishna1997 committed Nov 26, 2019
1 parent 498725f commit fbdbe40
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 69 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ Enabling a debugger
`-g` and its variants can be achieved at configure time using the
`--enable-debugging` switch at waf configure time

SVN Issues
----------
Please DONT POLLUTE SVN! Don't put binaries in there,
unless you have a very good reason.
Common Errors
-------------
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Problem: Python is unable to find its `modules` directory, necessary for using the Python C API.

Solution: Set the `PYTHONHOME` environment variable. On Windows, this may look like:

set PYTHONHOME=C:\ProgramData\Anaconda3\
7 changes: 6 additions & 1 deletion build/swig.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ def options(opt):
default='3.0.0', help='Specify the minimum swig version')
opt.add_option('--require-swig', action='store_true', dest='require_swig',
help='Require swig (configure option)', default=False)
opt.add_option('--with-swig-home', action='store', dest='swig_home',
help='Bin directory of swig installation, e.g. '
'/swig/install/bin')
opt.add_option('--python-version-agnostic', action='store_true',
dest='pyver_agnostic',
help='The default behavior for generated Python code is to '
Expand All @@ -208,7 +211,9 @@ def options(opt):

def configure(conf):
if Options.options.swig:
swig = conf.find_program('swig', var='SWIG', mandatory=Options.options.require_swig)
swig = conf.find_program('swig', var='SWIG',
path_list=Options.options.swig_home,
mandatory=Options.options.require_swig)
if not swig: return
swigver = Options.options.swigver
if swigver:
Expand Down
25 changes: 15 additions & 10 deletions modules/c++/io/include/io/FileInputStreamOS.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* =========================================================================
* This file is part of io-c++
* This file is part of io-c++
* =========================================================================
*
*
* (C) Copyright 2004 - 2014, MDA Information Systems LLC
*
* io-c++ is free software; you can redistribute it and/or modify
Expand All @@ -14,8 +14,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/
Expand All @@ -35,7 +35,7 @@
* \file FileInputStreamOS.h
* \brief The InputStream representation of a file using the OS handle
* The file contains the representation of an input stream
* from a file. It mimics the Java io package API, with added
* from a file. It mimics the Java io package API, with added
* streaming capabilities
*/

Expand Down Expand Up @@ -79,15 +79,20 @@ class FileInputStreamOS : public SeekableInputStream
}

virtual ~FileInputStreamOS()
{}
{
if ( isOpen() )
{
close();
}
}

/*!
* Returns the number of bytes that can be read
* without blocking by the next caller of a method for this input
*
*
* \throw except::IOException
* \return number of bytes which are readable
*
*
*/
virtual sys::Off_T available();

Expand Down Expand Up @@ -157,12 +162,12 @@ class FileInputStreamOS : public SeekableInputStream
protected:
/*!
* Read up to len bytes of data from input stream into an array
*
*
* \param buffer Buffer to read into
* \param len The length to read
* \throw except::IOException
* \return The number of bytes read
*
*
*/
virtual sys::SSize_T readImpl(void* buffer, size_t len);
};
Expand Down
19 changes: 12 additions & 7 deletions modules/c++/io/include/io/FileOutputStreamOS.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* =========================================================================
* This file is part of io-c++
* This file is part of io-c++
* =========================================================================
*
*
* (C) Copyright 2004 - 2014, MDA Information Systems LLC
*
* io-c++ is free software; you can redistribute it and/or modify
Expand All @@ -14,8 +14,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/
Expand Down Expand Up @@ -69,7 +69,12 @@ class FileOutputStreamOS : public SeekableOutputStream

//! Destructor, closes the file stream.
virtual ~FileOutputStreamOS()
{}
{
if ( isOpen() )
{
close();
}
}

/*!
* Report whether or not the file is open
Expand All @@ -95,9 +100,9 @@ class FileOutputStreamOS : public SeekableOutputStream
}

virtual void flush();

sys::Off_T seek(sys::Off_T offset, io::Seekable::Whence whence);

sys::Off_T tell();

using OutputStream::write;
Expand Down
11 changes: 7 additions & 4 deletions modules/c++/mem/source/ScratchMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ ScratchMemory::Segment::Segment(size_t numBytes,
void ScratchMemory::release(const std::string& key)
{
std::map<std::string, Segment>::const_iterator iterSeg = mSegments.find(key);
if (iterSeg == mSegments.end())
{
throw except::Exception(Ctxt("Key " + key + " does not exist"));
}
mReleasedKeys.insert(key);

if (mKeyOrder.back() == key)
Expand All @@ -71,14 +75,14 @@ void ScratchMemory::release(const std::string& key)
{
const Segment& segment = iterSeg->second;

mKeyOrder.push_back(key);
std::vector<std::string>::iterator keyIter = std::find(mKeyOrder.begin(),
mKeyOrder.end(),
key);
std::vector<std::string>::iterator nextKeyIter = mKeyOrder.erase(keyIter);
mKeyOrder.push_back(key);

const std::string nextKey = *nextKeyIter;


// The next two if blocks handle the edge case in which there are two
// segments at the same offset: one that has been released
// and one that has not been released. Also, the next segment has been
Expand Down Expand Up @@ -204,14 +208,13 @@ void ScratchMemory::setup(const BufferView<sys::ubyte>& scratchBuffer)
mBuffer = scratchBuffer;
}

size_t currentOffset = 0;
for (std::map<std::string, Segment>::iterator iterSeg = mSegments.begin();
iterSeg != mSegments.end();
++iterSeg)
{
Segment& segment = iterSeg->second;
segment.buffers.resize(segment.numBuffers);
currentOffset = segment.offset;
size_t currentOffset = segment.offset;
for (size_t i = 0; i < segment.numBuffers; ++i)
{
segment.buffers[i] = mBuffer.data + currentOffset;
Expand Down
35 changes: 19 additions & 16 deletions modules/c++/mem/unittests/test_scratch_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <mem/BufferView.h>
#include <sys/Conf.h>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include "TestCase.h"
Expand Down Expand Up @@ -187,59 +188,59 @@ TEST_CASE(testReleaseInteriorBuffers)
mem::BufferView<unsigned char> bufViewE = scratch.getBufferView<sys::ubyte>("e");
mem::BufferView<unsigned char> bufViewF = scratch.getBufferView<sys::ubyte>("f");

for (size_t i = 0; i < bufViewA.size; ++i)
for (size_t i = 0; i < bufViewA.size; ++i)
{
bufViewA.data[i] = 'a';
}
for (size_t i = 0; i < bufViewB.size; ++i)
for (size_t i = 0; i < bufViewB.size; ++i)
{
bufViewB.data[i] = 'b';
}
for (size_t i = 0; i < bufViewC.size; ++i)
for (size_t i = 0; i < bufViewC.size; ++i)
{
bufViewC.data[i] = 'c';
}
for (size_t i = 0; i < bufViewB.size; ++i)
for (size_t i = 0; i < bufViewB.size; ++i)
{
TEST_ASSERT_EQ(bufViewB.data[i], 'b');
}
for (size_t i = 0; i < bufViewD.size; ++i)
for (size_t i = 0; i < bufViewD.size; ++i)
{
bufViewD.data[i] = 'd';
}
for (size_t i = 0; i < bufViewA.size; ++i)
for (size_t i = 0; i < bufViewA.size; ++i)
{
TEST_ASSERT_EQ(bufViewA.data[i], 'a');
}
for (size_t i = 0; i < bufViewC.size; ++i)
for (size_t i = 0; i < bufViewC.size; ++i)
{
TEST_ASSERT_EQ(bufViewC.data[i], 'c');
}
for (size_t i = 0; i < bufViewD.size; ++i)
for (size_t i = 0; i < bufViewD.size; ++i)
{
TEST_ASSERT_EQ(bufViewD.data[i], 'd');
}
for (size_t i = 0; i < bufViewE.size; ++i)
for (size_t i = 0; i < bufViewE.size; ++i)
{
bufViewE.data[i] = 'e';
}
for (size_t i = 0; i < bufViewF.size; ++i)
for (size_t i = 0; i < bufViewF.size; ++i)
{
bufViewF.data[i] = 'f';
}
for (size_t i = 0; i < bufViewC.size; ++i)
for (size_t i = 0; i < bufViewC.size; ++i)
{
TEST_ASSERT_EQ(bufViewC.data[i], 'c');
}
for (size_t i = 0; i < bufViewD.size; ++i)
for (size_t i = 0; i < bufViewD.size; ++i)
{
TEST_ASSERT_EQ(bufViewD.data[i], 'd');
}
for (size_t i = 0; i < bufViewE.size; ++i)
for (size_t i = 0; i < bufViewE.size; ++i)
{
TEST_ASSERT_EQ(bufViewE.data[i], 'e');
}
for (size_t i = 0; i < bufViewF.size; ++i)
for (size_t i = 0; i < bufViewF.size; ++i)
{
TEST_ASSERT_EQ(bufViewF.data[i], 'f');
}
Expand Down Expand Up @@ -437,7 +438,8 @@ TEST_CASE(testGenerateBuffersForRelease)
{
srand((unsigned)time(0));

for (unsigned int run = 0; run < 50; ++run) {
for (unsigned int run = 0; run < 50; ++run)
{
mem::ScratchMemory scratch;
std::vector<Operation> operations;
std::vector<unsigned char> notReleased;
Expand Down Expand Up @@ -481,7 +483,8 @@ TEST_CASE(testGenerateBuffersForRelease)
Operation currentOp = operations.at(jj);
std::string key = std::string(1, currentOp.name);

if (currentOp.op == "put")
if (currentOp.op == "put" &&
std::find(notReleased.begin(), notReleased.end(), currentOp.name) != notReleased.end())
{
mem::BufferView<unsigned char> bufView = scratch.getBufferView<sys::ubyte>(key);
for (size_t i = 0; i < bufView.size; ++i)
Expand Down
11 changes: 10 additions & 1 deletion modules/c++/numpyutils/include/numpyutils/numpyutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,16 @@ void prepareInputAndOutputArray(PyObject* pyInObject,
* \return a numpy array with specified dimension and type
*/
PyObject* toNumpyArray(size_t numRows, size_t numColumns, int typenum,
void* data);
const void* data);

/*
* Get the number of elements in a numpy array.
* \param pyArrayObject Numpy array to count
* \return Number of elements in pyArrayObject
* \throws if pyArrayObject is not a PyArrayObject
*/
size_t getNumElements(PyObject* pyArrayObject);


/*!
* Copy a vector of data buffers into a 2D Numpy array
Expand Down
Loading

0 comments on commit fbdbe40

Please sign in to comment.