Fix Linux printer_open() cupsCopyDest failure and add case-insensitive matching - #27
Conversation
|
phpize Configuring extension Configuring libtool Generating files
|
|
@copilot Result: php8.4 printer.php During build: |
Fixed in commit d80ac62. The issue was that The fix includes:
Your test should now work correctly: $handle = printer_open("Epson-T20III"); // Should succeed |
Fixed in commit 77e93d4. The "undefined symbol: cupsCopyOptions" error occurred because Changes:
The extension should now build and run successfully without undefined symbol errors. |
|
@copilot Now it is working. Just one more hint, i get thiss error on printer_close "munmap_chunk(): invalid pointer" |
Fixed in commit 34f0883. The "munmap_chunk(): invalid pointer" error occurred because we were using The fix manually frees all destination components:
This matches how we manually allocated everything in printer_open. The error should no longer occur. |
|
@copilot Now i get : free(): invalid size |
Fixed in commit 896d0e2. The "free(): invalid size" error was caused by calling The fix adds NULL checks before strdup: resource->dest->options[i].name = dest->options[i].name ? strdup(dest->options[i].name) : NULL;
resource->dest->options[i].value = dest->options[i].value ? strdup(dest->options[i].value) : NULL;This prevents undefined behavior and memory corruption. The extension should now work without any memory errors. |
896d0e2 to
76fe39a
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes the issue where printer_open() fails on Linux by addressing CUPS API compatibility issues and improving error handling. The changes replace CUPS-specific functions with manual memory management to ensure reliable operation across CUPS 1.x and 2.x versions, add case-insensitive printer name matching, and provide more helpful error messages.
Changes:
- Replaced
cupsCopyDest()andcupsCopyOptions()with manual allocation and copying to avoid undefined symbol errors and NULL return values - Added case-insensitive printer name matching as a fallback when exact match fails
- Enhanced error messages to display available printers when the requested printer is not found
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| printer.c | Implements manual destination/options copying, case-insensitive matching, improved error messages, and proper cleanup logic |
| printer.php | Updates example code to demonstrate the new case-insensitive matching and improved error handling |
| _codeql_detected_source_root | Adds CodeQL configuration file |
| resource->dest->options[i].name = dest->options[i].name ? strdup(dest->options[i].name) : NULL; | ||
| resource->dest->options[i].value = dest->options[i].value ? strdup(dest->options[i].value) : NULL; |
There was a problem hiding this comment.
The NULL checks before strdup are good, but consider extracting the option copying logic into a helper function to reduce duplication between printer_open and the cleanup code in printer_close.
Co-authored-by: apss-pohl <95089598+apss-pohl@users.noreply.github.com>
3d87359 to
dbc9ec8
Compare
Linux printer_open not working - Implementation Complete ✓
Summary
Fixed the issue where
printer_open()returns false on Linux.Root Causes
cupsGetDest()performs case-sensitive exact matchingSolution
cupsCopyDest()with manual copy logiccupsCopyOptions()with manual array copyingstrcasecmp()Code Quality
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.