LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2024, 06:41 AM   #1
ajiten
Member
 
Registered: Jun 2023
Posts: 375

Rep: Reputation: 4
Question on passing pointer in C to Python code.


Was curious about how to pass a double pointer, triple pointer in Python, from a C code.
The concept of a pointer variable in C, is due to the specific size requirements imposed by the necessitated by the address-bus size (in bytes); something which on a machine, the int or even long datatype might not possess.

Saw the site here, on googling, as the top result; and am confused as what (even, the OP) it even means.

If it reasonable to ask about its implies sense here, please hint somewhat.
 
Old 02-26-2024, 08:23 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,879

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
It is working in the reverse order:
You need to construct in c (c++) a variable structure which can be used in pure python code. Python (internally) cannot handle double/triple and other different kind of pointer types of c.
see: https://stackoverflow.com/questions/...on-with-ctypes
Or you can implement a conversion function in python, for any arbitrary blob, but that will be extremely slow (and inefficient).
 
Old 02-26-2024, 09:34 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Quote:
Originally Posted by ajiten View Post
Was curious about how to pass a double pointer, triple pointer in Python, from a C code.
This would certainly qualify as an "XY Problem". In which "the problem that you propose" is not "the problem that you actually have."

Why are you "curious" about "passing [x] to Python?" What are you now trying to do?

Details right now are very important: "if you're trying to interface to 'a library,' exactly which one?" And, so on.

The Python programming language (in particular ...) has been applied to "create powerful interfaces to" a very great many things, and so there is actually quite a very-lot of material already out there on the Internet about how exactly it was done. (In fact, you certainly should not overlook the possibility that what you are now trying to do might have already been done. "Or something very close to it.") Sites like github and sourceforge are your friends.

Last edited by sundialsvcs; 02-26-2024 at 09:38 PM.
 
Old 02-27-2024, 08:39 AM   #4
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
I'm not sure this is what you are looking for but I made python bindings for a library I've been working on. I'm not entirely sure how quick it is. But this is the result of my research on the topic. You don't pass a pointer directly. Rather the data from the pointer from what I've learned. Should give some direction I'd surmise.

Main Git - https://gitlab.com/jmgibson1981/mylibraries
Python binding file - https://gitlab.com/jmgibson1981/myli...ref_type=heads
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python: passing functions or unevaluated code with multiple lines or expressions stateless Programming 1 11-30-2013 10:38 PM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM
Passing args in terminal window is OK. but isn't when passing in GNOME launcher why? majrys1962 Debian 0 11-18-2008 06:00 PM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 02:18 PM
pointer to pointer question in c lawkh Programming 2 01-29-2004 10:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration