Skip to content

Commit

Permalink
1. 新增main.cpp来模拟调用 不需要aiges
Browse files Browse the repository at this point in the history
2. 移除错误的gil release语句
3. 修改wrapper.py exec的返回值
4. 新增makefile main选项
5. 修改logger默认级别,移除自动创建log文件夹
  • Loading branch information
happened committed Jul 23, 2022
1 parent 9a92af9 commit 8d70ed8
Show file tree
Hide file tree
Showing 35 changed files with 17,637 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CMakelists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.22)
project(aiges_c_python-wrapper VERSION 1.0.0)
include_directories(./include)
aux_source_directory(./core SRC_LIST)
6 changes: 5 additions & 1 deletion wrapper2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif

wrapper:
echo $(PYLIB)
g++ -Wall -pedantic -Wextra -fPIC -shared -std=c++1y -fvisibility=default -Wno-attributes $(PYINC) -g -O0 -I. -I./include/spdlog/include/ -I./include/ -o libwrapper.so pyWrapper.cpp wrapper.cpp -L. -L /opt/conda/envs/loader/lib -lboost_filesystem -lboost_system $(PYLIB) -rdynamic
g++ -Wall -pedantic -Wextra -fPIC -shared -std=c++1y -fvisibility=default -Wno-attributes $(PYINC) -g -O0 -I. -I./include/spdlog/include/ -I./include/ -o libwrapper.so pyWrapper.cpp wrapper.cpp -L. -L /opt/conda/envs/loader/lib $(PYLIB) -rdynamic
mkdir -p wrapper_lib
cp libwrapper.so ./wrapper_lib

Expand All @@ -24,3 +24,7 @@ t:
echo $(PY_GT_3_6)
rm -f test
g++ -Wall -g -O0 -fPIC -I./include/spdlog/include/ $(PYINC) pyWrapper.cpp pyWrapperTest.cpp -o test $(PYLIB)

main:
echo $(PYLIB)
g++ -Wall -pedantic -Wextra -fPIC -std=c++1y -fvisibility=default -Wno-attributes $(PYINC) -g -O0 -I. -I./include/spdlog/include/ -I./include/ -o output pyWrapper.cpp wrapper.cpp main.cpp -L. -L /opt/conda/envs/loader/lib $(PYLIB) -rdynamic
72 changes: 72 additions & 0 deletions wrapper2/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "aiges/wrapper.h"
#include "aiges/type.h"
#include <iostream>
struct ParamList* paramListCreate(){
struct ParamList* pParamPtr= (struct ParamList*)malloc(sizeof(struct ParamList));
pParamPtr->key=NULL;
pParamPtr->value=NULL;
pParamPtr->vlen=0;
pParamPtr->next=NULL;
return pParamPtr;
}

struct DataList* dataListCreate(){
struct DataList* pDataPtr= (struct DataList*)malloc(sizeof(struct DataList));
pDataPtr->key=NULL;
pDataPtr->data=NULL;
pDataPtr->len=0;
pDataPtr->type=DataText;
pDataPtr->status=DataBegin;
pDataPtr->desc=NULL;
pDataPtr->next=NULL;
return pDataPtr;
}

struct DataList* dataListAppend(struct DataList* ptr,char* key,void* data,unsigned int len,int type,int status,struct ParamList* descPtr){
struct DataList* head=ptr;
if(ptr!=NULL && ptr->key==NULL){
ptr->key=key;
ptr->data=data;
ptr->len=len;
ptr->type=(DataType)(type);
ptr->status=(DataStatus)(status);
ptr->desc=descPtr;
ptr->next=NULL;
return ptr;
}
while(ptr->next!=NULL){
ptr=ptr->next;
}
struct DataList* pDataPtr= (struct DataList*)malloc(sizeof(struct DataList));
pDataPtr->key=key;
pDataPtr->data=data;
pDataPtr->len=len;
pDataPtr->type=(DataType)(type);
pDataPtr->status=(DataStatus)(status);
pDataPtr->desc=descPtr;
pDataPtr->next=NULL;
ptr->next=pDataPtr;
return head;
}

int main(int argc,char* argv[]){

pConfig cfg=paramListCreate();
int ret=wrapperInit(cfg);
std::cout<<ret<<std::endl;

pParamList pList=paramListCreate();

DataList* dataList=dataListCreate();
char* data_key="test_key";
char* data_content="hello world";
dataList= dataListAppend(dataList,data_key,(void*)data_content,11,0,2,NULL);

pDataList resp=dataListCreate();
unsigned int psrIds[1];
psrIds[0]=3;

std::string handle="handle0001";
ret=wrapperExec(handle.c_str(),pList, dataList,&resp, psrIds,0);
std::cout<<ret<<std::endl;
}
9 changes: 4 additions & 5 deletions wrapper2/pyWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,27 @@ PyWrapper::~PyWrapper() {
_wrapperFini.release();
_wrapperOnceExec.release();
_wrapperTest.release();
pybind11::gil_scoped_release release;
}


int PyWrapper::wrapperInit(std::map <std::string, std::string> config) {
py::gil_scoped_acquire acquire;
return _wrapperInit(config).cast<int>();
}


int PyWrapper::wrapperFini() {
py::gil_scoped_acquire acquire;
return _wrapperFini().cast<int>();
}

int PyWrapper::wrapperOnceExec(std::map <std::string, std::string> params, DataListCls reqData,
pDataList *respData, std::string sid) {
try {
py::gil_scoped_acquire acquire;
py::object r = _wrapperOnceExec(params, reqData);
Response *resp;
std::cout<<"start cast python resp to cpp object"<<std::endl;
resp = r.cast<Response *>();
std::cout<<"cast python resp to cpp object success"<<std::endl;
pDataList headPtr;
pDataList prePtr;
pDataList curPtr;
Expand Down Expand Up @@ -140,8 +140,7 @@ int PyWrapper::wrapperOnceExec(std::map <std::string, std::string> params, DataL


std::string PyWrapper::wrapperError(int err) {
py::gil_scoped_acquire acquire;
return _wrapperError(err).cast<std::string>();
return _wrapperError(err).cast<std::string>();
}


Expand Down
2 changes: 2 additions & 0 deletions wrapper2/pyWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <thread>
#include <chrono>
#include <sstream>
#include<map>
#include <vector>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/rotating_file_sink.h"

Expand Down
1 change: 0 additions & 1 deletion wrapper2/pybind11
Submodule pybind11 deleted from aa304c
Loading

0 comments on commit 8d70ed8

Please sign in to comment.