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

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    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 undefine the variable and malloc.
    I am not sure how to correct the error.
    Also I am compiling this with the ILE C AS400 compiler
    The following is the entire code.....


    Code:
    1. /* NOTE: this API is -ONLY- for use with single byte character strings. */
    2. /* Do not use it with Unicode. */
    3. #include "bytes_methods.h"
    4. #include "structmember.h"
    5. #include "stdlib.h"
    6. #include "Python.h"
    7. #include "stdio.h"
    8. #include "string.h"
    9. static PyObject*
    10. stringlib_isspace(PyObject *self)
    11. {
    12. const char* sum = (const char*)malloc(STRINGLIB_STR(self));
    13. return _Py_bytes_isspace(sum, STRINGLIB_LEN(self));
    14. }
    15. static PyObject*
    16. stringlib_isalpha(PyObject *self)
    17. {
    18. const char* sum = (const char*)malloc(STRINGLIB_STR(self));
    19. return _Py_bytes_isalpha(sum, STRINGLIB_LEN(self));
    20. }
    21. static PyObject*
    22. stringlib_isalnum(PyObject *self)
    23. {
    24. const char* sum = (const char*)malloc(STRINGLIB_STR(self));
    25. return _Py_bytes_isalnum(sum, STRINGLIB_LEN(self));
    26. }
    27. static PyObject*
    28. stringlib_isdigit(PyObject *self)
    29. {
    30. const char* sum = (const char*)malloc(STRINGLIB_STR(self));
    31. return _Py_bytes_isdigit(sum, STRINGLIB_LEN(self));
    32. }
    33. static PyObject*
    34. stringlib_islower(PyObject *self)
    35. {
    36. const char* sum = (const char*)malloc(STRINGLIB_STR(self));
    37. return _Py_bytes_islower(sum, STRINGLIB_LEN(self));
    38. }
    39. static PyObject*
    40. stringlib_isupper(PyObject *self)
    41. {
    42. const char* sum = (const char*)malloc(STRINGLIB_STR(self));
    43. return _Py_bytes_isupper(sum, STRINGLIB_LEN(self));
    44. }
    45. static PyObject*
    46. stringlib_istitle(PyObject *self)
    47. {
    48. const char* sum = (const char*)malloc(STRINGLIB_STR(self));
    49. return _Py_bytes_istitle(sum, STRINGLIB_LEN(self));
    50. }
    51. /* functions that return a new object partially translated by ctype funcs: */
    52. static PyObject*
    53. stringlib_lower(PyObject *self)
    54. {
    55. char* sum1;
    56. const char* sum = (const char*)malloc(STRINGLIB_STR(self));
    57. PyObject* newobj;
    58. newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
    59. sum1 = (char*)malloc(STRINGLIB_STR(newobj));
    60. if (!newobj)
    61. return NULL;
    62. _Py_bytes_lower(sum1, sum,
    63. STRINGLIB_LEN(self));
    64. return newobj;
    65. }
    66. static PyObject*
    67. stringlib_upper(PyObject *self)
    68. {
    69. char* sum1;
    70. const char* sum = (const char*)malloc(STRINGLIB_STR(self));
    71. PyObject* newobj;
    72. newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
    73. sum1 = (char*)malloc(STRINGLIB_STR(newobj));
    74. if (!newobj)
    75. return NULL;
    76. _Py_bytes_upper(sum1, sum,
    77. STRINGLIB_LEN(self));
    78. return newobj;
    79. }
    80. static PyObject*
    81. stringlib_title(PyObject *self)
    82. {
    83. char* sum1;
    84. char* sum = (char*)malloc(STRINGLIB_STR(self));
    85. PyObject* newobj;
    86. newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
    87. sum1 = (char*)realloc(sum,STRINGLIB_STR(newobj));
    88. if (!newobj)
    89. return NULL;
    90. _Py_bytes_title(sum1,sum,
    91. STRINGLIB_LEN(self));
    92. return newobj;
    93. }
    94. static PyObject*
    95. stringlib_capitalize(PyObject *self)
    96. {
    97. char* sum1;
    98. char* sum = (char*)malloc(STRINGLIB_STR(self));
    99. PyObject* newobj;
    100. newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
    101. if (!newobj)
    102. return NULL;
    103. sum1 = (char*)realloc(sum,STRINGLIB_STR(newobj));
    104. _Py_bytes_capitalize(sum1, sum,
    105. STRINGLIB_LEN(self));
    106. return newobj;
    107. }
    108. static PyObject*
    109. stringlib_swapcase(PyObject *self)
    110. {
    111. char* sum1;
    112. char* sum = (char *)malloc(STRINGLIB_STR(self));
    113. PyObject* newobj;
    114. newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
    115. sum1 = (char*)realloc(sum,STRINGLIB_STR(newobj));
    116. if (!newobj)
    117. return NULL;
    118. free (sum);
    119. _Py_bytes_swapcase(sum1,sum,
    120. STRINGLIB_LEN(self));
    121. return newobj;
    122. }

  2. #2
    Registered User
    Join Date
    May 2015
    Posts
    2
    update: I found the solution........
    I defined a 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(NULL, STRINGLIB_LEN(self));" to
    "objectint(newobj) = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));"

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,793
    And you think that taking only 1 byte from the pointer will really save you?

    Your program I suppose will crash as soon as you access such corrupted pointer
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,898
    > update: I found the solution........
    No, you found some hackery to make the compiler STFU.

    > Also I am compiling this with the ILE C AS400 compiler
    You need to examine Python.h (and others) to find out how PyObject, STRINGLIB_NEW etc are declared.
    My guess (since you're using an 'unusual' compiler) is that there are conditional compilation blocks for various things, and your compiler isn't represented. So you end up with some default declaration that doesn't compile properly.

    Eg.
    Code:
    #ifdef GCC
    // some code here specific to gcc
    #elsif MSVC
    // some code here specific to msvc
    #endif
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2014, 08:12 PM
  2. Replies: 39
    Last Post: 07-28-2013, 08:24 PM
  3. An interesting code about "struct" in "union"
    By meili100 in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2008, 04:37 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM