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

  • Home
  • SEARCH
  • 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 980061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:19:11+00:00 2026-05-16T04:19:11+00:00

I am working on creating a python c extension but am having difficulty finding

  • 0

I am working on creating a python c extension but am having difficulty finding documentation on what I want to do. I basically want to create a pointer to a cstruct and be able to have access that pointer. The sample code is below. Any help would be appreciated.

typedef struct{
 int x;
 int y;
} Point;

typedef struct {
 PyObject_HEAD
 Point* my_point;
} PointObject;

static PyTypeObject PointType = {
    PyObject_HEAD_INIT(NULL)
    0,                         /*ob_size*/
    "point",             /*tp_name*/
    sizeof(PointObject), /*tp_basicsize*/
    0,                         /*tp_itemsize*/
    0,                         /*tp_dealloc*/
    0,                         /*tp_print*/
    0,                         /*tp_getattr*/
    0,                         /*tp_setattr*/
    0,                         /*tp_compare*/
    0,                         /*tp_repr*/
    0,                         /*tp_as_number*/
    0,                         /*tp_as_sequence*/
    0,                         /*tp_as_mapping*/
    0,                         /*tp_hash */
    0,                         /*tp_call*/
    0,                         /*tp_str*/
    0,                         /*tp_getattro*/
    0,                         /*tp_setattro*/
    0,                         /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT,        /*tp_flags*/
    "point objects",           /* tp_doc */
};

static PyObject* set_point(PyObject* self, PyObject* args)
{
 PyObject* point; 

 if (!PyArg_ParseTuple(args, "O", &point))
 {
  return NULL;
 }

    //code to access my_point    
}
  • 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-16T04:19:12+00:00Added an answer on May 16, 2026 at 4:19 am

    Your PyArg_ParseTuple should not use format O but O! (see the docs):

    O! (object) [typeobject, PyObject *]
    

    Store a Python object in a C object
    pointer. This is similar to O, but
    takes two C arguments: the first is
    the address of a Python type object,
    the second is the address of the C
    variable (of type PyObject*) into
    which the object pointer is stored. If
    the Python object does not have the
    required type, TypeError is raised.

    Once you’ve done that, you know that in your function’s body (PointObject*)point will be a correct and valid pointer to a PointObject, and therefore its ->my_point will be the Point* you seek. With a plain format O you’d have to do the type checking yourself.

    Edit: the OP in a comments asks for the source…:

    static PyObject*
    set_point(PyObject* self, PyObject* args)
    {
        PyObject* point; 
    
        if (!PyArg_ParseTuple(args, "O!", &PointType, &point))
        {
            return NULL;
        }
    
        Point* pp = ((PointObject*)point)->my_point;
    
        // ... use pp as the pointer to Point you were looking for...
    
        // ... and incidentally don't forget to return a properly incref'd
        // PyObject*, of course;-)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are a couple of potential problems with your code.… May 16, 2026 at 11:37 am
  • Editorial Team
    Editorial Team added an answer You can use the join ($this->db->join();) methods provided by the… May 16, 2026 at 11:37 am
  • Editorial Team
    Editorial Team added an answer try: $ git clone "/cygdrive/c/Users/DAMS/Documents/My Dropbox/Projects/RED.git" You're not escaping the… May 16, 2026 at 11:37 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm a Python novice, trying to use pyCurl. The project I am working on
I am currently working on creating an import-based pipeline for my indie game using
I've been working with python for a while now and am just starting to
I'm working in the Google App Engine environment and programming in Python. I am
I'm working on creating an app that will parse MSDN articles for meta-information such
I am creating a custom reporting website, where I want to show live data
I'm trying to use YUI compressor in a maven goal, but I'm pretty new
My python program (Python 2.6) works fine when I run it using the Python
I'm dealing with a Virtuozzo server and want to automate logging into each container
I am creating a dynamic CSS file in ASP.NET MVC2, and I'm now encountering

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.