You are not logged in.

#1 2016-06-08 20:28:40

markzz
Member
From: Michigan, United States
Registered: 2013-06-08
Posts: 89
Website

[SOLVED] Using libalpm (for PHP extension)

I'm trying to build a PHP extension that allows me to use libalpm with something I'm doing in PHP.

From what I understand from the README and looking at the rest of pacman's source code, in order to use libalpm, you need to create a alpm_handle_t instance with alpm_initialize(), but when I do it, I get an issue that if I try to access something from the handle pointer (*handle), I get the following error if I try to access something like handle->root...

error: dereferencing pointer to incomplete type ‘alpm_handle_t {aka struct __alpm_handle_t}’

The code I'm using to initialize the handle is (alpm.h and alpm_list.h are included)...

static void php_alpm_init_globals(zend_alpm_globals *alpm_globals) {
    alpm_errno_t err;
    alpm_handle_t *handle = alpm_initialize("/", "/var/lib/pacman/", &err);
    alpm_globals->handle = handle;
}

I'm doing something wrong and I cannot seem to figure it out and if someone knows what to do and how it's supposed to be done, I would be very happy to know!

EDIT: Here are the files that I currently have...

php_alpm.h

#ifndef PHP_ALPM_H
#define PHP_ALPM_H

#ifdef ZTS
#include "TSRM.h"
#endif

ZEND_BEGIN_MODULE_GLOBALS(alpm)
    alpm_handle_t *handle;
ZEND_END_MODULE_GLOBALS(alpm)

#ifdef ZTS
#define ALPM_G(v) TSRMG(alpm_globals_id, zend_hello_globals *, v)
#else
#define ALPM_G(v) (alpm_globals.v)
#endif

#define PHP_ALPM_VERSION "0.1"
#define PHP_ALPM_EXTNAME "alpm"

PHP_MINIT_FUNCTION(alpm);
PHP_MSHUTDOWN_FUNCTION(alpm);
PHP_RINIT_FUNCTION(alpm);

extern zend_module_entry alpm_module_entry;
#define phpext_alpm_ptr &alpm_module_entry

#endif

alpm.c

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <alpm.h>
#include <alpm_list.h>

#include "php.h"
#include "php_ini.h"
#include "php_alpm.h"

ZEND_DECLARE_MODULE_GLOBALS(alpm)

PHP_FUNCTION(alpm_test);

static zend_function_entry alpm_functions[] = {
    PHP_FE(alpm_test, NULL)

    {NULL, NULL, NULL}
};

zend_module_entry alpm_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
    STANDARD_MODULE_HEADER,
#endif
    PHP_ALPM_EXTNAME,
    alpm_functions,
    PHP_MINIT(alpm),
    PHP_MSHUTDOWN(alpm),
    PHP_RINIT(alpm),
    NULL,
    NULL,
#if ZEND_MODULE_API_NO >= 20010901
    PHP_ALPM_VERSION,
#endif
    STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_ALPM
ZEND_GET_MODULE(alpm)
#endif

static void php_alpm_init_globals(zend_alpm_globals *alpm_globals) {
    alpm_errno_t err;
    alpm_handle_t *handle = alpm_initialize("/", "/var/lib/pacman/", &err);
    alpm_globals->handle = handle;
}

PHP_RINIT_FUNCTION(alpm) {
    return SUCCESS;
}

PHP_MSHUTDOWN_FUNCTION(alpm) {
    return SUCCESS;
}

PHP_MINIT_FUNCTION(alpm) {
    ZEND_INIT_MODULE_GLOBALS(alpm, php_alpm_init_globals, NULL);

    return SUCCESS;
}

PHP_FUNCTION(alpm_test) {
    alpm_handle_t *handle = ALPM_G(handle);

    RETURN_STRING(handle->dbpath) /* this line is what's causing issues during compilation */
}

config.m4

PHP_ARG_ENABLE(alpm, whether to enable alpm support, [ --enable-alpm Enable alpm support])

if test "$PHP_ALPM" = "yes"; then
    AC_DEFINE(HAVE_ALPM, 1, [Whether you have alpm])
    PHP_NEW_EXTENSION(alpm, alpm.c, $ext_shared)
fi

Last edited by markzz (2016-06-09 04:35:37)


I don't want to work.  I want to bang on the drum all day.

Offline

#2 2016-06-09 04:32:01

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

Re: [SOLVED] Using libalpm (for PHP extension)

const char *alpm_option_get_dbpath(alpm_handle_t *handle);

Offline

#3 2016-06-09 04:35:18

markzz
Member
From: Michigan, United States
Registered: 2013-06-08
Posts: 89
Website

Re: [SOLVED] Using libalpm (for PHP extension)

Allan wrote:
const char *alpm_option_get_dbpath(alpm_handle_t *handle);

Thank you!


I don't want to work.  I want to bang on the drum all day.

Offline

Board footer

Powered by FluxBB