Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsiddharth jain <sija@microsoft.com>2021-01-12 20:18:42 +0300
committersiddharth jain <sija@microsoft.com>2021-01-12 20:18:42 +0300
commit1631aa14d15068bfb8d028371a51c15503220be3 (patch)
treed9dfaac5d0efcbcfcbf8f290a06169f9b293ec90
parente9cc90e73ab26546906809d5af8ddd5c7e092add (diff)
api signature update
-rw-r--r--moses2/DLLEntryApi.cpp80
1 files changed, 45 insertions, 35 deletions
diff --git a/moses2/DLLEntryApi.cpp b/moses2/DLLEntryApi.cpp
index 155a6664c..e03ff9346 100644
--- a/moses2/DLLEntryApi.cpp
+++ b/moses2/DLLEntryApi.cpp
@@ -1,64 +1,74 @@
#include "Moses2Wrapper.h"
#include <iostream>
-#ifdef WIN32
- #include <windows.h>
-#endif // DEBUG
+#include <string.h>
+
+
+// Generic helper definitions for shared library support
+#if defined _WIN32
+#define IMPORT __declspec(dllimport)
+#define EXPORT __declspec(dllexport)
+#else // !(defined _WIN32 || defined __CYGWIN__) -- i.e., not Windows
+#define __stdcall
+#if __GNUC__ >= 4
+#define IMPORT __attribute__ ((visibility ("default")))
+#define EXPORT __attribute__ ((visibility ("default")))
+#else // __GNUC__ < 4, which does not support the __attribute__ tag
+#define IMPORT
+#define EXPORT
+#endif // __GNUC__ >= 4
+#endif
-#if defined(_MSC_VER)
-// Microsoft
- #define EXPORT __declspec(dllexport)
- #define IMPORT __declspec(dllimport)
-#elif defined(__GNUC__)
-// GCC
- #define HRESULT int
- #define EXPORT __attribute__((visibility("default")))
- #define __stdcall
- #define IMPORT
- #define S_OK 0
- #define E_FAIL 1
-#else
-// do nothing and hope for the best?
- #define EXPORT
- #define IMPORT
- #pragma warning Unknown dynamic link import/export semantics.
-#endif
using namespace std;
using namespace Moses2;
-extern "C" EXPORT HRESULT __stdcall GetMosesSystem(const char* filePath, Moses2::Moses2Wrapper ** pObject) {
+extern "C" EXPORT MosesApiErrorCode __stdcall GetMosesSystem(const char* filePath, Moses2::Moses2Wrapper * *pObject) {
+
if (*pObject == NULL) {
*pObject = new Moses2::Moses2Wrapper(filePath);
- return S_OK;
+ return MS_API_OK;
}
else {
- return E_FAIL;
+ return MS_API_E_FAILURE;
}
}
-extern "C" EXPORT HRESULT __stdcall MosesTranslate(Moses2::Moses2Wrapper * pObject, long id, const char* input, char* output, int strlen) {
+extern "C" EXPORT MosesApiErrorCode __stdcall Translate(Moses2::Moses2Wrapper * pObject, long id, const char* input, char** output) {
if (pObject != NULL)
{
std::string tr = pObject->Translate(input, id);
- std::copy(tr.begin(), tr.end(), output);
- output[std::min(strlen - 1, (int)tr.size())] = 0;
- return S_OK;
+ *output = Moses2Wrapper::CopyString(tr.c_str());
+ return MS_API_OK;
+ }
+ else {
+ return MS_API_E_FAILURE;
+ }
+}
+
+extern "C" EXPORT MosesApiErrorCode __stdcall FreeMemory(char* output) {
+ if (output != nullptr) {
+ Moses2Wrapper::Free(output);
+ return MS_API_OK;
}
else {
- return E_FAIL;
+ return MS_API_E_FAILURE;
}
}
-extern "C" EXPORT int __stdcall ReleaseSystem(Moses2::Moses2Wrapper ** pObject) {
+
+extern "C" EXPORT MosesApiErrorCode __stdcall ReleaseSystem(Moses2::Moses2Wrapper * *pObject) {
if (*pObject != NULL)
{
- delete *pObject;
+ delete* pObject;
*pObject = NULL;
- return S_OK;
+ return MS_API_OK;
}
else {
- return E_FAIL;
+ return MS_API_E_FAILURE;
}
}
-extern "C" EXPORT string __stdcall GetEngineVersion() {
- return "1.0";
+
+extern "C" EXPORT MosesApiErrorCode __stdcall EngineVersion() {
+ //std::cout << "windows build on v1142/ msvc 14.27.29110"<< std::endl;
+ std::cout << "0.0.1" << std::endl;
+ return MS_API_OK;
} \ No newline at end of file