Skip to content

Commit

Permalink
fix issue HIT-SCIR#52: mingw compiling bug
Browse files Browse the repository at this point in the history
Oneplus committed Oct 10, 2014

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent a371937 commit a831c3d
Showing 17 changed files with 48 additions and 39 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -5,10 +5,14 @@ project ("LTP - Language Technology Platform")
# -- config cmake modules path
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

if(APPLE)
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libstdc++ -Wno-error=c++11-narrowing")
if (APPLE)
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libstdc++ -Wno-error=c++11-narrowing")
endif(APPLE)

if (MINGW)
set(CMAKE_CXX_FLAGS "-std=c++11 -Wno-narrowing -fpermissive")
endif (MINGW)

# -- config output directories
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set (LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ add_subdirectory ("srl")
add_subdirectory ("__ltp_dll")

# mongoose server is not supported in windows
if (NOT WIN32)
if (UNIX)
add_subdirectory ("unittest")
add_subdirectory ("server")
endif()
15 changes: 12 additions & 3 deletions src/__xml4nlp/Xml4nlp.cpp
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@

#include "Xml4nlp.h"
#include "__util/MyLib.h"
#include <cstring>

const char * const NOTE_SENT = "sent";
const char * const NOTE_WORD = "word";
@@ -1143,6 +1144,14 @@ int XML4NLP::BuildDOMFrame() {
return 0;
}

#if defined(_WIN32) && !defined(_MSC_VER)
static size_t strnlen(const char *s, size_t max) {
register const char *p;
for(p = s; *p && max--; ++p);
return(p - s);
}
#endif // defined

bool XML4NLP::LTMLValidation() {
// there should not be any attributes in `<xml4nlp>`
// but it wont matter
@@ -1204,19 +1213,19 @@ bool XML4NLP::LTMLValidation() {

#define END }}}

FOREACH(p, s, w)
FOREACH(p, s, w)
// segment check
const char * buffer = NULL;
buffer = w.wordPtr->Attribute(TAG_CONT);
if ((state & 0x02)
if ((state & 0x02)
&& (!buffer || !strnlen(buffer, 1024))) { return false; }

buffer = w.wordPtr->Attribute(TAG_POS);
if ((state & 0x04)
&& (!buffer || !strnlen(buffer, 1024))) { return false; }

buffer = w.wordPtr->Attribute(TAG_PSR_PARENT);
if ((state & 0x08)
if ((state & 0x08)
&& (!buffer || !strnlen(buffer, 1024))) { return false; }

buffer = w.wordPtr->Attribute(TAG_PSR_RELATE);
2 changes: 1 addition & 1 deletion src/ner/ner_dll.h
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
#define NER_DLL_API
#define NER_DLL_API_EXPORT

#ifdef _WIN32
#if defined(_MSC_VER)
#undef NER_DLL_API
#ifdef NER_DLL_API_EXPORT
#define NER_DLL_API extern "C" _declspec(dllexport)
4 changes: 2 additions & 2 deletions src/parser/parser_dll.h
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
#define PARSER_DLL_API
#define PARSER_DLL_API_EXPORT

#ifdef _WIN32
#if defined(_MSC_VER)
#undef PARSER_DLL_API
#ifdef PARSER_DLL_API_EXPORT
#define PARSER_DLL_API extern "C" _declspec(dllexport)
@@ -27,7 +27,7 @@ PARSER_DLL_API void * parser_create_parser(const char * path);

/*
* release the postagger resources
*
*
* @param[in] segmentor the segmentor
* @return int i don't know
*/
4 changes: 2 additions & 2 deletions src/postagger/postag_dll.h
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
#define POSTAGGER_DLL_API
#define POSTAGGER_DLL_API_EXPORT

#ifdef _WIN32
#if defined(_MSC_VER)
#undef POSTAGGER_DLL_API
#ifdef POSTAGGER_DLL_API_EXPORT
#define POSTAGGER_DLL_API extern "C" _declspec(dllexport)
@@ -29,7 +29,7 @@ POSTAGGER_DLL_API void * postagger_create_postagger(const char * path,

/*
* release the postagger resources
*
*
* @param[in] segmentor the segmentor
* @return int i don't know
*/
4 changes: 2 additions & 2 deletions src/segmentor/segment_dll.h
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
#define SEGMENTOR_DLL_API
#define SEGMENTOR_DLL_API_EXPORT

#ifdef _WIN32
#if defined(_MSC_VER)
#undef SEGMENTOR_DLL_API
#ifdef SEGMENTOR_DLL_API_EXPORT
#define SEGMENTOR_DLL_API extern "C" _declspec(dllexport)
@@ -38,7 +38,7 @@ SEGMENTOR_DLL_API void * segmentor_create_segmentor(const char * path,
* @param[in] segmentor the segmentor
* @return int i don't know
*/
SEGMENTOR_DLL_API int segmentor_release_segmentor(void * parser);
SEGMENTOR_DLL_API int segmentor_release_segmentor(void * parser);

/*
* run segment on the given segmentor
2 changes: 1 addition & 1 deletion src/srl/SRL_DLL.h
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ using namespace std;
#define SRL_DLL_API
#define SRL_DLL_API_EXPORT

#ifdef _WIN32
#if defined(_MSC_VER)
#undef SRL_DLL_API
#ifdef SRL_DLL_API_EXPORT
#define SRL_DLL_API extern "C" _declspec(dllexport)
2 changes: 1 addition & 1 deletion src/utils/cfgparser.hpp
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class ConfigParser {
int _num_entries;
bool _valid;

#ifdef _WIN32
#if defined(_MSC_VER)
typedef stdext::hash_map<std::string, std::string> internal_entries_t;
typedef stdext::hash_map<std::string, internal_entries_t> internal_sections_t;
#else
4 changes: 2 additions & 2 deletions src/utils/chartypes.hpp
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ namespace ltp {
namespace strutils {
namespace chartypes {

enum{
enum{
// level 1
CHAR_LETTER = 1,
CHAR_DIGIT = 2,
@@ -83,7 +83,7 @@ class __chartype_collections {
}

private:
#ifdef _WIN32
#if defined(_MSC_VER)
typedef stdext::hash_map<const char *, int,
utility::__Default_CharArray_HashFunction> internal_collection_t;
#else
6 changes: 3 additions & 3 deletions src/utils/hasher.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __HASHER_HPP__
#define __HASHER_HPP__

#ifdef _WIN32
#if defined(_MSC_VER)
#include <hash_map>
#endif

@@ -10,8 +10,8 @@
namespace ltp {
namespace utility {

struct __Default_CharArray_HashFunction
#ifdef _WIN32
struct __Default_CharArray_HashFunction
#if defined(_MSC_VER)
: public stdext::hash_compare<const char *>
#endif
{
14 changes: 4 additions & 10 deletions src/utils/math/sparsevec.h
Original file line number Diff line number Diff line change
@@ -2,22 +2,16 @@
#define __SPARSE_VECTOR_H__

#include "featurevec.h"
#include "utils/unordered_map.hpp"
#include <iostream>
#include <string>

#ifdef _WIN32
#include <hash_map>
#else
//#include <ext/hash_map>
#include <tr1/unordered_map>
#endif

namespace ltp {
namespace math {

class SparseVec {
public:
#ifdef _WIN32
#if defined(_MSC_VER)
typedef stdext::hash_map<int,double> internal_sparsevec_t;
#else
typedef std::tr1::unordered_map<int, double> internal_sparsevec_t;
@@ -115,9 +109,9 @@ class SparseVec {
}
}

inline void add(const int * idx,
inline void add(const int * idx,
const double * val,
const int n,
const int n,
const int loff,
const double scale) {
if (!idx) {
2 changes: 1 addition & 1 deletion src/utils/spthread.hpp
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
| Used in linux and mac os |
+ ======================================== +
*/
#ifndef WIN32
#if !defined(_WIN32) && !defined(_WIN64)

#include <pthread.h>
#include <unistd.h>
2 changes: 1 addition & 1 deletion src/utils/stringmap.hpp
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ namespace utility {
template <class T>
class StringMap {
public:
#ifdef _WIN32
#if defined(_MSC_VER)
typedef stdext::hash_map<const char *, T,
__Default_CharArray_HashFunction> internal_map_t;
#else
12 changes: 6 additions & 6 deletions src/utils/template.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// A light weight template engine which support few template functions.
// It's designed for feature extraction in various NLP tasks. Speed is mainly concerned.
// Since template is treated as an internal program-specified, we didnt use the safe
// functions like strnlen, strncmp, strncpy just for consideration of speed.

//! A light weight template engine which support few template functions. It's
//! designed for feature extraction in various NLP tasks. Speed is mainly
//! concerned. Since template is treated as an internal program-specified, we
//! didn't use the safe functions like strnlen, strncmp, strncpy just for
//! consideration of speed.
#ifndef __TEMPLATE_HPP__
#define __TEMPLATE_HPP__

@@ -21,7 +21,7 @@ namespace utility {
template <typename T>
class __Template_Token_Cache {
private:
#ifdef _WIN32
#if defined(_MSC_VER)
typedef stdext::hash_map<const char *, int,
__Default_CharArray_HashFunction> indexing_t;
#else
2 changes: 1 addition & 1 deletion src/utils/unordered_map.hpp
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
#ifndef __UTILS_UNORDERED_MAP_HPP__
#define __UTILS_UNORDERED_MAP_HPP__

#ifdef _WIN32
#if defined(_MSC_VER)
#include <hash_map>
#else
#include <tr1/unordered_map>
2 changes: 2 additions & 0 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
add_subdirectory (boost)
add_subdirectory (maxent)
add_subdirectory (tinyxml)
if (UNIX)
add_subdirectory (gtest)
endif()

0 comments on commit a831c3d

Please sign in to comment.