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 8457969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:57:05+00:00 2026-06-10T12:57:05+00:00

I have a compatibility library that uses SWIG to access a C++ library. I

  • 0

I have a compatibility library that uses SWIG to access a C++ library. I would find it useful to be able to create a SWIG-wrapped Python object inside this layer (as opposed to accepting the C++ object as an argument or returning one). I.e. I want the PyObject* that points to the SWIG-wrapped C++ object.

I discovered that the SWIG_NewPointerObj function does exactly this. The SWIG-generated xx_wrap.cpp file uses this function, but it’s also made available in the header emitted by swig -python -external-runtime swigpyrun.h

HOWEVER, I cannot find any reference to what the last argument to this function is. It appears that it specifies the ownership of the object, but there is no documentation that says what each of the options mean (or even what they all are).
It appears that the following are acceptable values:

  • 0
  • SWIG_POINTER_OWN
  • SWIG_POINTER_NOSHADOW
  • SWIG_POINTER_NEW = OWN + NOSHADOW
  • SWIG_POINTER_DISOWN (I’m not sure if SWIG_NewPointerObj accepts this)
  • SWIG_POINTER_IMPLICIT_CONV (I’m not sure if SWIG_NewPointerObj accepts this)

I want to create an object that is used only in my wrapping layer. I want to create it out of my own pointer to the C++ object (so I can change the C++ object’s value and have it be reflected in the Python object. I need it so it can be passed to a Python callback function. I want to keep this one instance throughout the life of the program so that I don’t waste time creating/destroying identical objects for each callback. Which option is appropriate, and what do I Py_INCREF?

  • 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-06-10T12:57:07+00:00Added an answer on June 10, 2026 at 12:57 pm

    When you create new pointer objects with SWIG_NewPointerObj, you may pass the following flags:

    SWIG_POINTER_OWN
    SWIG_POINTER_NOSHADOW
    

    If SWIG_POINTER_OWN is set, the destructor of the underlying C++ class will be called when the Python pointer is finalized. By default, the destructor will not be called. See Memory Management

    For your use case, you don’t need to set any flags at all.

    From what I can see in the sources, if SWIG_POINTER_NOSHADOW is set, then a basic wrapped pointer is returned. You will not be able to access member variables in Python. All you’ll have is an opaque pointer.

    Reference: /usr/share/swig/2.0.7/python/pyrun.swg

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

Sidebar

Related Questions

I have renamed a python class that is part of a library. I am
I have a Cocoa app that uses otool to find required shared libraries that
Using this page, http://developer.android.com/sdk/compatibility-library.html , I have installed the Android Support Package, added a
I have an intranet site that loads in IE7 compatibility mode, unless the user
I'm using the Android Compatibility library to implement fragments and have extended the layout
I have an Android application for pre-Honeycomb devices that uses custom tabs to launch
I have a library that can be compiled as a shared library (or DLL
I have a small application that uses the Attach API to modify some third
I have a User Control Library that I am loading dynamically. From that lib
i am developing an arabic android application and i have the compatibility package referenced

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.