python 3.8
$ uname -a
Darwin MBIN0077.local 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64
if value packed in byte obj is 0x88 0xDE it becomes 0Xe4 0X8D on MacOs, Amazon Linux but remains as 0x88 0xDE on ubuntu linux
it seems if prepare docker image on host OS A & deploy on Host OS B is creating issue, pls support for it
?
ex:
buf_kb = ctypes.string_at(raw_data,sizeofrawData)
P.S.: raw_data is byte object returned from function in .so <unsigned char* in c & LP c_ubyte in python 3.8>
Sample code for ideation:
[1]
<main.py>
import ctypes
import os
def main():
print("inside main")
test_lib = ctypes.cdll.LoadLibrary("/src/testlib.so")
a= (ctypes.c_ubyte * 2)(0x1B, 0x26)
b= (ctypes.c_ubyte * 2)(0xE4, 0x1B)
result = test_lib.calc(ctypes.byref(a),ctypes.byref(b))
buf_kb = ctypes.string_at(result, 2)
print("b4 hex::",buf_kb)
json = {
"block": buf_kb.hex()
}
print("json is::",json)
if __name__ == '__main__':
main()
<main.cpp>
#include <iostream>
#include <cstring>
using namespace std;
extern "C" unsigned char* calc(unsigned char* a,unsigned char* b)
{
cout<<"Hello";
unsigned char* result = NULL;
memcpy(result,a,2);
return result;
}
Expected output: json should print 0x1B, 0x26 but its different on Ubuntu , AWS fargate.
<Generate .so lib with below command>
g++ -fPIC -Wall -O3 -shared test.cpp -o testlib.so
[2]
FROM ubuntu:latest
COPY . /src
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y python3
CMD ["python3", "/src/main.py"]
Kindly help to resolve the same asap.
Thank you very much.
Regards,
Gaurav Jain