All of lore.kernel.org
 help / color / mirror / Atom feed
* Migrating PyCups to Python CFFI for libcups 3.x
@ 2025-04-02 13:49 Soumyadeep Ghosh
  2025-04-03  8:52 ` Zdenek Dohnal
  0 siblings, 1 reply; 4+ messages in thread
From: Soumyadeep Ghosh @ 2025-04-02 13:49 UTC (permalink / raw)
  To: printing-architecture; +Cc: Till Kamppeter, Zdohnal

Hello everyone, 

This mail is after a long discussion with Till about various different approaches and possibilities. PyCups for libcups 2.4.x was written in C using the Python's C extensions 

The problem with that is:

1. Very low scope of automation
2.Very less support from different python communities
3.Only source of support is the original python documentation

With libcups 3.x, I am planning to move to use Python CFFI. With this, there is also a scope for automating the bindings too. For an example, how this CFFI bindings work, sharing an example here

#include

const char* isPrime(int a){
  int i, flag=0;
  for(i=2;i
  {   if (a%i==0)
        (flag=1);
      else
        (flag=0);
  }
  if (flag==1)
    return ("Number is Non-prime.");
  else
    return ("Number is Prime.");
}

int main()
{
    int n;
    printf("Enter any number:");
    scanf("%d",&n);
    isPrime(n);
}

This is a C function, and now, we complie this as a shared object and call this from python

from cffi import FFI

class DeterminePrime:
    def __init__(self, library_path="../C programme/determine_prime.so"):
        self.ffi = FFI()
       
        self.ffi.cdef("""
            const char* isPrime(int);
        """)
       
        self.lib = self.ffi.dlopen(library_path)

    def check_prime(self, number):
        result = self.ffi.string(self.lib.isPrime(number))
        return result.decode('utf-8')


As one can see, we just need the signature in many cases, to call the function properly. Please let me know what you think about this change.


Thanks and Regards,
Soumyadeep Ghosh



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-04 10:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02 13:49 Migrating PyCups to Python CFFI for libcups 3.x Soumyadeep Ghosh
2025-04-03  8:52 ` Zdenek Dohnal
2025-04-04 10:29   ` Soumyadeep Ghosh
2025-04-04 10:38   ` Till Kamppeter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.