By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

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

P: 2
The part of the code that is causing this error is:
Expand|Select|Wrap|Line Numbers
  1. newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); 
  2.  
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.....

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


P: 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(NULL, STRINGLIB_LEN(self));" to "objectint(newobj) = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));"
May 6 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.