Permalink
Browse files

Refactor

  • Loading branch information...
1 parent ddc0ac9 commit d7cf6de713dca8a931bf1eefe10114b501fffa9b @rsky committed Aug 31, 2012
Showing with 124 additions and 44 deletions.
  1. +58 −19 device.c
  2. +9 −0 opencl.c
  3. +57 −25 platform.c
View
@@ -9,6 +9,9 @@
#include "device.h"
+#define get_info_func ((phpcl_get_info_func_t)phpcl_get_device_info)
+#define get_info_ex_func ((phpcl_get_info_ex_func_t)phpcl_get_device_info_ex)
+
/* {{{ globals */
static const phpcl_info_param_t device_info_params[] = {
@@ -145,6 +148,54 @@ static zval *phpcl_get_device_info_ex(cl_device_id device,
return zinfo;
}
+/* }}} */
+/* {{{ phpcl_get_device_info_all() */
+
+static void phpcl_get_device_info_all(INTERNAL_FUNCTION_PARAMETERS,
+ cl_device_id device)
+{
+ const phpcl_info_param_t *param = device_info_params;
+ char buf[32] = {0};
+
+ array_init_size(return_value, 64);
+ snprintf(buf, sizeof(buf), "%p", device);
+ add_assoc_string(return_value, "id", buf, 1);
+
+ while (param->key != NULL) {
+ zval *entry = phpcl_get_info(get_info_func, get_info_ex_func,
+ device, NULL, param TSRMLS_CC);
+ if (entry) {
+ add_assoc_zval(return_value, param->key, entry);
+ } else {
+ add_assoc_null(return_value, param->key);
+ }
+ param++;
+ }
+}
+
+/* }}} */
+/* {{{ phpcl_get_device_info_by_name() */
+
+static void phpcl_get_device_info_by_name(INTERNAL_FUNCTION_PARAMETERS,
+ cl_device_id device, cl_int name)
+{
+ const phpcl_info_param_t *param = device_info_params;
+
+ RETVAL_NULL();
+
+ while (param->key != NULL) {
+ if (param->name == name) {
+ zval *entry = phpcl_get_info(get_info_func, get_info_ex_func,
+ device, NULL, param TSRMLS_CC);
+ if (entry) {
+ RETVAL_ZVAL(entry, 0, 1);
+ }
+ return;
+ }
+ param++;
+ }
+}
+
/* }}} */
/* {{{ array cl_get_device_ids([resource cl_platform_id platform[, int device_type]]) */
@@ -209,39 +260,27 @@ PHP_FUNCTION(cl_get_device_ids)
}
/* }}} */
-/* {{{ array cl_get_device_info(resource cl_device_id device) */
+/* {{{ array cl_get_device_info(resource cl_device_id device[, int name]) */
PHP_FUNCTION(cl_get_device_info)
{
- const phpcl_info_param_t *param = device_info_params;
zval *zid = NULL;
cl_device_id device = NULL;
- char buf[64] = {0};
+ long name = 0;
RETVAL_FALSE;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
- "r", &zid) == FAILURE) {
+ "r|l", &zid, &name) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(device, cl_device_id, &zid, -1,
"cl_device_id", phpcl_le_device());
- array_init_size(return_value, 64);
- snprintf(buf, sizeof(buf), "%p", device);
- add_assoc_string(return_value, "id", buf, 1);
-
- while (param->key != NULL) {
- zval *entry = phpcl_get_info(
- (phpcl_get_info_func_t)phpcl_get_device_info,
- (phpcl_get_info_ex_func_t)phpcl_get_device_info_ex,
- device, NULL, param TSRMLS_CC);
- if (entry) {
- add_assoc_zval(return_value, param->key, entry);
- } else {
- add_assoc_null(return_value, param->key);
- }
- param++;
+ if (ZEND_NUM_ARGS() == 2) {
+ phpcl_get_device_info_by_name(INTERNAL_FUNCTION_PARAM_PASSTHRU, device, (cl_int)name);
+ } else {
+ phpcl_get_device_info_all(INTERNAL_FUNCTION_PARAM_PASSTHRU, device);
}
}
View
@@ -58,6 +58,7 @@ static void phpcl_release_sampler(phpcl_sampler_t *ptr TSRMLS_DC);
/* platform */
ZEND_BEGIN_ARG_INFO_EX(arg_info_cl_get_platform_info, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
ZEND_ARG_INFO(0, platform)
+ ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
/* device */
@@ -68,6 +69,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arg_info_cl_get_device_info, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
ZEND_ARG_INFO(0, device)
+ ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
/* }}} */
@@ -852,6 +854,13 @@ zval *phpcl_get_info(phpcl_get_info_func_t get_info,
}
}
break;
+
+ default:
+ ZVAL_NULL(zinfo);
+ }
+
+ if (err != CL_SUCCESS) {
+ ZVAL_NULL(zinfo);
}
return zinfo;
View
@@ -9,14 +9,9 @@
#include "platform.h"
-/* {{{ type definitions */
+#define get_info_func ((phpcl_get_info_func_t)phpcl_get_platform_info)
+#define get_info_ex_func NULL
-typedef struct {
- const char *key;
- cl_platform_info name;
-} phpcl_platform_info_param_t;
-
-/* }}} */
/* {{{ globals */
static const phpcl_info_param_t platform_info_params[] = {
@@ -41,6 +36,54 @@ static cl_int phpcl_get_platform_info(cl_platform_id platform,
return clGetPlatformInfo(platform, name, value_size, value, value_size_ret);
}
+/* }}} */
+/* {{{ phpcl_get_platform_info_all() */
+
+static void phpcl_get_platform_info_all(INTERNAL_FUNCTION_PARAMETERS,
+ cl_platform_id platform)
+{
+ const phpcl_info_param_t *param = platform_info_params;
+ char buf[32] = {0};
+
+ array_init_size(return_value, 8);
+ snprintf(buf, sizeof(buf), "%p", platform);
+ add_assoc_string(return_value, "id", buf, 1);
+
+ while (param->key != NULL) {
+ zval *entry = phpcl_get_info(get_info_func, get_info_ex_func,
+ platform, NULL, param TSRMLS_CC);
+ if (entry) {
+ add_assoc_zval(return_value, param->key, entry);
+ } else {
+ add_assoc_null(return_value, param->key);
+ }
+ param++;
+ }
+}
+
+/* }}} */
+/* {{{ phpcl_get_platform_info_by_name() */
+
+static void phpcl_get_platform_info_by_name(INTERNAL_FUNCTION_PARAMETERS,
+ cl_platform_id platform, cl_int name)
+{
+ const phpcl_info_param_t *param = platform_info_params;
+
+ RETVAL_NULL();
+
+ while (param->key != NULL) {
+ if (param->name == name) {
+ zval *entry = phpcl_get_info(get_info_func, get_info_ex_func,
+ platform, NULL, param TSRMLS_CC);
+ if (entry) {
+ RETVAL_ZVAL(entry, 0, 1);
+ }
+ return;
+ }
+ param++;
+ }
+}
+
/* }}} */
/* {{{ array cl_get_platform_ids(void) */
@@ -90,38 +133,27 @@ PHP_FUNCTION(cl_get_platform_ids)
}
/* }}} */
-/* {{{ array cl_get_platform_info(resource cl_platform_id platform) */
+/* {{{ array cl_get_platform_info(resource cl_platform_id platform[, int name]) */
PHP_FUNCTION(cl_get_platform_info)
{
- const phpcl_info_param_t *param = platform_info_params;
zval *zid = NULL;
cl_platform_id platform = NULL;
- char buf[64] = {0};
+ long name = 0;
RETVAL_FALSE;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
- "r", &zid) == FAILURE) {
+ "r|l", &zid, &name) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(platform, cl_platform_id, &zid, -1,
"cl_platform_id", phpcl_le_platform());
- array_init_size(return_value, 8);
- snprintf(buf, sizeof(buf), "%p", platform);
- add_assoc_string(return_value, "id", buf, 1);
-
- while (param->key != NULL) {
- zval *entry = phpcl_get_info(
- (phpcl_get_info_func_t)phpcl_get_platform_info, NULL,
- platform, NULL, param TSRMLS_CC);
- if (entry) {
- add_assoc_zval(return_value, param->key, entry);
- } else {
- add_assoc_null(return_value, param->key);
- }
- param++;
+ if (ZEND_NUM_ARGS() == 2) {
+ phpcl_get_platform_info_by_name(INTERNAL_FUNCTION_PARAM_PASSTHRU, platform, (cl_int)name);
+ } else {
+ phpcl_get_platform_info_all(INTERNAL_FUNCTION_PARAM_PASSTHRU, platform);
}
}

0 comments on commit d7cf6de

Please sign in to comment.