Skip to content

Commit a844e6b

Browse files
committed
Fix error with ContainerInfo after version up
- Correct error : missing attribute ContainerInfo.column_info_list after update to SWIG 4.0.2 - Update python to 3.9.5 in Makefile - Update CmakeLists.txt to build in Windows
1 parent 0a8fb18 commit a844e6b

File tree

3 files changed

+47
-47
lines changed

3 files changed

+47
-47
lines changed

CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ project(griddb_python)
44

55
set(C_LIB E:/c_client-master/c_client-master/bin/x64/Release)
66
set(C_HEADER E:/c_client-master/c_client-master/client/c/include)
7-
set(SOURCE_HEADER E:/cmake-fun/SourceCode/src)
8-
set(PYTHON_RESOURCE C:/Users/griddb/AppData/Local/Programs/Python/Python36/)
9-
set(SWIG_RESOURCE E:/swigwin-3.0.12)
7+
set(SOURCE_HEADER E:/griddb/python_client/SourceCode/src)
8+
set(PYTHON_RESOURCE C:/Users/griddb/AppData/Local/Programs/Python/Python39/)
9+
set(NUMPY_RESOURCE C:/Users/griddb/AppData/Local/Programs/Python/Python39/Lib/site-packages/numpy/core/include)
10+
set(SWIG_RESOURCE E:/swigwin-4.0.2)
1011

1112
set(PYTHON_LIBRARIES ${PYTHON_RESOURCE}/libs)
1213
set(PYTHON_INCLUDE_DIRS ${PYTHON_RESOURCE}/include)
@@ -23,8 +24,8 @@ include(${SWIG_USE_FILE})
2324
set(CMAKE_SWIG_FLAGS -c++)
2425
set(CMAKE_CXX_FLAGS "/DLL /LD /D_USRDLL /D_WINDLL /MT /MD")
2526

26-
include_directories(${C_HEADER} ${PYTHON_RESOURCE}/include ${SOURCE_HEADER})
27-
link_directories(${PYTHON_RESOURCE}/libs ${C_LIB})
27+
include_directories(${C_HEADER} ${PYTHON_RESOURCE}/include ${SOURCE_HEADER} ${NUMPY_RESOURCE})
28+
link_directories(${PYTHON_RESOURCE}/libs ${C_LIB} ${NUMPY_RESOURCE})
2829

2930
set_property(SOURCE ${SOURCE_HEADER}/griddb.i PROPERTY CPLUSPLUS ON)
3031
swig_add_library(griddb_python TYPE SHARED LANGUAGE python SOURCES ${SOURCE_HEADER}/griddb.i
@@ -41,6 +42,8 @@ ${SOURCE_HEADER}/RowKeyPredicate.cpp
4142
${SOURCE_HEADER}/RowSet.cpp
4243
${SOURCE_HEADER}/TimestampUtils.cpp
4344
${SOURCE_HEADER}/Field.cpp
45+
${SOURCE_HEADER}/RowList.cpp
46+
${SOURCE_HEADER}/RowSet.cpp
4447
${SOURCE_HEADER}/Util.cpp)
4548

4649
target_link_libraries(griddb_python gridstore_c)

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ CPPFLAGS = -fPIC -std=c++0x -g -O2
99
INCLUDES = -Iinclude -Isrc
1010

1111
INCLUDES_PYTHON = $(INCLUDES) \
12-
-I/usr/include/python3.6 \
13-
-I$(HOME)/.pyenv/versions/3.6.4/lib/python3.6/site-packages/numpy/core/include
12+
-I/usr/include/python3.9/ \
13+
-I$(HOME)/.pyenv/versions/3.9.5/lib/python3.9/site-packages/numpy/core/include
1414

1515
PROGRAM = _griddb_python.so
1616
EXTRA = griddb_python.py griddb_python.pyc

src/gstype_python.i

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,14 +2265,7 @@ static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool tim
22652265
%attribute(griddb::ExpirationInfo, int, division_count, get_division_count, set_division_count);
22662266

22672267
//Attribute ContainerInfo::columnInfoList
2268-
#if SWIG_VERSION < 0x040000
2269-
%extend griddb::ContainerInfo{
2270-
%pythoncode %{
2271-
__swig_getmethods__["column_info_list"] = get_column_info_list
2272-
__swig_setmethods__["column_info_list"] = set_column_info_list
2273-
%}
2274-
};
2275-
#endif
2268+
%attributeval(griddb::ContainerInfo, ColumnInfoList, column_info_list, get_column_info_list, set_column_info_list);
22762269

22772270
/**
22782271
* Typemap for Container::multi_put
@@ -2337,32 +2330,29 @@ static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool tim
23372330
%typemap(doc, name = "row_list") (GSRow** listRowdata, int rowCount) "list[list[object]]";
23382331

23392332
//attribute ContainerInfo::column_info_list
2340-
%typemap(in, fragment = "SWIG_AsCharPtrAndSize", fragment = "cleanString") (ColumnInfoList columnInfoList) (int* alloc = NULL){
2333+
%typemap(in, fragment = "SWIG_AsCharPtrAndSize", fragment = "cleanString") (ColumnInfoList*) (int* alloc = NULL){
23412334

23422335
if (!PyList_Check($input)) {
23432336
PyErr_SetString(PyExc_ValueError, "Expected a List");
23442337
SWIG_fail;
23452338
}
2346-
int res;
2347-
char* v = 0;
2348-
bool vbool;
2349-
size_t size = 0;
2350-
size = (size_t)PyInt_AsLong(PyLong_FromSsize_t(PyList_Size($input)));
2351-
$1.columnInfo = NULL;
2352-
$1.size = size;
2353-
size_t stringSize = 0;
2339+
2340+
$1 = NULL;
2341+
size_t size = (size_t)PyInt_AsLong(PyLong_FromSsize_t(PyList_Size($input)));
23542342
if (size) {
23552343
try {
2356-
alloc = new int[size]();
2357-
$1.columnInfo = new GSColumnInfo[size]();
2344+
$1 = new ColumnInfoList();
2345+
alloc = new int[size]();
2346+
$1->columnInfo = new GSColumnInfo[size]();
23582347
} catch (bad_alloc& ba) {
23592348
PyErr_SetString(PyExc_ValueError, "Memory allocation for set column_info_list is error");
23602349
SWIG_fail;
23612350
}
2351+
$1->size = size;
23622352
PyObject* columInfoList;
23632353
int option;
23642354
for (int i = 0; i < size; i++) {
2365-
$1.columnInfo[i] = GS_COLUMN_INFO_INITIALIZER;
2355+
$1->columnInfo[i] = GS_COLUMN_INFO_INITIALIZER;
23662356
columInfoList = PyList_GetItem($input, i);
23672357
if (!PyList_Check(columInfoList)) {
23682358
PyErr_SetString(PyExc_ValueError, "Expected a List");
@@ -2371,55 +2361,62 @@ static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool tim
23712361
size_t sizeColumn = (size_t)PyInt_AsLong(PyLong_FromSsize_t(PyList_Size(columInfoList)));
23722362
if (sizeColumn == 3) {
23732363
option = PyInt_AsLong(PyList_GetItem(columInfoList, 2));
2374-
$1.columnInfo[i].options = option;
2364+
$1->columnInfo[i].options = option;
23752365
if (option != GS_TYPE_OPTION_NULLABLE && option != GS_TYPE_OPTION_NOT_NULL) {
23762366
PyErr_SetString(PyExc_ValueError, "Invalid value for column option");
23772367
SWIG_fail;
23782368
}
23792369
} else if (sizeColumn == 2) {
2380-
if (i == 0) {
2381-
$1.columnInfo[i].options = GS_TYPE_OPTION_NOT_NULL;
2382-
} else {
2383-
$1.columnInfo[i].options = GS_TYPE_OPTION_NULLABLE;
2384-
}
2370+
if (i == 0) {
2371+
$1->columnInfo[i].options = GS_TYPE_OPTION_NOT_NULL;
2372+
} else {
2373+
$1->columnInfo[i].options = GS_TYPE_OPTION_NULLABLE;
2374+
}
23852375
} else {
23862376
PyErr_SetString(PyExc_ValueError, "Invalid element number for List");
23872377
SWIG_fail;
23882378
}
23892379

2380+
char* v = 0;
2381+
size_t stringSize = 0;
2382+
int res;
23902383
res = SWIG_AsCharPtrAndSize(PyList_GetItem(columInfoList, 0), &v, &stringSize, &alloc[i]);
23912384
if (!SWIG_IsOK(res)) {
23922385
PyErr_SetString(PyExc_ValueError, "Can't convert field to string");
23932386
SWIG_fail;
23942387
}
2395-
$1.columnInfo[i].name = v;
2396-
$1.columnInfo[i].type = PyInt_AsLong(PyList_GetItem(columInfoList, 1));
2388+
$1->columnInfo[i].name = v;
2389+
$1->columnInfo[i].type = PyInt_AsLong(PyList_GetItem(columInfoList, 1));
23972390
}
23982391
}
23992392
}
24002393

2401-
%typemap(freearg, fragment = "cleanString") (ColumnInfoList columnInfoList) {
2394+
%typemap(freearg, fragment = "cleanString") (ColumnInfoList*) {
24022395
size_t size = 0;
2403-
if ($1.size) {
2404-
size = $1.size;
2405-
}
2406-
if ($1.columnInfo != NULL) {
2407-
if (alloc$argnum) {
2408-
for (int i = 0; i < size; i++) {
2409-
if ($1.columnInfo[i].name) {
2410-
cleanString($1.columnInfo[i].name, alloc$argnum[i]);
2396+
if ($1) {
2397+
if ($1->size) {
2398+
size = $1->size;
2399+
}
2400+
if ($1->columnInfo != NULL) {
2401+
if (alloc$argnum) {
2402+
for (int i = 0; i < size; i++) {
2403+
if ($1->columnInfo[i].name) {
2404+
cleanString($1->columnInfo[i].name, alloc$argnum[i]);
2405+
}
24112406
}
24122407
}
2408+
delete [] $1->columnInfo;
24132409
}
2414-
delete [] $1.columnInfo;
2410+
2411+
delete $1;
24152412
}
24162413
if (alloc$argnum) {
24172414
delete [] alloc$argnum;
24182415
}
24192416
}
24202417

2421-
%typemap(out, fragment = "convertStrToObj") (ColumnInfoList) {
2422-
ColumnInfoList data = $1;
2418+
%typemap(out, fragment = "convertStrToObj") (ColumnInfoList*) {
2419+
ColumnInfoList data = *$1;
24232420
size_t size = data.size;
24242421
$result = PyList_New(size);
24252422
if ($result == NULL) {

0 commit comments

Comments
 (0)