Operations between types "struct _object*" and "int" is not allowed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hancockm
    New Member
    • May 2015
    • 2

    Operations between types "struct _object*" and "int" is not allowed

    The part of the code that is causing this error is:
    Code:
    newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
    I have tried to undefined the variable and malloc. I am not sure how to correct the error.
    Also I am compiling this to with the ILE C AS400 compiler
    The following is the entire code.....

    Code:
    /* NOTE: this API is -ONLY- for use with single byte character strings. */
    /* Do not use it with Unicode. */
    
    #include "bytes_methods.h"
    #include "structmember.h"
    #include "stdlib.h"
    #include "Python.h"
    #include "stdio.h"
    #include "string.h"
    
    
    static PyObject*
    stringlib_isspace(PyObject *self)
    {
    const char* sum = (const char*)malloc(STRINGLIB_STR(self));
        return _Py_bytes_isspace(sum, STRINGLIB_LEN(self));
    }
    
    static PyObject*
    stringlib_isalpha(PyObject *self)
    {
    const char* sum = (const char*)malloc(STRINGLIB_STR(self));
        return _Py_bytes_isalpha(sum, STRINGLIB_LEN(self));
    }
    
    static PyObject*
    stringlib_isalnum(PyObject *self)
    {
    const char* sum = (const char*)malloc(STRINGLIB_STR(self));
        return _Py_bytes_isalnum(sum, STRINGLIB_LEN(self));
    }
    
    static PyObject*
    stringlib_isdigit(PyObject *self)
    {
    const char* sum = (const char*)malloc(STRINGLIB_STR(self));
        return _Py_bytes_isdigit(sum, STRINGLIB_LEN(self));
    }
    
    static PyObject*
    stringlib_islower(PyObject *self)
    {
    const char* sum = (const char*)malloc(STRINGLIB_STR(self));
        return _Py_bytes_islower(sum, STRINGLIB_LEN(self));
    }
    
    static PyObject*
    stringlib_isupper(PyObject *self)
    {
    const char* sum = (const char*)malloc(STRINGLIB_STR(self));
        return _Py_bytes_isupper(sum, STRINGLIB_LEN(self));
    }
    
    static PyObject*
    stringlib_istitle(PyObject *self)
    {
    const char* sum = (const char*)malloc(STRINGLIB_STR(self));
        return _Py_bytes_istitle(sum, STRINGLIB_LEN(self));
    }
    
    
    /* functions that return a new object partially translated by ctype funcs: */
    
    static PyObject*
    stringlib_lower(PyObject *self)
    {
    char* sum1;
    const char* sum = (const char*)malloc(STRINGLIB_STR(self));
        PyObject* newobj;
        newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
        sum1 = (char*)malloc(STRINGLIB_STR(newobj));
        if (!newobj)
                return NULL;
        _Py_bytes_lower(sum1, sum,
                     STRINGLIB_LEN(self));
        return newobj;
    }
    
    static PyObject*
    stringlib_upper(PyObject *self)
    {
    char* sum1;
    const char* sum = (const char*)malloc(STRINGLIB_STR(self));
        PyObject* newobj;
        newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
        sum1 = (char*)malloc(STRINGLIB_STR(newobj));
        if (!newobj)
                return NULL;
        _Py_bytes_upper(sum1, sum,
                     STRINGLIB_LEN(self));
        return newobj;
    }
    
    static PyObject*
    stringlib_title(PyObject *self)
    {
    char* sum1;
    char* sum = (char*)malloc(STRINGLIB_STR(self));
        PyObject* newobj;
        newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
        sum1 = (char*)realloc(sum,STRINGLIB_STR(newobj));
        if (!newobj)
                return NULL;
        _Py_bytes_title(sum1,sum,
                     STRINGLIB_LEN(self));
        return newobj;
    }
    
    static PyObject*
    stringlib_capitalize(PyObject *self)
    {
    char* sum1;
    char* sum = (char*)malloc(STRINGLIB_STR(self));
        PyObject* newobj;
        newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
        if (!newobj)
                return NULL;
        sum1 = (char*)realloc(sum,STRINGLIB_STR(newobj));
        _Py_bytes_capitalize(sum1, sum,
                          STRINGLIB_LEN(self));
        return newobj;
    }
    
    static PyObject*
    stringlib_swapcase(PyObject *self)
    {
    char* sum1;
    char* sum = (char *)malloc(STRINGLIB_STR(self));
        PyObject* newobj;
        newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
        sum1 = (char*)realloc(sum,STRINGLIB_STR(newobj));
        if (!newobj)
                return NULL;
        free (sum);
        _Py_bytes_swapcase(sum1,sum,
                        STRINGLIB_LEN(self));
        return newobj;
    }
  • hancockm
    New Member
    • May 2015
    • 2

    #2
    update: I found the solution....... . inside ctype.h file I defined the struct as an int "#define objectint(b) *(uint8_t*)&b" and then I went to the offending line of code and change "newobj = STRINGLIB_NEW(N ULL, STRINGLIB_LEN(s elf));" to "objectint(newo bj) = STRINGLIB_NEW(N ULL, STRINGLIB_LEN(s elf));"

    Comment

    Working...