Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
[Python] Found and solved a threading issue. Revisisted the API to ha…
Browse files Browse the repository at this point in the history
…ve this fixed. Documentation stil to update.
  • Loading branch information
shlublu committed May 19, 2020
1 parent 3762ec2 commit 9f4b0fe
Show file tree
Hide file tree
Showing 14 changed files with 694 additions and 265 deletions.
77 changes: 39 additions & 38 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
## v0.3 - XXXX-XX-XX

### New features

* Python: added unit tests and improved the documentation.
* Python: added functions beginCriticalSection() / endCriticalSection()

### Fixes

* Python: fixed multithreading issue

### Compatibility breakers

*none*


## v0.2 - 2020-05-15

### New features

* Added `CRC` class and `hash` module.

### Fixes

*none*

### Compatibility breakers

* Moved `include/<modules>` directories to `include/shlublu/<modules>`. Includes directives `#include<module/function.h>` should be replaced by `#include<shlublu/module/function.h>` in your code.
* Put all exposed symbols behind global namespace `shlublu::`. You can either prefix symbols accordingly or use `using namespace shlublu;`.
* In `util/Debug.h`: changed macros names from `PRAGMA_xxx` to `SHLUBLU_xxx` as namespaces do not apply to macros. They should be renamed in your code too.


## v0.1 - 2020-05-13

First workable version.


## v0.3 - XXXX-XX-XX

### New features

* Python:
* introduced `ObjectHandler`, compatible with CPython's `PyObject *`
* added functions `beginCriticalSection()` / `endCriticalSection()`
* added unit tests and improved the documentation.

### Fixes

* Python: fixed a multithreading issue

### Compatibility breakers

* Python: `ValueRef` and `ArgsRef` have been replaced by `ObjectHandler`. Explicit use of htese types should be replaced in your code.

## v0.2 - 2020-05-15

### New features

* Added `CRC` class and `hash` module.

### Fixes

*none*

### Compatibility breakers

* Moved `include/<modules>` directories to `include/shlublu/<modules>`. Includes directives `#include<module/function.h>` should be replaced by `#include<shlublu/module/function.h>` in your code.
* Put all exposed symbols behind global namespace `shlublu::`. You can either prefix symbols accordingly or use `using namespace shlublu;`.
* In `util/Debug.h`: changed macros names from `PRAGMA_xxx` to `SHLUBLU_xxx` as namespaces do not apply to macros. They should be renamed in your code too.


## v0.1 - 2020-05-13

First workable version.


170 changes: 70 additions & 100 deletions include/shlublu/binding/Python.h

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions include/shlublu/binding/Python_BindingException.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <shlublu/util/Exceptions.h>


namespace shlublu
{

namespace Python
{

/**
Python throws this exception should an issue happen.
*/
class BindingException : public ShlubluException
{
public:
/**
Constructor.
@param message description of the issue
*/
explicit BindingException(const std::string& message)
: ShlubluException(("Python binding: " + message).c_str())
{}

/**
Constructor.
@param message description of the issue
*/
explicit BindingException(const char* message)
: BindingException(std::string(message))
{}
};

}

}

56 changes: 56 additions & 0 deletions include/shlublu/binding/Python_ObjectHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>


namespace shlublu
{

namespace Python
{

class ObjectHandler
{
public:
class Hasher
{
public:
int64_t operator()(ObjectHandler const& key) const;
};


public:
ObjectHandler();
ObjectHandler(ObjectHandler const& src);
ObjectHandler(ObjectHandler&& src) noexcept;
ObjectHandler(PyObject* pyObj);

ObjectHandler& operator = (ObjectHandler src) noexcept;

void swap(ObjectHandler& other) noexcept;

PyObject* get() const;
uint64_t id() const;

operator PyObject* () const;

private:
PyObject* mPyObj;
uint64_t mId;

private:
uint64_t nextId();

static uint64_t sSequence;
};


bool operator == (ObjectHandler const& lhs, ObjectHandler const& rhs);
bool operator != (ObjectHandler const& lhs, ObjectHandler const& rhs);

}

}


3 changes: 3 additions & 0 deletions shlublu-linux.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@
<ItemGroup>
<ClCompile Include="src\async\MutexLock.cpp" />
<ClCompile Include="src\binding\Python.cpp" />
<ClCompile Include="src\binding\Python_ObjectHandler.cpp" />
<ClCompile Include="src\hash\CRC.c" />
<ClCompile Include="src\text\String.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\shlublu\async\MutexLock.h" />
<ClInclude Include="include\shlublu\binding\Python.h" />
<ClInclude Include="include\shlublu\binding\Python_BindingException.h" />
<ClInclude Include="include\shlublu\binding\Python_ObjectHandler.h" />
<ClInclude Include="include\shlublu\hash\CRC.h" />
<ClInclude Include="include\shlublu\text\String.h" />
<ClInclude Include="include\shlublu\util\Debug.h" />
Expand Down
9 changes: 9 additions & 0 deletions shlublu-linux.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="src\hash\CRC.c">
<Filter>src\hash</Filter>
</ClCompile>
<ClCompile Include="src\binding\Python_ObjectHandler.cpp">
<Filter>src\binding</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\shlublu\async\MutexLock.h">
Expand All @@ -71,5 +74,11 @@
<ClInclude Include="include\shlublu\hash\CRC.h">
<Filter>include\hash</Filter>
</ClInclude>
<ClInclude Include="include\shlublu\binding\Python_ObjectHandler.h">
<Filter>include\binding</Filter>
</ClInclude>
<ClInclude Include="include\shlublu\binding\Python_BindingException.h">
<Filter>src\binding</Filter>
</ClInclude>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions shlublu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
<ItemGroup>
<ClCompile Include="src\async\MutexLock.cpp" />
<ClCompile Include="src\binding\Python.cpp" />
<ClCompile Include="src\binding\Python_ObjectHandler.cpp" />
<ClCompile Include="src\hash\CRC.c" />
<ClCompile Include="src\text\String.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\shlublu\async\MutexLock.h" />
<ClInclude Include="include\shlublu\binding\Python.h" />
<ClInclude Include="include\shlublu\binding\Python_BindingException.h" />
<ClInclude Include="include\shlublu\binding\Python_ObjectHandler.h" />
<ClInclude Include="include\shlublu\hash\CRC.h" />
<ClInclude Include="include\shlublu\text\String.h" />
<ClInclude Include="include\shlublu\util\Debug.h" />
Expand Down
9 changes: 9 additions & 0 deletions shlublu.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="src\hash\CRC.c">
<Filter>src\hash</Filter>
</ClCompile>
<ClCompile Include="src\binding\Python_ObjectHandler.cpp">
<Filter>src\binding</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\shlublu\async\MutexLock.h">
Expand All @@ -71,5 +74,11 @@
<ClInclude Include="include\shlublu\hash\CRC.h">
<Filter>include\hash</Filter>
</ClInclude>
<ClInclude Include="include\shlublu\binding\Python_ObjectHandler.h">
<Filter>include\binding</Filter>
</ClInclude>
<ClInclude Include="include\shlublu\binding\Python_BindingException.h">
<Filter>include\binding</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading

0 comments on commit 9f4b0fe

Please sign in to comment.