Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6713539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:23:34+00:00 2026-05-26T08:23:34+00:00

So I’m running into a problem with my custom types, functions and attributes in

  • 0

So I’m running into a problem with my custom types, functions and attributes in Python.

When I’m in Python, and I want to set an attribute on one of my custom types (for example Vector4), my code gets a NULL for the const char* attribute_name argument (and yes, I am importing my module).

Oddly enough, when I hard code the attribute name in my setter function, I get the error:

SystemError: error return without exception set

I do see the object getting created in Python (and again in C++), so I don’t think that’s the problem. I do return 1 if the setattro hook did successfully set the attribute in C++, and I see the code getting called and setting the attribute on the C++ side. There are no errors/exceptions that are raised when the attribute is being set.

Additionally, when I call a function on the instance of my class in Python, it calls the function set in tp_getattro instead of checking the dictionary.

I’m not entirely sure why, maybe it’s because I’m setting a dictionary and putting my functions in there, instead of doing it via a PyModuleDef array, thus functions aren’t being seen when PyType_Ready is called.

Does anyone have any idea why this might be happening? We’re using Python 3.2.


Relevant:

I have a base type (tp_new and tp_dealloc) and then I am creating derived types at runtime. The derived types have a dictionary, tp_base, tp_getattro and a tp_setattro.

This is how functions are bound to Python class/types:

PyMethodDef newMethod;
newMethod.ml_doc = newMethod.ml_name = funcName;
newMethod.ml_flags = METH_VARARGS;
newMethod.ml_meth = pythonFunc;

PyGeneralObj* selfFake = PyObject_New(PyGeneralObj, &MetaEngineType);
selfFake->className = className;
selfFake->funcName = funcName;
Py_INCREF((PyObject*)selfFake);

PyObject *func = PyCFunction_New(&newMethod, (PyObject*)selfFake);
PyObject *method = PyInstanceMethod_New(func);

ErrorIf((method == NULL), "Python: Cannot create instance function. %s", 
funcName);

ErrorIf((PyDict_SetItem(classObj->m_pyClassType->tp_dict,            
PyReturnStr(newMethod.ml_name), method) == -1), 
"Python: Cannot create function in dictionary.");

Py_DECREF(func);
Py_DECREF(method);

Where funcName and className are const char*. pythonFunc is a generic python function that handles calling all of our functions that are bound to our meta system. classObj is a pointer to a PythonClass which has a member m_pyClassType (a typeof PyTypeObject).

PyGeneralObj is a new object has two const char* and a void* (this is the object in C++)

I do PyType_Ready and get no errors, and then increment my type. I then add the object to the module PyObject that I’m given from PyImport_ImportModule. I do append my main module to the runtime and initalize python and import my module.


If more information/code is needed, I can post some more. I hope this makes sense, this is my first time posting on stackoverflow.

For clarification, we want to have dynamic attributes that are completely resolved on the C++ side. And for functions, I want to be able to override the PyObject* self argument so that I can get the string name of the function that needs to be called.

We don’t want to use third party libraries/interfaces like Boost, Cython and whatever.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:23:34+00:00Added an answer on May 26, 2026 at 8:23 am

    The problem was in my implementation of getattro.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.